private Matcher<FST> getSubmatcher(FST ref) { Type refType = ref.getType(); Matcher<FST> submatcher = type2matcher.get(refType); while (submatcher == null) { refType = ts.getParent(refType); if (refType == null) { break; } submatcher = type2matcher.get(refType); } if (submatcher == null) { throw new IllegalStateException(String.format( "There is no submatcher for type %s", refType)); } return submatcher; }
public void addBegin(AnnotationFS annotation, Type type) { Set<AnnotationFS> list = beginMap.get(type); if (list == null) { list = new HashSet<AnnotationFS>(INITIAL_CAPACITY); beginMap.put(type, list); } list.add(annotation); if (!lowMemoryProfile) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { addBegin(annotation, parent); } } }
public void addEnd(AnnotationFS annotation, Type type) { Set<AnnotationFS> list = endMap.get(type); if (list == null) { list = new HashSet<AnnotationFS>(INITIAL_CAPACITY); endMap.put(type, list); } list.add(annotation); if (!lowMemoryProfile) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { addEnd(annotation, parent); } } }
public void removeEnd(AnnotationFS annotation, Type type) { Set<AnnotationFS> list = endMap.get(type); if (list != null) { list.remove(annotation); if (list.isEmpty()) { endMap.remove(annotation.getType()); } } if (!lowMemoryProfile) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { removeEnd(annotation, parent); } } }
public void removeBegin(AnnotationFS annotation, Type type) { Set<AnnotationFS> list = beginMap.get(type); if (list != null) { list.remove(annotation); if (list.isEmpty()) { beginMap.remove(annotation.getType()); } } if (!lowMemoryProfile) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { removeBegin(annotation, parent); } } }
private boolean isElevatedType(TypeSystem aTS, Type aType) { // Elevated types do not contribute any new features if (aType.getFeatures().stream().anyMatch(f -> f.getDomain().equals(aType))) { return false; } // Elevated types have only sub-types which are also elevated types if (aTS.getDirectSubtypes(aType).stream().anyMatch(t -> !isElevatedType(aTS, t))) { return false; } // Elevated types do not inherit from Annotation if (aTS.getParent(aType).equals(aTS.getType(CAS.TYPE_NAME_ANNOTATION))) { return false; } // Hm, ok, so this looks like an elevated type return true; }
private boolean isElevatedType(TypeSystem aTS, Type aType) { // Elevated types do not contribute any new features if (aType.getFeatures().stream().anyMatch(f -> f.getDomain().equals(aType))) { return false; } // Elevated types have only sub-types which are also elevated types if (aTS.getDirectSubtypes(aType).stream().anyMatch(t -> !isElevatedType(aTS, t))) { return false; } // Elevated types do not inherit from Annotation if (aTS.getParent(aType).equals(aTS.getType(CAS.TYPE_NAME_ANNOTATION))) { return false; } // Hm, ok, so this looks like an elevated type return true; }
@SuppressWarnings("unchecked") public void removeBegin(AnnotationFS annotation, Type type) { int code = ((TypeImpl) type).getCode(); Collection<Object> set = (Collection<Object>) beginMap[code]; if (set != null) { set.remove(annotation); if (set.isEmpty()) { beginMap[code] = null; } } if (!lowMemoryProfile) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { removeBegin(annotation, parent); } } }
@SuppressWarnings("unchecked") public void removeEnd(AnnotationFS annotation, Type type) { int code = ((TypeImpl) type).getCode(); Collection<Object> set = (Collection<Object>) endMap[code]; if (set != null) { set.remove(annotation); if (set.isEmpty()) { endMap[code] = null; } } if (!lowMemoryProfile) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { removeEnd(annotation, parent); } } }
public void removePartOf(Type type) { Integer count = partOf.get(type.getName()); if (count != null && count > 0) { count--; partOf.put(type.getName(), count); } if (!lowMemoryProfile) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { removePartOf(parent); } } }
@SuppressWarnings("unchecked") public void addEnd(AnnotationFS annotation, Type type) { empty = false; int code = ((TypeImpl) type).getCode(); Collection<Object> set = (Collection<Object>) endMap[code]; if (set == null) { set = new ArrayList<Object>(INITIAL_CAPACITY); endMap[code] = set; } set.add(annotation); if (!lowMemoryProfile && !type.getName().equals(ROOT_TYPE1) && !type.getName().equals(ROOT_TYPE2)) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { addEnd(annotation, parent); } } }
@SuppressWarnings("unchecked") public void addBegin(AnnotationFS annotation, Type type) { empty = false; int code = ((TypeImpl) type).getCode(); Collection<Object> set = (Collection<Object>) beginMap[code]; if (set == null) { set = new ArrayList<Object>(INITIAL_CAPACITY); beginMap[code] = set; } set.add(annotation); if (!lowMemoryProfile && !type.getName().equals(ROOT_TYPE1) && !type.getName().equals(ROOT_TYPE2)) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { addBegin(annotation, parent); } } }
public void addPartOf(Type type) { Integer count = partOf.get(type.getName()); if (count == null) { count = 0; } count++; partOf.put(type.getName(), count); if (!lowMemoryProfile) { TypeSystem typeSystem = getCAS().getTypeSystem(); Type parent = typeSystem.getParent(type); if (parent != null) { addPartOf(parent); } } }
if (!aTS.getTopType().equals(aTS.getParent(linkType))) { return false;
if (!aTS.getParent(aType).equals(aTS.getType(CAS.TYPE_NAME_ANNOTATION_BASE))) { return Optional.empty();
/** * Update. */ private void update() { cachedResult.clear(); // for aggregates, this is the fully-merged type system // for all systems, it is the type system with imports resolved TypeSystemDescription typeSystemDescription = modelRoot.getMergedTypeSystemDescription(); if (typeSystemDescription == null) return; // cleared table TypeDescription[] types = typeSystemDescription.getTypes(); TypeSystem typeSystem = modelRoot.descriptorCAS.get().getTypeSystem(); String typeName; Map allTypes = modelRoot.allTypes.get(); for (int i = 0; i < types.length; i++) { cachedResult.add(typeName = types[i].getName()); Type nextType = (Type) allTypes.get(typeName); while (nextType != null) { nextType = typeSystem.getParent(nextType); if (nextType != null) cachedResult.add(nextType.getName()); } } } }
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(); } }
private void insertFS(FeatureStructure fs, Type type, CAS cas, boolean withParents) { TypeTreeNode typeTreeNode = getTreeNode(type, cas); FSTreeNode node = createFSNode(typeTreeNode, fs); typeTreeNode.addChild(node); if (withParents) { Type parent = fs.getCAS().getTypeSystem().getParent(type); if (parent != null) { insertFS(fs, parent, cas, withParents); } } }
private static boolean isSlotFeature(TypeSystem aTypeSystem, Feature feat) { // This could be written more efficiently using a single conjunction. The reason this // has not been done is to facilitate debugging. boolean multiValued = feat.getRange().isArray() || aTypeSystem .subsumes(aTypeSystem.getType(CAS.TYPE_NAME_LIST_BASE), feat.getRange()); if (!multiValued) { return false; } boolean linkInheritsFromTop = CAS.TYPE_NAME_TOP .equals(aTypeSystem.getParent(feat.getRange().getComponentType()).getName()); boolean hasTargetFeature = feat.getRange().getComponentType() .getFeatureByBaseName(FEAT_SLOT_TARGET) != null; boolean hasRoleFeature = feat.getRange().getComponentType() .getFeatureByBaseName(FEAT_SLOT_ROLE) != null; return linkInheritsFromTop && hasTargetFeature && hasRoleFeature; }
private static boolean isSlotFeature(TypeSystem aTypeSystem, Feature feat) { // This could be written more efficiently using a single conjunction. The reason this // has not been done is to facilitate debugging. boolean multiValued = feat.getRange().isArray() || aTypeSystem .subsumes(aTypeSystem.getType(CAS.TYPE_NAME_LIST_BASE), feat.getRange()); if (!multiValued) { return false; } boolean linkInheritsFromTop = CAS.TYPE_NAME_TOP .equals(aTypeSystem.getParent(feat.getRange().getComponentType()).getName()); boolean hasTargetFeature = feat.getRange().getComponentType() .getFeatureByBaseName(FEAT_SLOT_TARGET) != null; boolean hasRoleFeature = feat.getRange().getComponentType() .getFeatureByBaseName(FEAT_SLOT_ROLE) != null; return linkInheritsFromTop && hasTargetFeature && hasRoleFeature; }