@Override public void map(JCas jCas, Element element, AnnotationCollector collector) { if (element.tagName().equalsIgnoreCase("p")) { collector.add(new Paragraph(jCas)); } } }
private void addStructure() { final Header header = new Header(jCas, 0, 17); header.addToIndexes(); final Paragraph paragraph = new Paragraph(jCas, 18, 38); paragraph.addToIndexes(); final Footer footer = new Footer(jCas, 40, jCas.getDocumentText().length()); footer.addToIndexes(); }
@Test public void testSelectSimple() throws UIMAException, InvalidParameterException { Paragraph paragraph = new Paragraph(jCas); paragraph.setBegin(0); paragraph.setDepth(1); paragraph.setEnd(TEXT.length()); paragraph.addToIndexes(); RecordStructureManager manager = new RecordStructureManager(StructureHierarchy.build(jCas, structuralClasses)); Optional<Structure> select = manager.select("Paragraph"); assertTrue(select.isPresent()); assertEquals(paragraph, select.get()); }
final Paragraph d = new Paragraph(jCas); d.setBegin(19); d.setEnd(19);
@Test public void testSelectNthTwo() throws InvalidParameterException { 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(); RecordStructureManager manager = new RecordStructureManager(StructureHierarchy.build(jCas, structuralClasses)); Optional<Structure> select1 = manager.select("Paragraph:nth-of-type(1)"); assertTrue(select1.isPresent()); assertEquals(paragraph1, select1.get()); assertNotEquals(paragraph2, select1.get()); Optional<Structure> select2 = manager.select("Paragraph:nth-of-type(2)"); assertTrue(select2.isPresent()); assertEquals(paragraph2, select2.get()); assertNotEquals(paragraph1, select2.get()); Optional<Structure> select3 = manager.select("Paragraph:nth-of-type(3)"); assertFalse(select3.isPresent()); }
@Before public void setup() throws IOException { jCas.setDocumentText(TEXT); tempDirectory = Files.createTempDirectory(TemplateFieldJsonReportConsumerTest.class.getSimpleName()); tempDirectory.toFile().deleteOnExit(); DocumentAnnotation documentAnnotation = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); documentAnnotation.setSourceUri(SOURCEURI); Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(1); paragraph1.setEnd(52); paragraph1.addToIndexes(); Paragraph paragraph2 = new Paragraph(jCas); paragraph2.setBegin(53); paragraph2.setDepth(1); paragraph2.setEnd(105); paragraph2.addToIndexes(); TemplateField field = new TemplateField(jCas); field.setBegin(53); field.setEnd(105); field.addToIndexes(); }
protected void addParagraphAnnotations() { Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(1); paragraph1.addToIndexes(); Paragraph paragraph2 = new Paragraph(jCas); paragraph2.setBegin(53); paragraph2.setDepth(1); paragraph2.addToIndexes(); Paragraph paragraph3 = new Paragraph(jCas); paragraph3.setBegin(106); paragraph3.setDepth(1); Paragraph paragraph4 = new Paragraph(jCas); paragraph4.setBegin(159); paragraph4.setDepth(1); Paragraph paragraph5 = new Paragraph(jCas); paragraph5.setBegin(212); paragraph5.setDepth(1); Paragraph paragraph6 = new Paragraph(jCas); paragraph6.setBegin(213); paragraph6.setDepth(1);
section.addToIndexes(); Paragraph paragraph = new Paragraph(jCas); paragraph.setBegin(0); paragraph.setDepth(2);
@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()); }
documentAnnotation.setSourceUri(SOURCEURI); Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(1); paragraph1.addToIndexes(); Paragraph paragraph2 = new Paragraph(jCas); paragraph2.setBegin(53); paragraph2.setDepth(1); paragraph2.addToIndexes(); Paragraph paragraph3 = new Paragraph(jCas); paragraph3.setBegin(106); paragraph3.setDepth(1); paragraph3.addToIndexes(); Paragraph paragraph4 = new Paragraph(jCas); paragraph4.setBegin(159); paragraph4.setDepth(1);
assertEquals(e, "Hello".length()); builder.addAnnotations(Arrays.asList(new Entity(jCas), new Paragraph(jCas)), s, e, 6);
@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()); }
@Before public void setup() throws IOException { jCas.setDocumentText(TEXT); tempDirectory = Files.createTempDirectory(AllAnnotationsJsonConsumerTest.class.getSimpleName()); tempDirectory.toFile().deleteOnExit(); DocumentAnnotation documentAnnotation = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); documentAnnotation.setSourceUri(SOURCEURI); Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(1); paragraph1.setEnd(52); paragraph1.addToIndexes(); Person entity1 = new Person(jCas); entity1.setBegin(70); entity1.setEnd(73); entity1.setValue("cat"); entity1.addToIndexes(); Event event = new Event(jCas); event.setBegin(53); event.setEnd(105); event.setArguments(new StringArray(jCas, 2)); event.setArguments(0, "cat"); event.setArguments(1, "dog"); event.setEntities(new FSArray(jCas, 1)); event.setEntities(0, entity1); event.addToIndexes(); }