@Override public Type getType(RutaBlock parent, RutaStream stream) { return stream.getCas().getAnnotationType(); }
public Type getSharedParentType(List<Type> types) { if (types == null || types.isEmpty()) { return cas.getAnnotationType(); } if (types.size() == 1) { return types.get(0); } TypeSystem typeSystem = cas.getTypeSystem(); Type parentType = types.get(0); for (Type type : types) { parentType = getSharedParentType(parentType, type, typeSystem); } return parentType; }
private Type getSharedParentType(Type type1, Type type2, TypeSystem typeSystem) { if (cas.getAnnotationType().equals(type1) || cas.getAnnotationType().equals(type2)) { return cas.getAnnotationType(); } if (type1.equals(type2)) { return type1; } if (typeSystem.subsumes(type1, type2)) { return type1; } if (typeSystem.subsumes(type2, type1)) { return type2; } Type parentType = typeSystem.getParent(type1); while (parentType != null && !cas.getAnnotationType().equals(parentType)) { if (typeSystem.subsumes(parentType, type2)) { return parentType; } } return cas.getAnnotationType(); } }
return annotationTypeDummy; } else { return cas.getAnnotationType();
/** * Get the CAS type for the given JCas wrapper class making sure it is or inherits from * {@link Annotation}. * * @param aCas * the CAS hosting the type system. * @param aJCasClass * the JCas wrapper class. * @return the CAS type. */ public static Type getAnnotationType(CAS aCas, Class<?> aJCasClass) { final Type type = getType(aCas, aJCasClass); if (!aCas.getTypeSystem().subsumes(aCas.getAnnotationType(), type)) { throw new IllegalArgumentException("Type [" + aJCasClass.getName() + "] is not an annotation type"); } return type; }
public <T> T getVariableValue(String name, Class<T> type) { boolean containsKey = variableValues.containsKey(name); Object result = variableValues.get(name); if (containsKey && result == null) { // TODO find the problem with the null values! // this might now work for word lists in another env. return type.cast(getInitialValue(name, type)); } if (result == annotationTypeDummy) { return type.cast(cas.getAnnotationType()); } if (result != null) { return type.cast(result); } else if (owner.getParent() != null) { return owner.getParent().getEnvironment().getVariableValue(name, type); } return null; }
/** * Get the CAS type for the given name making sure it is or inherits from Annotation. * * @param aCas * the CAS hosting the type system. * @param aTypeName * the fully qualified type name. * @return the CAS type. */ public static Type getAnnotationType(CAS aCas, String aTypeName) { Type type = getType(aCas, aTypeName); if (!aCas.getTypeSystem().subsumes(aCas.getAnnotationType(), type)) { throw new IllegalArgumentException("Type [" + aTypeName + "] is not an annotation type"); } return type; }
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; }
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; }
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; }
public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas) { TypeSystem ts = aCas.getTypeSystem(); LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> allIndexedFS = collectIndexed(aCas); Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>( Comparator.comparingInt(llcas::ll_getFSRef)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs)); // Remove all that are not annotations allReachableFS.entrySet().removeIf(e -> !ts.subsumes(aCas.getAnnotationType(), e.getKey().getType())); // Remove all that are indexed allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue()); // All that is left are non-index annotations return allReachableFS; } }
/** * Convenience method to iterator over all annotations of a given type. * * @param cas * the CAS containing the type system. * @param type * the type. * @return A collection of the selected type. * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a> */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static Collection<AnnotationFS> select(final CAS cas, final Type type) { if (!cas.getTypeSystem().subsumes(cas.getAnnotationType(), type)) { throw new IllegalArgumentException("Type [" + type.getName() + "] is not an annotation type"); } return (Collection) FSCollectionFactory.create(cas.getAnnotationIndex(type)); }
private void doMatch(ComposedRuleElementMatch match, TextMarkerStream stream, InferenceCrowd crowd) { List<AnnotationFS> textsMatched = match.getTextsMatched(); if (textsMatched == null || textsMatched.isEmpty()) { return; } int begin = textsMatched.get(0).getBegin(); int end = textsMatched.get(textsMatched.size() - 1).getEnd(); AnnotationFS annotation = stream.getCas().createAnnotation(stream.getCas().getAnnotationType(), begin, end); List<EvaluatedCondition> evaluatedConditions = new ArrayList<EvaluatedCondition>( conditions.size()); for (AbstractTextMarkerCondition condition : conditions) { crowd.beginVisit(condition, null); EvaluatedCondition eval = condition.eval(annotation, this, stream, crowd); crowd.endVisit(condition, null); evaluatedConditions.add(eval); } match.setConditionInfo(evaluatedConditions); match.evaluateInnerMatches(true); }
public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas) { TypeSystem ts = aCas.getTypeSystem(); LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> allIndexedFS = collectIndexed(aCas); Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>((fs1, fs2) -> llcas.ll_getFSRef(fs1) - llcas.ll_getFSRef(fs2)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs)); // Remove all that are not annotations allReachableFS.entrySet() .removeIf(e -> !ts.subsumes(aCas.getAnnotationType(), e.getKey().getType())); // Remove all that are indexed allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue()); // All that is left are non-index annotations return allReachableFS; } }
public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas) { TypeSystem ts = aCas.getTypeSystem(); LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> allIndexedFS = collectIndexed(aCas); Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>((fs1, fs2) -> llcas.ll_getFSRef(fs1) - llcas.ll_getFSRef(fs2)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs)); // Remove all that are not annotations allReachableFS.entrySet() .removeIf(e -> !ts.subsumes(aCas.getAnnotationType(), e.getKey().getType())); // Remove all that are indexed allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue()); // All that is left are non-index annotations return allReachableFS; } }
/** * Convenience method to iterator over all annotations of a given type. * * @param array * features structure array. * @param type * the type. * @return A collection of the selected type. * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a> */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static Collection<AnnotationFS> select(ArrayFS array, Type type) { final CAS cas = array.getCAS(); if (!cas.getTypeSystem().subsumes(cas.getAnnotationType(), type)) { throw new IllegalArgumentException("Type [" + type.getName() + "] is not an annotation type"); } return (Collection) FSCollectionFactory.create(array, type); }
@Override public void checkStateChanged(CheckStateChangedEvent event) { Object element = event.getElement(); boolean checked = event.getChecked(); Type type = null; if (element instanceof TypeTreeNode) { type = ((TypeTreeNode) element).getType(); } else if (element instanceof AnnotationTreeNode) { type = ((AnnotationTreeNode) element).getType(); } Type modeType = editor.getAnnotationMode(); if(!checked && modeType != null && modeType.equals(type)) { // reset mode to uima.tcas.Annotation if deselected getTreeViewer().setGrayed(new TypeTreeNode(null, type), false); Type annotationType = editor.getDocument().getCAS().getAnnotationType(); editor.setAnnotationMode(annotationType); } if (type != null && !editor.getAnnotationMode().equals(type)) { editor.setShownAnnotationType(type, checked); } }
/** * Create a {@link Collection} of the given type of feature structures. This collection is backed * by the CAS, either via an {@link CAS#getAnnotationIndex(Type)} or * {@link FSIndexRepository#getAllIndexedFS(Type)}. * * @param cas * the CAS to select from. * @param type * the type of feature structures to select. All sub-types are returned as well. * @return a {@link Collection} of the given type of feature structures backed live by the CAS. * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a> */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static Collection<FeatureStructure> create(CAS cas, Type type) { // If the type is an annotation type, we can use the annotation index, which directly // provides us with its size. If not, we have to use getAllIndexedFS() which we have to // scan from beginning to end in order to determine its size. TypeSystem ts = cas.getTypeSystem(); if (ts.subsumes(cas.getAnnotationType(), type)) { return (Collection) create(cas.getAnnotationIndex(type)); } else { return create(cas.getIndexRepository().getAllIndexedFS(type)); } }
AnnotationFS annotation = stream.getCas().createAnnotation(stream.getCas().getAnnotationType(), begin, end);
AnnotationFS anno1 = cas.createAnnotation(cas.getAnnotationType(), 0, 1); cas.addFsToIndexes(anno1); AnnotationFS anno2 = cas.createAnnotation(cas.getAnnotationType(), 0, 1);