@Test public void testGetMissingStructure() throws InvalidParameterException { assertFalse(recordStructureManager.select("Document > Break").isPresent()); }
@Test public void testGetFirstParagraph() throws InvalidParameterException { Optional<Structure> structure = recordStructureManager.select("Document > Paragraph:nth-of-type(1)"); assertTrue(structure.isPresent()); assertEquals(paragraph1, structure.get()); }
@Test public void testCanGetAfterMissingRepeat() throws InvalidParameterException { SelectorPath minimal = SelectorPath.parse("Document > Paragraph"); RepeatSearch repeatUnit = new RepeatSearch(ImmutableList.of(minimal), minimal); recordStructureManager.repeatRecord(Optional.empty(), repeatUnit, true); Optional<Structure> adjusted = recordStructureManager.select("Document > Paragraph:nth-of-type(2)"); assertTrue(adjusted.isPresent()); assertEquals(paragraph1, adjusted.get()); } }
@Test public void testCanNotRepeatMissingStructure() throws InvalidParameterException { SelectorPath minimal = SelectorPath.parse("Table"); RepeatSearch repeatSearch = new RepeatSearch(ImmutableList.of(minimal), minimal); Optional<Structure> structure = recordStructureManager.select("Document > Heading"); assertFalse(recordStructureManager.repeatRecord(structure, repeatSearch, true).isPresent()); }
@Test public void testCanGetAfterRepeatParagraph() throws InvalidParameterException { SelectorPath minimal = SelectorPath.parse("Document > Paragraph:nth-of-type(1)"); RepeatSearch repeatUnit = new RepeatSearch(ImmutableList.of(minimal), minimal); Optional<Structure> structure = recordStructureManager.select("Document > Heading"); Optional<Structure> repeat1 = recordStructureManager.repeatRecord(structure, repeatUnit, true); Optional<Structure> repeat2 = recordStructureManager.repeatRecord(repeat1, repeatUnit, false); Optional<Structure> repeat3 = recordStructureManager.repeatRecord(repeat2, repeatUnit, false); recordStructureManager.repeatRecord(repeat3, repeatUnit, false); Optional<Structure> adjusted = recordStructureManager.select("Document > Paragraph:nth-of-type(2)"); assertTrue(adjusted.isPresent()); assertEquals(paragraph5, adjusted.get()); }
new RecordStructureManager(StructureHierarchy.build(jCas, structuralClasses)); Optional<Structure> selectNest1 = manager.select("Section > Paragraph:nth-of-type(1)"); assertTrue(selectNest1.isPresent()); assertEquals(paragraph, selectNest1.get()); Optional<Structure> selectNest2 = manager.select("Section > Paragraph"); assertTrue(selectNest2.isPresent()); assertEquals(paragraph, selectNest2.get()); Optional<Structure> selectNest3 = manager.select("Section:nth-of-type(1) > Paragraph"); assertTrue(selectNest3.isPresent()); assertEquals(paragraph, selectNest3.get()); Optional<Structure> selectRoot = manager.select("Section"); assertTrue(selectRoot.isPresent()); assertEquals(section, selectRoot.get());
@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()); }
@Test public void testCanRepeatParagraph() throws InvalidParameterException { SelectorPath minimal = SelectorPath.parse("Document > Paragraph:nth-of-type(1)"); RepeatSearch repeatUnit = new RepeatSearch(ImmutableList.of(minimal), minimal); Optional<Structure> structure = recordStructureManager.select("Document > Heading"); Optional<Structure> repeat1 = recordStructureManager.repeatRecord(structure, repeatUnit, true); assertTrue(repeat1.isPresent()); assertEquals(paragraph1, repeat1.get()); Optional<Structure> repeat2 = recordStructureManager.repeatRecord(repeat1, repeatUnit, false); assertTrue(repeat2.isPresent()); assertEquals(paragraph2, repeat2.get()); Optional<Structure> repeat3 = recordStructureManager.repeatRecord(repeat2, repeatUnit, false); assertTrue(repeat3.isPresent()); assertEquals(paragraph3, repeat3.get()); Optional<Structure> repeat4 = recordStructureManager.repeatRecord(repeat3, repeatUnit, false); assertTrue(repeat4.isPresent()); assertEquals(paragraph4, repeat4.get()); Optional<Structure> repeat5 = recordStructureManager.repeatRecord(repeat4, repeatUnit, false); assertFalse(repeat5.isPresent()); }
@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()); }