@Override public String apply(FeatureStructure fs) { return fs.getStringValue(feat); } };
private String extractValue(AnnotationFS target) { FeatureStructure curElemAnno = target; for (int i = 0; i < featurePath.size() - 1; i++) { FeatureStructure featValue = curElemAnno.getFeatureValue(featurePath.get(i)); curElemAnno = featValue; } Feature lastFeature = featurePath.get(featurePath.size() - 1); return curElemAnno.getStringValue(lastFeature); } }
@Nullable public String getStringValue(String name) { return featureStructure.getStringValue(getFeature(name)); }
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; }
@Nullable @Override public String get(Object key) { if (!(key instanceof String)) { return null; } FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, (String) key); FeatureStructure fs = metadataIndex.find(check); return fs.getStringValue(valueFeature); }
public static Object stringListToArray(FeatureStructure fs) { List<String> list = new ArrayList<String>(); TypeSystem ts = fs.getCAS().getTypeSystem(); Type emptyFSList = ts.getType("uima.cas.EmptyStringList"); Feature headFeature = ts.getFeatureByFullName("uima.cas.NonEmptyStringList:head"); Feature tailFeature = ts.getFeatureByFullName("uima.cas.NonEmptyStringList:tail"); Set<FeatureStructure> alreadySeen = new HashSet<FeatureStructure>(); FeatureStructure nextFs; for (FeatureStructure currentFs = fs; currentFs.getType() != emptyFSList; currentFs = nextFs) { list.add(currentFs.getStringValue(headFeature)); nextFs = currentFs.getFeatureValue(tailFeature); if (alreadySeen.contains(nextFs)) { return loopInList(list); } alreadySeen.add(nextFs); } return list.toArray(new String[list.size()]); }
public boolean match(FeatureStructure fs) { // compile(((FeatureStructureImpl) fs).getCAS().getTypeSystem()); final int max = this.featNames.size() - 1; // The last position in the // path! if (max < 0) { // If the path is empty, we can't get a string, and therefore the // constraint is not satisfied. return false; } Feature feat; for (int i = 0; i < max; i++) { feat = fs.getType().getFeatureByBaseName(this.featNames.get(i)); if (feat == null) { return false; } fs = fs.getFeatureValue(feat); } feat = fs.getType().getFeatureByBaseName(this.featNames.get(max)); if (feat == null) { return false; } return this.stringConstraint.match(fs.getStringValue(feat)); }
@Nullable @Override public String put(String key, String value) { FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, key); FeatureStructure fs = metadataIndex.find(check); String existing = null; if (fs != null) { existing = fs.getStringValue(valueFeature); metadataCas.removeFsFromIndexes(fs); } else { fs = check; } fs.setStringValue(valueFeature, value); metadataCas.addFsToIndexes(fs); return existing; }
/** * A Helper method to add {@link TagsetDescription} to {@link CAS} */ public static void updateCasWithTagSet(CAS aCas, String aLayer, String aTagSetName) { Type TagsetType = CasUtil.getType(aCas, TagsetDescription.class); Feature layerFeature = TagsetType.getFeatureByBaseName("layer"); Feature nameFeature = TagsetType.getFeatureByBaseName("name"); boolean tagSetModified = false; // modify existing tagset Name for (FeatureStructure fs : CasUtil.select(aCas, TagsetType)) { String layer = fs.getStringValue(layerFeature); String tagSetName = fs.getStringValue(nameFeature); if (layer.equals(aLayer)) { // only if the tagset name is changed if (!aTagSetName.equals(tagSetName)) { fs.setStringValue(nameFeature, aTagSetName); aCas.addFsToIndexes(fs); } tagSetModified = true; break; } } if (!tagSetModified) { FeatureStructure fs = aCas.createFS(TagsetType); fs.setStringValue(layerFeature, aLayer); fs.setStringValue(nameFeature, aTagSetName); aCas.addFsToIndexes(fs); } }
@Override public String getStringValue(MatchContext context, RutaStream stream) { AnnotationFS annotation = context.getAnnotation(); Feature feature = this.fe.getFeature(context, stream); List<AnnotationFS> list = this.getTargetAnnotation(annotation, this.fe, context, stream); Collection<? extends FeatureStructure> featureStructures = this.fe.getFeatureStructures(list, false, context, stream); if (!featureStructures.isEmpty()) { FeatureStructure next = featureStructures.iterator().next(); if (next instanceof AnnotationFS && !next.getType().equals(annotation.getType())) { feature = this.fe.getFeature(new MatchContext((AnnotationFS) next, context.getElement(), context.getRuleMatch(), context.getDirection()), stream); } if (next instanceof AnnotationFS && feature instanceof CoveredTextFeature) { return ((AnnotationFS) next).getCoveredText(); } else { return next.getStringValue(feature); } } return null; }
/** * Returns a value associated with a given feature. * * @param aCas - * Cas containing data to extract * @param aFeature - * feature to locate in the CAS * @param aName - * name of the feature * @return - value as String * @throws Exception the exception */ public static String getFeatureAsString(CAS aCas, Feature aFeature, String aName) throws Exception { Feature seqNo2 = aFeature.getRange().getFeatureByBaseName(aName); FeatureStructure documentMetaData = aCas.getView(CAS.NAME_DEFAULT_SOFA).getDocumentAnnotation() .getFeatureValue(aFeature); return documentMetaData.getStringValue(seqNo2); }
for (FeatureStructure link : array.toArray()) { LinkWithRoleModel m = new LinkWithRoleModel(); m.role = link.getStringValue(roleFeat); m.targetAddr = WebAnnoCasUtil.getAddr(link.getFeatureValue(targetFeat)); m.label = ((AnnotationFS) link.getFeatureValue(targetFeat))
for (FeatureStructure link : array.toArray()) { LinkWithRoleModel m = new LinkWithRoleModel(); m.role = link.getStringValue(roleFeat); m.targetAddr = WebAnnoCasUtil.getAddr(link.getFeatureValue(targetFeat)); m.label = ((AnnotationFS) link.getFeatureValue(targetFeat))
for (FeatureStructure link : array.toArray()) { LinkWithRoleModel m = new LinkWithRoleModel(); m.role = link.getStringValue(roleFeat); m.targetAddr = WebAnnoCasUtil.getAddr(link.getFeatureValue(targetFeat)); m.label = ((AnnotationFS) link.getFeatureValue(targetFeat))
public static <T> T getFeature(FeatureStructure aFS, String aFeatureName) { Feature feature = aFS.getType().getFeatureByBaseName(aFeatureName); if (feature == null) { throw new IllegalArgumentException("Type [" + aFS.getType().getName() + "] has no feature called [" + aFeatureName + "]"); } switch (feature.getRange().getName()) { case CAS.TYPE_NAME_STRING: return (T) aFS.getStringValue(feature); case CAS.TYPE_NAME_BOOLEAN: return (T) (Boolean) aFS.getBooleanValue(feature); case CAS.TYPE_NAME_FLOAT: return (T) (Float) aFS.getFloatValue(feature); case CAS.TYPE_NAME_INTEGER: return (T) (Integer) aFS.getIntValue(feature); default: throw new IllegalArgumentException("Cannot get value of feature [" + feature.getName() + "] with type [" + feature.getRange().getName() + "]"); } }
public static <T> T getFeature(FeatureStructure aFS, String aFeatureName) { Feature feature = aFS.getType().getFeatureByBaseName(aFeatureName); if (feature == null) { throw new IllegalArgumentException("Type [" + aFS.getType().getName() + "] has no feature called [" + aFeatureName + "]"); } switch (feature.getRange().getName()) { case CAS.TYPE_NAME_STRING: return (T) aFS.getStringValue(feature); case CAS.TYPE_NAME_BOOLEAN: return (T) (Boolean) aFS.getBooleanValue(feature); case CAS.TYPE_NAME_FLOAT: return (T) (Float) aFS.getFloatValue(feature); case CAS.TYPE_NAME_INTEGER: return (T) (Integer) aFS.getIntValue(feature); default: throw new IllegalArgumentException("Cannot get value of feature [" + feature.getName() + "] with type [" + feature.getRange().getName() + "]"); } }
@Override public List<? extends Position> generateSubPositions(int aCasId, AnnotationFS aFs, LinkCompareBehavior aLinkCompareBehavior) { List<Position> subPositions = new ArrayList<>(); for (LinkFeatureDecl decl : linkFeatures) { Feature linkFeature = aFs.getType().getFeatureByBaseName(decl.name); ArrayFS array = (ArrayFS) aFs.getFeatureValue(linkFeature); if (array == null) { continue; } for (FeatureStructure linkFS : array.toArray()) { String role = linkFS.getStringValue(linkFS.getType().getFeatureByBaseName( decl.roleFeature)); AnnotationFS target = (AnnotationFS) linkFS.getFeatureValue(linkFS.getType() .getFeatureByBaseName(decl.targetFeature)); Position pos = getPosition(aCasId, aFs, decl.name, role, target.getBegin(), target.getEnd(), aLinkCompareBehavior); subPositions.add(pos); } } return subPositions; } }
public static String getStringFeatValue(CAS aCasView, String aTypeS, String aFeatS) { String result = null; Type type = aCasView.getTypeSystem().getType(aTypeS); if (type != null) { FSIterator<AnnotationFS> idIter = aCasView.getAnnotationIndex(type).iterator(); while (idIter.isValid()) { org.apache.uima.cas.FeatureStructure idFS = idIter.get(); result = idFS.getStringValue(aCasView.getTypeSystem().getFeatureByFullName( aTypeS + ":" + aFeatS)); idIter.moveToNext(); } } return result; }
CASArtifact( @Nullable LabelAdapters labelAdapters, CAS cas ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.getView("metadata"); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); FSIndexRepository indexRepository = metadataCas.getIndexRepository(); artifactID = indexRepository.getIndex("artifactID", idType).iterator().get() .getStringValue(idFeat); metadataIndex = indexRepository.getIndex("metadata", metadataType); casMetadata = new CASMetadata(); }
/** * Returns a string value of a given Feature Structure. * * @param aCasView - * CAS view to retrieve data from * @param aTypeS - * Feature Type * @param aFeatS - * Feature Structure * @return feature value as string */ public static String getStringFeatValue(CAS aCasView, String aTypeS, String aFeatS) { String result = null; FSIterator idIter = aCasView.getAnnotationIndex(aCasView.getTypeSystem().getType(aTypeS)) .iterator(); while (idIter != null && idIter.isValid()) { org.apache.uima.cas.FeatureStructure idFS = idIter.get(); result = idFS.getStringValue(aCasView.getTypeSystem().getFeatureByFullName( aTypeS + ":" + aFeatS)); idIter.moveToNext(); } return result; }