@Test public void testSingular() throws Exception { jCas.setDocumentText("I went to the market and met Sally. She told me he would be late."); addWordTokens(jCas); processJCas(); assertEquals(4, JCasUtil.select(jCas, Person.class).size()); assertEquals("I", JCasUtil.selectByIndex(jCas, Person.class, 0).getCoveredText()); assertEquals("She", JCasUtil.selectByIndex(jCas, Person.class, 1).getCoveredText()); assertEquals("me", JCasUtil.selectByIndex(jCas, Person.class, 2).getCoveredText()); assertEquals("he", JCasUtil.selectByIndex(jCas, Person.class, 3).getCoveredText()); assertEquals(0, JCasUtil.select(jCas, Organisation.class).size()); }
@Test public void testExistingMixed() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("They refered to him as Senator Col John Smith"); Person p = new Person(jCas); p.setBegin(jCas.getDocumentText().indexOf("Col John Smith")); p.setEnd(p.getBegin() + "Col John Smith".length()); p.addToIndexes(); processJCas(); Collection<Person> select = JCasUtil.select(jCas, Person.class); assertEquals(1, select.size()); Person out = select.iterator().next(); assertEquals("Senator Col", out.getTitle()); assertEquals("Senator Col John Smith", out.getCoveredText()); }
@Test public void testSingleExisting() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("They refered to him as Sir John Smith"); Person p = new Person(jCas); p.setBegin(jCas.getDocumentText().indexOf("Sir John Smith")); p.setEnd(p.getBegin() + "Sir John Smith".length()); p.addToIndexes(); processJCas(); Collection<Person> select = JCasUtil.select(jCas, Person.class); assertEquals(1, select.size()); Person out = select.iterator().next(); assertEquals("Sir", out.getTitle()); assertEquals("Sir John Smith", out.getCoveredText()); }
@Test public void testSingleExisting2() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("They refered to him as Mr. John Smith"); Person p = new Person(jCas); p.setBegin(jCas.getDocumentText().indexOf("Mr. John Smith")); p.setEnd(p.getBegin() + "Mr. John Smith".length()); p.addToIndexes(); processJCas(); Collection<Person> select = JCasUtil.select(jCas, Person.class); assertEquals(1, select.size()); Person out = select.iterator().next(); assertEquals("Mr", out.getTitle()); assertEquals("Mr. John Smith", out.getCoveredText()); }
@Test public void test() throws Exception { jCas.setDocumentText("British Prime Minister Theresa May called for a snap election"); Nationality n = new Nationality(jCas, 0, 7); n.addToIndexes(); Person p = new Person(jCas, 8, 34); p.addToIndexes(); processJCas(); assertEquals(0, JCasUtil.select(jCas, Nationality.class).size()); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals( "British Prime Minister Theresa May", JCasUtil.selectByIndex(jCas, Person.class, 0).getCoveredText()); } }
@Test public void testOne() throws Exception { jCas.setDocumentText("His name was Andrew Smith (Andy)"); Person p = new Person(jCas, 13, 32); p.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Person.class).size()); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Andrew Smith", p1.getCoveredText()); Person p2 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertEquals("Andy", p2.getCoveredText()); assertEquals(p1.getReferent(), p2.getReferent()); }
@Test public void testMiddleAndEnd() throws Exception { jCas.setDocumentText("His name was Andrew (Drew) Smith (Obj X)"); Person p = new Person(jCas, 13, 40); p.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Person.class).size()); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Andrew (Drew) Smith", p1.getCoveredText()); Person p2 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertEquals("Obj X", p2.getCoveredText()); assertEquals(p1.getReferent(), p2.getReferent()); } }
@Test public void testExtendPeriod() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("They called him Dr. John Watson."); Person p = new Person(jCas); p.setBegin(20); p.setEnd(31); p.addToIndexes(); processJCas(); Collection<Person> select = JCasUtil.select(jCas, Person.class); assertEquals(1, select.size()); Person out = select.iterator().next(); assertEquals("Dr", out.getTitle()); assertEquals("Dr. John Watson", out.getCoveredText()); } }
@Test public void testMultiplePersonNoReferences() throws Exception { jCas.setDocumentText( "Mr Simon Brown, was caught stealing sausages. Brown was found guilty. Mr Peter Brown was acquitted."); Person pSimon = new Person(jCas, 0, 14); pSimon.addToIndexes(); Person pPeter = new Person(jCas, 70, 84); pPeter.addToIndexes(); processJCas(); assertEquals(3, JCasUtil.select(jCas, Person.class).size()); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Mr Simon Brown", p1.getCoveredText()); Person p2 = JCasUtil.selectByIndex(jCas, Person.class, 2); assertEquals("Mr Peter Brown", p2.getCoveredText()); Person p3 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertEquals("Brown", p3.getCoveredText()); assertNull(p3.getReferent()); }
@Test public void testMultiple() throws Exception { jCas.setDocumentText("His name was Andrew Smith (Drew) (Smithy)"); Person p = new Person(jCas, 13, 41); p.addToIndexes(); processJCas(); assertEquals(3, JCasUtil.select(jCas, Person.class).size()); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Andrew Smith", p1.getCoveredText()); Person p2 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertEquals("Drew", p2.getCoveredText()); Person p3 = JCasUtil.selectByIndex(jCas, Person.class, 2); assertEquals("Smithy", p3.getCoveredText()); assertEquals(p1.getReferent(), p2.getReferent()); assertEquals(p1.getReferent(), p3.getReferent()); }
@Test public void testSinglePersonNoReferences() throws Exception { jCas.setDocumentText("Mr Simon Brown, was caught stealing sausages. Brown was found guilty."); Person p = new Person(jCas, 0, 14); p.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Person.class).size()); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Mr Simon Brown", p1.getCoveredText()); Person p2 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertEquals("Brown", p2.getCoveredText()); assertNotNull(p1.getReferent()); assertEquals(p1.getReferent(), p2.getReferent()); }
@Test public void testNoPersonNestedApostrophe() throws Exception { jCas.setDocumentText("The UN's leader released a statement"); Organisation o = new Organisation(jCas, 4, 15); o.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Relation.class).size()); Relation r = JCasUtil.selectByIndex(jCas, Relation.class, 0); assertEquals("UN's leader", r.getCoveredText()); assertEquals("ROLE", r.getRelationshipType()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); Organisation org = JCasUtil.selectByIndex(jCas, Organisation.class, 0); assertEquals("UN", org.getCoveredText()); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); Person pers = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("leader", pers.getCoveredText()); }
@Test public void testNoPersonNested() throws Exception { jCas.setDocumentText("The UN Senior Advisor released a statement"); Organisation o = new Organisation(jCas, 4, 21); o.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Relation.class).size()); Relation r = JCasUtil.selectByIndex(jCas, Relation.class, 0); assertEquals("UN Senior Advisor", r.getCoveredText()); assertEquals("ROLE", r.getRelationshipType()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); Organisation org = JCasUtil.selectByIndex(jCas, Organisation.class, 0); assertEquals("UN", org.getCoveredText()); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); Person pers = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Senior Advisor", pers.getCoveredText()); }
@Test public void testNoPerson() throws Exception { jCas.setDocumentText("The UN Senior Advisor released a statement"); Organisation o = new Organisation(jCas, 4, 6); o.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Relation.class).size()); Relation r = JCasUtil.selectByIndex(jCas, Relation.class, 0); assertEquals("UN Senior Advisor", r.getCoveredText()); assertEquals("ROLE", r.getRelationshipType()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); Organisation org = JCasUtil.selectByIndex(jCas, Organisation.class, 0); assertEquals("UN", org.getCoveredText()); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); Person pers = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Senior Advisor", pers.getCoveredText()); }
@Test public void testNoPersonApostrophe() throws Exception { jCas.setDocumentText("The UN's leader released a statement"); Organisation o = new Organisation(jCas, 4, 6); o.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Relation.class).size()); Relation r = JCasUtil.selectByIndex(jCas, Relation.class, 0); assertEquals("UN's leader", r.getCoveredText()); assertEquals("ROLE", r.getRelationshipType()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); Organisation org = JCasUtil.selectByIndex(jCas, Organisation.class, 0); assertEquals("UN", org.getCoveredText()); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); Person pers = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("leader", pers.getCoveredText()); } }
@Test public void testSinglePersonWithReferences() throws Exception { jCas.setDocumentText("Mr Simon Brown, was caught stealing sausages. Brown was found guilty."); Person p = new Person(jCas, 0, 14); p.setReferent(new ReferenceTarget(jCas)); p.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Person.class).size()); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Mr Simon Brown", p1.getCoveredText()); Person p2 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertEquals("Brown", p2.getCoveredText()); assertNotNull(p1.getReferent()); assertEquals(p1.getReferent(), p2.getReferent()); }
@Test public void testSingleTypes() throws Exception { jCas.setDocumentText("John Smith was seen at London King's Cross"); Annotations.createPerson(jCas, 0, 4, "John"); Annotations.createPerson(jCas, 5, 10, "Smith"); Location l1 = Annotations.createLocation(jCas, 23, 29, "London", null); Location l2 = Annotations.createLocation(jCas, 30, 42, "King's Cross", null); processJCas("types", new String[] {"Person"}); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); Person p = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("John Smith", p.getCoveredText()); assertEquals("John Smith", p.getValue()); assertEquals(l1, JCasUtil.selectByIndex(jCas, Location.class, 0)); assertEquals(l2, JCasUtil.selectByIndex(jCas, Location.class, 1)); }
@Test public void testMultipleTypes() throws Exception { jCas.setDocumentText("John Smith was seen at London King's Cross"); Annotations.createPerson(jCas, 0, 4, "John"); Annotations.createPerson(jCas, 5, 10, "Smith"); Annotations.createLocation(jCas, 23, 29, "London", null); Annotations.createLocation(jCas, 30, 42, "King's Cross", null); processJCas("types", new String[] {"Person", "Location"}); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Person p = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("John Smith", p.getCoveredText()); assertEquals("John Smith", p.getValue()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("London King's Cross", l.getCoveredText()); assertEquals("London King's Cross", l.getValue()); }
@Test public void testMultipleAdjacentTypes() throws Exception { jCas.setDocumentText("John Smith London King's Cross"); Annotations.createPerson(jCas, 0, 4, "John"); Annotations.createPerson(jCas, 5, 10, "Smith"); Annotations.createLocation(jCas, 11, 17, "London", null); Annotations.createLocation(jCas, 18, 30, "King's Cross", null); processJCas("types", new String[] {"Person", "Location"}); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Person p = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("John Smith", p.getCoveredText()); assertEquals("John Smith", p.getValue()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("London King's Cross", l.getCoveredText()); assertEquals("London King's Cross", l.getValue()); }
@Test public void testSeparator() throws Exception { jCas.setDocumentText("John Smith was seen at London\tKing's Cross"); Annotations.createPerson(jCas, 0, 4, "John"); Annotations.createPerson(jCas, 8, 13, "Smith"); Annotations.createLocation(jCas, 26, 32, "London", null); Annotations.createLocation(jCas, 33, 45, "King's Cross", null); processJCas("types", new String[] {"Person", "Location"}); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Person p = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("John Smith", p.getCoveredText()); assertEquals("John Smith", p.getValue()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("London\tKing's Cross", l.getCoveredText()); assertEquals("London\tKing's Cross", l.getValue()); } }