/** * Make fields from definitions and look up the location in the structure * * @param structureHierarchy the structure hierarchy * @param fields the fields * @return the list of configurations */ private List<TemplateFieldConfiguration> makeFields( final CoveringStructureHierarchy structureHierarchy, Collection<TemplateFieldDefinition> definitions) { List<TemplateFieldConfiguration> fields = new ArrayList<>(); for (TemplateFieldDefinition templateFieldDefinition : definitions) { String fieldPath = structureHierarchy.generatePath(templateFieldDefinition).toString(); TemplateFieldConfiguration field = makeField(templateFieldDefinition, fieldPath); fields.add(field); } return fields; }
/** * Generate the covered paths, reducing to the lowest depth. * * @param structureHierarchy the structure hierarchy * @param coveredStructures the covered structures * @param depth the maximum depth * @return list of paths for the covered structures */ private List<String> generateCoveredPaths( ItemHierarchy<Structure> structureHierarchy, List<Structure> coveredStructures, int depth) { LinkedHashSet<String> collect = coveredStructures .stream() .map(s -> structureHierarchy.getSelectorPath(s).toDepth(depth).toString()) .collect(Collectors.toCollection(LinkedHashSet::new)); Builder<String> builder = ImmutableList.<String>builder(); String parent = collect.iterator().next(); builder.add(parent); for (String path : collect) { if (!path.startsWith(parent)) { builder.add(path); parent = path; } } return builder.build(); }
preceding.isPresent() ? structureHierarchy.getSelectorPath(preceding.get()).toString() : ""; following.isPresent() ? structureHierarchy.getSelectorPath(following.get()).toString() : ""; if (coveringStructure.isPresent() && coveredStructures.contains(coveringStructure.get())) { Structure repeatingUnit = coveringStructure.get(); minimalRepeat = structureHierarchy.getSelectorPath(repeatingUnit).toString();
@Test public void testGenerateTwo() { Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(1); paragraph1.setEnd(20); paragraph1.addToIndexes(); Paragraph paragraph2 = new Paragraph(jCas); paragraph2.setBegin(20); paragraph2.setDepth(1); paragraph2.setEnd(TEXT.length()); paragraph2.addToIndexes(); ItemHierarchy<Structure> structureHierarchy = StructureHierarchy.build(jCas, structuralClasses); SelectorPath path1 = structureHierarchy.getSelectorPath(paragraph1); SelectorPath path2 = structureHierarchy.getSelectorPath(paragraph2); assertEquals("Paragraph:nth-of-type(1)", path1.toString()); assertEquals("Paragraph:nth-of-type(2)", path2.toString()); }
@Test public void testGenerateNested() { Section section = new Section(jCas); section.setBegin(0); section.setDepth(1); section.setEnd(TEXT.length()); section.addToIndexes(); Paragraph paragraph = new Paragraph(jCas); paragraph.setBegin(0); paragraph.setDepth(2); paragraph.setEnd(TEXT.length()); paragraph.addToIndexes(); ItemHierarchy<Structure> structureHierarchy = StructureHierarchy.build(jCas, structuralClasses); SelectorPath path1 = structureHierarchy.getSelectorPath(paragraph); assertEquals("Section:nth-of-type(1) > Paragraph:nth-of-type(1)", path1.toString()); }
@Test public void testGenerateSimple() { Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(1); paragraph1.setEnd(20); paragraph1.addToIndexes(); ItemHierarchy<Structure> structureHierarchy = StructureHierarchy.build(jCas, structuralClasses); SelectorPath path = structureHierarchy.getSelectorPath(paragraph1); assertEquals("Paragraph:nth-of-type(1)", path.toString()); }
@Test public void testGenerateNested2() { Section section = new Section(jCas); section.setBegin(0); section.setDepth(1); section.setEnd(TEXT.length()); section.addToIndexes(); Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(2); paragraph1.setEnd(20); paragraph1.addToIndexes(); Paragraph paragraph2 = new Paragraph(jCas); paragraph2.setBegin(20); paragraph2.setDepth(2); paragraph2.setEnd(TEXT.length()); paragraph2.addToIndexes(); ItemHierarchy<Structure> structureHierarchy = StructureHierarchy.build(jCas, structuralClasses); SelectorPath path1 = structureHierarchy.getSelectorPath(paragraph1); SelectorPath path2 = structureHierarchy.getSelectorPath(paragraph2); assertEquals("Section:nth-of-type(1) > Paragraph:nth-of-type(1)", path1.toString()); assertEquals("Section:nth-of-type(1) > Paragraph:nth-of-type(2)", path2.toString()); }
@Test public void testGenerateNestedToDepth1() { Section section = new Section(jCas); section.setBegin(0); section.setDepth(1); section.setEnd(TEXT.length()); section.addToIndexes(); Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(2); paragraph1.setEnd(20); paragraph1.addToIndexes(); Paragraph paragraph2 = new Paragraph(jCas); paragraph2.setBegin(20); paragraph2.setDepth(2); paragraph2.setEnd(TEXT.length()); paragraph2.addToIndexes(); ItemHierarchy<Structure> structureHierarchy = StructureHierarchy.build(jCas, structuralClasses); SelectorPath path1 = structureHierarchy.getSelectorPath(paragraph1); SelectorPath path2 = structureHierarchy.getSelectorPath(paragraph1); assertEquals("Section:nth-of-type(1)", path1.toDepth(1).toString()); assertEquals("Section:nth-of-type(1)", path2.toDepth(1).toString()); }