/** * Initializes the type system. */ public void typeSystemInit(TypeSystem typeSystem) throws AnalysisEngineProcessException { // sentence type // String sentenceTypeName = // AnnotatorUtil.getRequiredStringParameter(mContext, // UimaUtil.SENTENCE_TYPE_PARAMETER); // mSentenceType = AnnotatorUtil.getType(typeSystem, sentenceTypeName); // name type mNameType = AnnotatorUtil.getRequiredTypeParameter(context, typeSystem, NameFinder.NAME_TYPE_PARAMETER); mStructureFeature = AnnotatorUtil.getRequiredFeatureParameter(context, mNameType, "opennlp.uima.normalizer.StructureFeature"); if (!SUPPORTED_TYPES.contains(mStructureFeature.getRange().getName())) { throw new AnalysisEngineProcessException( ExceptionMessages.MESSAGE_CATALOG, "range_type_unsupported", new Object[] {mStructureFeature.getRange().getName()}); } }
/** * Checks if the given feature has the expected type otherwise * an exception is thrown. * * @param feature * @param expectedType * @throws AnalysisEngineProcessException - if type does not match */ private static void checkFeatureType(Feature feature, String expectedType) throws AnalysisEngineProcessException { if (!feature.getRange().getName().equals(expectedType)) { throw new OpenNlpAnnotatorProcessException( ExceptionMessages.WRONG_FEATURE_TYPE, new Object[] {feature.getName(), expectedType }); } }
if (CAS.TYPE_NAME_STRING.equals(mStructureFeature.getRange().getName())) { nameAnnotation.setStringValue(mStructureFeature, text); } else { if (CAS.TYPE_NAME_BYTE.equals(mStructureFeature.getRange().getName())) { nameAnnotation.setByteValue(mStructureFeature, number.byteValue()); } else if (CAS.TYPE_NAME_SHORT.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setShortValue(mStructureFeature, number.shortValue()); } else if (CAS.TYPE_NAME_INTEGER.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setIntValue(mStructureFeature, number.intValue()); } else if (CAS.TYPE_NAME_LONG.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setLongValue(mStructureFeature, number.longValue()); } else if (CAS.TYPE_NAME_FLOAT.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setFloatValue(mStructureFeature, number.floatValue()); } else if (CAS.TYPE_NAME_DOUBLE.equals(mStructureFeature.getRange() .getName())) { nameAnnotation
private boolean validType(Feature feature) { String name = feature.getRange().getName(); return StringUtils.equals(name, CAS.TYPE_NAME_INTEGER_ARRAY) || StringUtils.equals(name, CAS.TYPE_NAME_DOUBLE_ARRAY) || StringUtils.equals(name, CAS.TYPE_NAME_FLOAT_ARRAY); }
@Override public Type getRange() { checkDelegate(); return delegate.getRange(); }
public static boolean isPrimitiveFeature(Feature aFeature) { return aFeature.getRange().isPrimitive(); } }
public static boolean isPrimitiveFeature(Feature aFeature) { return aFeature.getRange().isPrimitive(); } }
private boolean isSpanLayer(TypeSystem aTS, Type aType) { // A UIMA type can be a span layer if... // ... there are only primitive features or slot features List<Feature> nonPrimitiveFeatures = aType.getFeatures().stream() .filter(f -> !isBuiltInFeature(f)) .filter(f -> !(f.getRange().isPrimitive() || isSlotFeature(aTS, f))) .collect(Collectors.toList()); return nonPrimitiveFeatures.isEmpty(); }
private Object getPrimitive(FeatureStructure fs, Feature feature) { String s = feature.getRange().getName(); if (s.equals("uima.cas.String")) return fs.getStringValue(feature); else if (s.equals("uima.cas.Integer")) return fs.getIntValue(feature); else if (s.equals("uima.cas.Double")) return fs.getDoubleValue(feature); return null; }
public static void collect(Set<FeatureStructure> aFSes, FeatureStructure aFS) { if (aFS != null && !aFSes.contains(aFS)) { aFSes.add(aFS); for (Feature f : aFS.getType().getFeatures()) { if (!f.getRange().isPrimitive() && !CAS.FEATURE_BASE_NAME_SOFA.equals(f.getShortName())) { collect(aFSes, aFS.getFeatureValue(f)); } } } }
public static void collect(Set<FeatureStructure> aFSes, FeatureStructure aFS) { if (aFS != null && !aFSes.contains(aFS)) { aFSes.add(aFS); for (Feature f : aFS.getType().getFeatures()) { if (!f.getRange().isPrimitive() && !CAS.FEATURE_BASE_NAME_SOFA.equals(f.getShortName())) { collect(aFSes, aFS.getFeatureValue(f)); } } } }
public static void collect(Set<FeatureStructure> aFSes, FeatureStructure aFS) { if (aFS != null && !aFSes.contains(aFS)) { aFSes.add(aFS); for (Feature f : aFS.getType().getFeatures()) { if (!f.getRange().isPrimitive() && !CAS.FEATURE_BASE_NAME_SOFA.equals(f.getShortName())) { collect(aFSes, aFS.getFeatureValue(f)); } } } }
public static void setFeature(FeatureStructure aFS, String aFeature, byte... aValue) { Feature feat = getMandatoryFeature(aFS, aFeature); if (feat.getRange().isPrimitive()) { requireSingleValue(feat, aValue); aFS.setByteValue(feat, aValue[0]); } else if (aValue == null) { aFS.setFeatureValue(feat, null); } else { aFS.setFeatureValue(feat, createByteArray(aFS.getCAS(), aValue)); } }
public static void setFeature(FeatureStructure aFS, String aFeature, short... aValue) { Feature feat = getMandatoryFeature(aFS, aFeature); if (feat.getRange().isPrimitive()) { requireSingleValue(feat, aValue); aFS.setShortValue(feat, aValue[0]); } else if (aValue == null) { aFS.setFeatureValue(feat, null); } else { aFS.setFeatureValue(feat, createShortArray(aFS.getCAS(), aValue)); } }
public byte getByteValue(Feature feat) throws CASRuntimeException { final TypeSystemImpl ts = this.getCASImpl().getTypeSystemImpl(); if (!ts.subsumes(feat.getDomain(), getType())) { throwUndefinedFeatureExc(feat, getType()); } if (!ts.subsumes(feat.getRange(), ts.getType(CAS.TYPE_NAME_BYTE))) { throwIllegalRangeExc(feat, ts.getType(CAS.TYPE_NAME_BYTE)); } final int featCode = ((FeatureImpl) feat).getCode(); return this.getCASImpl().getByteValue(this.getAddress(), featCode); }
public short getShortValue(Feature feat) throws CASRuntimeException { final TypeSystemImpl ts = this.getCASImpl().getTypeSystemImpl(); if (!ts.subsumes(feat.getDomain(), getType())) { throwUndefinedFeatureExc(feat, getType()); } if (!ts.subsumes(feat.getRange(), ts.getType(CAS.TYPE_NAME_SHORT))) { throwIllegalRangeExc(feat, ts.getType(CAS.TYPE_NAME_SHORT)); } final int featCode = ((FeatureImpl) feat).getCode(); return this.getCASImpl().getShortValue(this.getAddress(), featCode); }
public long getLongValue(Feature feat) throws CASRuntimeException { final TypeSystemImpl ts = this.getCASImpl().getTypeSystemImpl(); if (!ts.subsumes(feat.getDomain(), getType())) { throwUndefinedFeatureExc(feat, getType()); } if (!ts.subsumes(feat.getRange(), ts.getType(CAS.TYPE_NAME_LONG))) { throwIllegalRangeExc(feat, ts.getType(CAS.TYPE_NAME_LONG)); } final int featCode = ((FeatureImpl) feat).getCode(); return this.getCASImpl().getLongValue(this.getAddress(), featCode); }