@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()); }
@Override public Collection<Candidate> getCandidates(EntityInformation<Organisation> entityInformation) { Collection<Organisation> organisations = entityInformation.getMentions(); Collection<Candidate> candidates = new HashSet<>(); for (Organisation organisation : organisations) { try { candidates.addAll(queryByNameContains(organisation.getValue())); } catch (ParseException e) { LOGGER.error(e.getMessage()); } } return candidates; }
/** * @generated * @param jcas JCas to which this Feature Structure belongs * @param begin offset to the begin spot in the SofA * @param end offset to the end spot in the SofA */ public Organisation(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
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 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()); }
e2.addToIndexes(); Organisation o = new Organisation(jCas, 153, 179); // Abusing the entity type just so we can o.addToIndexes();
@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()); }
return Optional.of(new Nationality(jCas)); case "Organisation": return Optional.of(new Organisation(jCas)); case "Person": return Optional.of(new Person(jCas));
@Test public void testPlural() throws Exception { jCas.setDocumentText( "They were last seen running towards the school, making a nuisance of themselves."); addWordTokens(jCas); processJCas(); assertEquals(2, JCasUtil.select(jCas, Organisation.class).size()); assertEquals("They", JCasUtil.selectByIndex(jCas, Organisation.class, 0).getCoveredText()); assertEquals( "themselves", JCasUtil.selectByIndex(jCas, Organisation.class, 1).getCoveredText()); assertEquals(0, JCasUtil.select(jCas, Person.class).size()); }
@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()); }
p.addToIndexes(); Organisation o = new Organisation(jCas); o.setValue("Dstl"); o.setBegin(15); o.setEnd(19); o.setConfidence(0.96); o.addToIndexes();
/** * @generated * @param jcas JCas to which this Feature Structure belongs * @param begin offset to the begin spot in the SofA * @param end offset to the end spot in the SofA */ public Organisation(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
return Optional.of(new Nationality(jCas)); case "Organisation": return Optional.of(new Organisation(jCas)); case "Person": return Optional.of(new Person(jCas));
@Test public void testNationalityPeople() throws Exception { jCas.setDocumentText("The Scottish people voted in an independence referendum"); Nationality n = new Nationality(jCas, 4, 12); n.addToIndexes(); processJCas(); assertEquals(0, JCasUtil.select(jCas, Nationality.class).size()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); assertEquals( "Scottish people", JCasUtil.selectByIndex(jCas, Organisation.class, 0).getCoveredText()); }
@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 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()); }
@Test public void testQuantityPeople() throws Exception { jCas.setDocumentText("47,000 people voted in an independence referendum"); Quantity n = new Quantity(jCas, 0, 6); n.addToIndexes(); processJCas(); assertEquals(0, JCasUtil.select(jCas, Quantity.class).size()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); assertEquals( "47,000 people", JCasUtil.selectByIndex(jCas, Organisation.class, 0).getCoveredText()); }
@Override public Collection<Candidate> getCandidates(EntityInformation<Organisation> entityInformation) { Collection<Organisation> organisations = entityInformation.getMentions(); Collection<Candidate> candidates = new HashSet<>(); for (Organisation organisation : organisations) { try { candidates.addAll(queryByNameContains(organisation.getValue())); } catch (ParseException e) { LOGGER.error(e.getMessage()); } } return candidates; }
@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 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()); }