return Optional.of(new Nationality(jCas)); case "Organisation": return Optional.of(new Organisation(jCas)); case "Person": return Optional.of(new Person(jCas));
return Optional.of(new Nationality(jCas)); case "Organisation": return Optional.of(new Organisation(jCas)); case "Person": return Optional.of(new Person(jCas));
public static Organisation createOrganisation(JCas jCas, int begin, int end, String value) { Organisation p = new Organisation(jCas); p.setValue(value); p.setBegin(begin); p.setEnd(end); p.addToIndexes(); return p; }
@Test public void testStrictHeadMatch() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "The Florida Supreme Court sat today, and the Florida Court made a decision."; jCas.setDocumentText(text); Organisation fsc = new Organisation(jCas); fsc.setBegin(text.indexOf("Florida Supreme Court")); fsc.setEnd(fsc.getBegin() + "Florida Supreme Court".length()); fsc.addToIndexes(); Organisation fc = new Organisation(jCas); fc.setBegin(text.indexOf("Florida Court")); fc.setEnd(fc.getBegin() + "Florida Court".length()); fc.addToIndexes(); processJCas(); processJCasWithSieve(5); List<ReferenceTarget> targets = new ArrayList<>(JCasUtil.select(jCas, ReferenceTarget.class)); assertEquals(1, targets.size()); }
@Test public void testRelaxedStringMatch() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "The University of Warwick is near Coventry and that was the University at which Chris studied."; // university of warwick - university jCas.setDocumentText(text); Person chris = new Person(jCas); chris.setBegin(text.indexOf("Chris")); chris.setEnd(chris.getBegin() + "Chris".length()); chris.addToIndexes(); Organisation uow = new Organisation(jCas); uow.setBegin(text.indexOf("University of Warwick")); uow.setEnd(uow.getBegin() + "University of Warwick".length()); uow.addToIndexes(); Organisation u = new Organisation(jCas); u.setBegin(text.indexOf("University", uow.getEnd())); u.setEnd(u.getBegin() + "University".length()); u.addToIndexes(); processJCas(); processJCasWithSieve(2); List<ReferenceTarget> targets = new ArrayList<>(JCasUtil.select(jCas, ReferenceTarget.class)); List<Organisation> location = new ArrayList<>(JCasUtil.select(jCas, Organisation.class)); assertEquals(1, targets.size()); assertSame(targets.get(0), location.get(0).getReferent()); assertSame(targets.get(0), location.get(1).getReferent()); }
@Test public void testPreciseConstructAcronym() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "The British Broadcasting Corporation or the BBC if you prefer shows television programmes."; // British Broadcasting Corporation - BBC jCas.setDocumentText(text); // We need these in otherwise we just get one long setence from the mention detector Organisation beeb = new Organisation(jCas); beeb.setBegin(text.indexOf("British Broadcasting Corporation")); beeb.setEnd(beeb.getBegin() + "British Broadcasting Corporation".length()); beeb.addToIndexes(); Organisation bbc = new Organisation(jCas); bbc.setBegin(text.indexOf("BBC")); bbc.setEnd(bbc.getBegin() + "BBC".length()); bbc.addToIndexes(); processJCas(); processJCasWithSieve(4); List<ReferenceTarget> targets = new ArrayList<>(JCasUtil.select(jCas, ReferenceTarget.class)); assertEquals(1, targets.size()); List<Organisation> orgs = new ArrayList<Organisation>(JCasUtil.select(jCas, Organisation.class)); assertEquals(2, orgs.size()); assertNotNull(orgs.get(0).getReferent()); assertEquals( orgs.get(0).getReferent().getInternalId(), orgs.get(1).getReferent().getInternalId()); }
@Test public void testEnhanceOrganisation() { Organisation o = new Organisation(jCas); o.setValue("British Government"); Mention m = new Mention(o); genderEnhancer.enhance(m); assertEquals(Gender.N, m.getGender()); }
@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 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 testNested() throws Exception { jCas.setDocumentText("A statement US Army Major J Bloggs said that"); Organisation o = new Organisation(jCas, 12, 34); o.addToIndexes(); Person p = new Person(jCas, 20, 34); p.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Relation.class).size()); Relation r = JCasUtil.selectByIndex(jCas, Relation.class, 0); assertEquals("US Army Major J Bloggs", r.getCoveredText()); assertEquals("ROLE", r.getRelationshipType()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); Organisation org = JCasUtil.selectByIndex(jCas, Organisation.class, 0); assertEquals("US Army", org.getCoveredText()); }
@Test public void testAdjacent() throws Exception { jCas.setDocumentText("A statement US Army Major J Bloggs said that"); Organisation o = new Organisation(jCas, 12, 19); o.addToIndexes(); Person p = new Person(jCas, 20, 34); p.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Relation.class).size()); Relation r = JCasUtil.selectByIndex(jCas, Relation.class, 0); assertEquals("US Army Major J Bloggs", r.getCoveredText()); assertEquals("ROLE", r.getRelationshipType()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); Organisation org = JCasUtil.selectByIndex(jCas, Organisation.class, 0); assertEquals("US Army", org.getCoveredText()); }
@Test public void testBetween() throws Exception { jCas.setDocumentText("A statement UN Spokesperson J Bloggs said that"); Organisation o = new Organisation(jCas, 12, 14); o.addToIndexes(); Person p = new Person(jCas, 28, 36); p.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Relation.class).size()); Relation r = JCasUtil.selectByIndex(jCas, Relation.class, 0); assertEquals("UN Spokesperson J Bloggs", 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()); }
@Test public void testAdjacentApostrophe() throws Exception { jCas.setDocumentText("A statement US Army's Major J Bloggs said that"); Organisation o = new Organisation(jCas, 12, 19); o.addToIndexes(); Person p = new Person(jCas, 22, 36); p.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Relation.class).size()); Relation r = JCasUtil.selectByIndex(jCas, Relation.class, 0); assertEquals("US Army's Major J Bloggs", r.getCoveredText()); assertEquals("ROLE", r.getRelationshipType()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); Organisation org = JCasUtil.selectByIndex(jCas, Organisation.class, 0); assertEquals("US Army", org.getCoveredText()); }
e2.addToIndexes(); Organisation o = new Organisation(jCas, 153, 179); // Abusing the entity type just so we can
p.addToIndexes(); Organisation o = new Organisation(jCas); o.setValue("Dstl"); o.setBegin(15);