public static Feature getRequiredFeature(Type type, String featureName) throws AnalysisEngineProcessException { Feature feature = type.getFeatureByBaseName(featureName); if (feature == null) { throw new OpenNlpAnnotatorProcessException( ExceptionMessages.FEATURE_NOT_FOUND, new Object[] {type.getName(), featureName}); } return feature; }
/** * 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 .setDoubleValue(mStructureFeature, number.doubleValue());
protected void documentDone(CAS cas) { // TODO: Create confidence FS // contains String name type // contains Double prob if (documentConfidenceType != null) { FeatureStructure confidenceFS = cas.createFS(documentConfidenceType); confidenceFS.setDoubleValue(documentConfidenceFeature, documentConfidence.mean()); confidenceFS.setStringValue(documentConfidenceNameTypeFeature, mNameType.getName()); cas.addFsToIndexes(confidenceFS); } // Clears the adaptive data which was created for the current document mNameFinder.clearAdaptiveData(); documentConfidence = new Mean(); }
@Override public boolean select(Viewer viewer, Object parentElement, Object element) { // check if the string from the filterText is contained in the type name Type type = (Type) element; return type.getName().contains(filterText.getText()); } } });
@Override public void typeChanged(Type newType) { store.setValue(LAST_SELECTED_FS_TYPE, newType.getName()); } });
public String verbalizeType(Type type) { if (type.getName().equals("uima.tcas.DocumentAnnotation")) { return "Document"; } else { return type.getShortName(); } }
public String verbalizeType(Type type) { if (type.getName().equals(CAS.TYPE_NAME_DOCUMENT_ANNOTATION)) { return "Document"; } else { return type.getShortName(); } }
private String[] getArrayMultiplierForType(Type type) { String confKey = type.getName().replaceAll("\\.", "..") + ".arraymulti"; String confEntry = configuration.getString(confKey, null); if (confEntry != null && !confEntry.isEmpty()) return confEntry.split(","); else return new String[0]; }
private boolean isBuiltInFeature(Feature aFeature) { Set<String> builtInTypes = new HashSet<>(asList( CAS.TYPE_NAME_TOP, CAS.TYPE_NAME_ANNOTATION_BASE, CAS.TYPE_NAME_ANNOTATION)); return builtInTypes.contains(aFeature.getDomain().getName()); }
private Object getPrimitiveComponent(FeatureStructure array, int index) { Type cType = array.getType().getComponentType(); if (cType.getName().equals("uima.cas.String")) return ((StringArray) array).get(index); else if (cType.getName().equals("uima.cas.Double")) return ((DoubleArray) array).get(index); else if (cType.getName().equals("uima.cas.Integer")) return ((IntegerArray) array).get(index); return null; }
private Type getClassType(Class<? extends Annotation> cls) { for(Type type:Lists.newArrayList(actual.getTypeSystem().getTypeIterator())) { if(type.getName().equals(cls.getName())) return type; } throw new IllegalArgumentException("No type found for class: " + cls.getName()); }
public static Feature getRequiredFeature(Type type, String featureName) throws AnalysisEngineProcessException { Feature feature = type.getFeatureByBaseName(featureName); if (feature == null) { throw new OpenNlpAnnotatorProcessException( ExceptionMessages.FEATURE_NOT_FOUND, new Object[] { type.getName(), featureName}); } return feature; }
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; }
private Type getType(String annotationType) { for(Type type:Lists.newArrayList(actual.getTypeSystem().getTypeIterator())) { if(type.getName().equals(annotationType)) return type; else if(type.getShortName().equals(annotationType)) return type; } throw new IllegalArgumentException("No such type found: " + annotationType); }
/** * Write an annotation * * @param sb the sb * @param annotation the annotation */ protected void writeLine(StringBuilder sb, String prefix, Base annotation) { writeLine(sb, prefix, annotation.getCoveredText() + "[" + annotation.getType().getName() + "]"); }
@Override public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) { AnnotationFS annotation = context.getAnnotation(); String typeWithFeature = annotation.getType().getName() + "." + featureStringExpression.getStringValue(context, stream); MatchReference mf = new MatchReference(typeWithFeature); FeatureMatchExpression fme = new FeatureMatchExpression(mf, "==", argExpr); boolean checkFeatureValue = fme.checkFeatureValue(annotation, context, stream); return new EvaluatedCondition(this, checkFeatureValue); }
@Test public void testRecordable() throws UIMAException { JCas jCas = JCasFactory.createJCas(); FakeRecordable fakeRecordable = new FakeRecordable(jCas); assertEquals(new Annotation(jCas).getType().getName(), fakeRecordable.getTypeName()); }