private Object getPrimitiveFunction(FeatureStructure fs, String function) { if (function.equalsIgnoreCase("coveredText()")) { return ((Annotation) fs).getCoveredText(); } else if (function.equalsIgnoreCase("type()")) { return fs.getType().getName(); } return null; }
/** * Copies a generic {@code FeatureStructure} to another of the same type. * * @param from {@code FeatureStructure} to copy from. * @param to {@code FeatureStructure} to copy to. */ public void copy(FeatureStructure from, FeatureStructure to) { fsCopiers.getOrDefault(from.getType().getName(), this::defaultCopy).accept(from, to); to.getCAS().addFsToIndexes(to); } }
public boolean match(FeatureStructure fs) { // compile(((FeatureStructureImpl) fs).getCAS().getTypeSystem()); final int max = this.featNames.size(); for (int i = 0; i < max; i++) { Feature feat = fs.getType().getFeatureByBaseName(this.featNames.get(i)); if (feat == null) { return false; } fs = fs.getFeatureValue(feat); } return this.cons.match(fs); }
private void fillFeatures(FeatureStructure oldFS, FeatureStructure newFS, Type newType, Map<Integer, Integer> new2oldBegin, Map<Integer, Integer> new2oldEnd, RutaStream stream, RuleMatch match) { for (Object obj : newType.getFeatures()) { Feature feature = (Feature) obj; String sn = feature.getShortName(); if (!"sofa".equals(sn) && !"begin".equals(sn) && !"end".equals(sn)) { Feature oldFeature = oldFS.getType().getFeatureByBaseName(sn); fillFeature(oldFS, oldFeature, newFS, feature, new2oldBegin, new2oldEnd, stream, match); } } }
private void fillFeatures(FeatureStructure oldFS, FeatureStructure newFS, Type newType, Map<Integer, Integer> new2oldBegin, Map<Integer, Integer> new2oldEnd, TextMarkerStream stream, RuleMatch match) { for (Object obj : newType.getFeatures()) { Feature feature = (Feature) obj; String sn = feature.getShortName(); if (!"sofa".equals(sn) && !"begin".equals(sn) && !"end".equals(sn)) { Feature oldFeature = oldFS.getType().getFeatureByBaseName(sn); fillFeature(oldFS, oldFeature, newFS, feature, new2oldBegin, new2oldEnd, stream, match); } } }
private List<AnnotationFS> collectLinks(FeatureStructure aChain) { List<AnnotationFS> links = new ArrayList<>(); // Now we seek the link within the current chain AnnotationFS linkFs = (AnnotationFS) aChain.getFeatureValue(aChain.getType() .getFeatureByBaseName(getChainFirstFeatureName())); while (linkFs != null) { links.add(linkFs); linkFs = getNextLink(linkFs); } return links; }
@Override public void insertFS(FeatureStructure fs, CAS cas, boolean withParents) { Type type = fs.getType(); if (type.getShortName().equals("RutaBasic") || type.getShortName().equals("DebugBlockApply") || type.getShortName().equals("DebugMatchedRuleMatch") || type.getShortName().equals("DebugFailedRuleMatch") || type.getShortName().equals("DebugScriptApply") || type.getShortName().equals("DebugRuleElementMatches") || type.getShortName().equals("DebugRuleElementMatch")) { return; } insertFS(fs, type, cas, withParents); }
/** * Get the first link of a chain from the chain head feature structure. */ private AnnotationFS getFirstLink(FeatureStructure aChain) { return (AnnotationFS) aChain.getFeatureValue(aChain.getType().getFeatureByBaseName( getChainFirstFeatureName())); }
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)); } } } }
/** * Set the first link of a chain in the chain head feature structure. */ private void setFirstLink(FeatureStructure aChain, AnnotationFS aLink) { aChain.setFeatureValue(aChain.getType().getFeatureByBaseName(getChainFirstFeatureName()), aLink); }
/** * Get the first link of a chain from the chain head feature structure. */ private AnnotationFS getFirstLink(FeatureStructure aChain) { return (AnnotationFS) aChain.getFeatureValue(aChain.getType().getFeatureByBaseName( getChainFirstFeatureName())); }
/** * Set the first link of a chain in the chain head feature structure. */ private void setFirstLink(FeatureStructure aChain, AnnotationFS aLink) { aChain.setFeatureValue(aChain.getType().getFeatureByBaseName(getChainFirstFeatureName()), aLink); }
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 Set<FeatureStructure> getNonIndexedFSes(CAS aCas) { TypeSystem ts = aCas.getTypeSystem(); Set<FeatureStructure> allIndexedFS = collectIndexed(aCas); Set<FeatureStructure> allReachableFS = collectReachable(aCas); // Remove all that are indexed allReachableFS.removeAll(allIndexedFS); // Remove all that are not annotations allReachableFS.removeIf(fs -> !ts.subsumes(aCas.getAnnotationType(), fs.getType())); // All that is left are non-index annotations return allReachableFS; }
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; }
@Override public List<LinkWithRoleModel> getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS) { Feature linkFeature = aFS.getType().getFeatureByBaseName(aFeature.getName()); return wrapFeatureValue(aFeature, aFS.getCAS(), aFS.getFeatureValue(linkFeature)); }
@Override public List<LinkWithRoleModel> getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS) { Feature linkFeature = aFS.getType().getFeatureByBaseName(aFeature.getName()); return wrapFeatureValue(aFeature, aFS.getCAS(), aFS.getFeatureValue(linkFeature)); }