/** * Build the structure hierarchy, by first collecting all the annotations. * * @param jCas the jCas * @param annotationTypes the annotations classes to use * @return the root structure node */ protected static <T extends Annotation> Node<T> buildRoot( JCas jCas, Set<Class<? extends T>> annotationTypes) { return build( TypeUtils.filterAnnotations( JCasUtil.select(jCas, BaleenAnnotation.class), annotationTypes)); }
/** * Build the structure hierarchy, by first collecting all the annotations. * * @param jCas the jCas * @param annotationTypes the annotations classes to use * @return the root structure node */ protected static <T extends Annotation> Node<T> buildRoot( JCas jCas, Set<Class<? extends T>> annotationTypes) { return build( TypeUtils.filterAnnotations( JCasUtil.select(jCas, BaleenAnnotation.class), annotationTypes)); }
/** * Build the structure hierarchy for the given jCas, using only the structural classes provided. * * <p>The structure is built by first using the offset of the Structure annotation and then using * the depth. * * @param jCas the jCas * @param types the structural classes * @return the Structure base AnnotationHierachy */ public static StructureHierarchy build(JCas jCas, Set<Class<? extends Structure>> types) { final List<Structure> structures = filterAnnotations(JCasUtil.select(jCas, Structure.class), types); return new StructureHierarchy(AnnotationHierarchyBuilder.build(structures)); } }
/** * Build the structure hierarchy for the given jCas, using only the structural classes provided. * * <p>The structure is built by first using the offset of the Structure annotation and then using * the depth. * * @param jCas the jCas * @param types the structural classes * @return the Structure base AnnotationHierachy */ public static StructureHierarchy build(JCas jCas, Set<Class<? extends Structure>> types) { final List<Structure> structures = filterAnnotations(JCasUtil.select(jCas, Structure.class), types); return new StructureHierarchy(AnnotationHierarchyBuilder.build(structures)); } }
/** * Build the structure hierarchy, first by sorting the structure, by offset and depth, then using * a deque to recursively create the structure. * * @param structures the list of all structural annotations * @return the root structure node */ protected static <T extends Annotation> AnnotationNode<T> build(final List<T> annotations) { Collections.sort( annotations, (s1, s2) -> { int compare = Integer.compare(s1.getBegin(), s2.getBegin()); if (compare == 0) { compare = Integer.compare(s2.getEnd(), s1.getEnd()); } if (compare == 0) { compare = Integer.compare(getDepth(s1), getDepth(s2)); } return compare; }); final AnnotationNode<T> parent = new AnnotationNode<>(null, null); final Deque<AnnotationNode<T>> deque = new ArrayDeque<>(); deque.push(parent); annotations.forEach(s -> build(deque, s)); return parent; }
/** * Build the structure hierarchy, first by sorting the structure, by offset and depth, then using * a deque to recursively create the structure. * * @param structures the list of all structural annotations * @return the root structure node */ protected static <T extends Annotation> AnnotationNode<T> build(final List<T> annotations) { Collections.sort( annotations, (s1, s2) -> { int compare = Integer.compare(s1.getBegin(), s2.getBegin()); if (compare == 0) { compare = Integer.compare(s2.getEnd(), s1.getEnd()); } if (compare == 0) { compare = Integer.compare(getDepth(s1), getDepth(s2)); } return compare; }); final AnnotationNode<T> parent = new AnnotationNode<>(null, null); final Deque<AnnotationNode<T>> deque = new ArrayDeque<>(); deque.push(parent); annotations.forEach(s -> build(deque, s)); return parent; }