private void createAndAddLocationEntity(String entityValue, String subType) { jCas.setDocumentText(PREFIX + entityValue); Location coord = new Location(jCas); coord.setSubType(subType); coord.setValue(entityValue); coord.setBegin(PREFIX.length()); coord.setEnd(PREFIX.length() + entityValue.length()); coord.addToIndexes(); } }
@Test public void testOf() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("The city of Salisbury is busy on a Saturday."); Location theCity = new Location(jCas, 0, 8); Location salisbury = new Location(jCas, 12, 21); theCity.addToIndexes(); salisbury.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("The city of Salisbury", l.getCoveredText()); } }
@Test public void testBorder1() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("The England-Wales border is a lovely area."); Location england = new Location(jCas, 4, 11); Location wales = new Location(jCas, 12, 17); england.addToIndexes(); wales.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("England-Wales border", l.getCoveredText()); }
@Test public void testBorder2() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("The England-Wales border is a lovely area."); Location england = new Location(jCas, 4, 11); Location wales = new Location(jCas, 12, 24); england.addToIndexes(); wales.addToIndexes(); processJCas(); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("England-Wales border", l.getCoveredText()); }
@Test public void testPeopleOfLocation() throws Exception { jCas.setDocumentText("The people of Scotland voted in an independence referendum"); Location l = new Location(jCas, 14, 22); l.addToIndexes(); processJCas(); assertEquals(0, JCasUtil.select(jCas, Location.class).size()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); assertEquals( "people of Scotland", JCasUtil.selectByIndex(jCas, Organisation.class, 0).getCoveredText()); }
@Test public void testNoQuantity() throws UIMAException { jCas.setDocumentText("The weapons were found 20 miles N of London"); Location l = new Location(jCas, 37, 43); l.addToIndexes(); processJCas(); assertEquals("N of London", l.getCoveredText()); assertEquals(0, JCasUtil.select(jCas, Quantity.class).size()); }
@Test public void testArea() throws UIMAException { jCas.setDocumentText("The weapons were found in the vicinity of Tower Bridge"); Location l = new Location(jCas, 42, 54); l.addToIndexes(); processJCas(); assertEquals("the vicinity of Tower Bridge", l.getCoveredText()); assertEquals(0, JCasUtil.select(jCas, Quantity.class).size()); } }
@Test public void test2() throws UIMAException { jCas.setDocumentText("It happened in northern Syria."); Location l = new Location(jCas, 24, 29); l.addToIndexes(); processJCas(); assertEquals("northern Syria", l.getCoveredText()); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); }
@Test public void testPeopleOfLocationKeepOriginal() throws Exception { jCas.setDocumentText("The people of Scotland voted in an independence referendum"); Location l = new Location(jCas, 14, 22); l.addToIndexes(); processJCas(People.PARAM_REMOVE_ORIGINAL, false); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); assertEquals("Scotland", JCasUtil.selectByIndex(jCas, Location.class, 0).getCoveredText()); assertEquals(1, JCasUtil.select(jCas, Organisation.class).size()); assertEquals( "people of Scotland", JCasUtil.selectByIndex(jCas, Organisation.class, 0).getCoveredText()); }
public static Location createLocation( JCas jCas, int begin, int end, String value, String geojson) { Location l = new Location(jCas); l.setValue(value); l.setBegin(begin); l.setEnd(end); if (geojson != null) { l.setGeoJson(geojson); } l.addToIndexes(); return l; }
@Test public void testMergeWithExistingAnnotationAnnotationArray() { UimaSupport support = new UimaSupport(PIPELINE, UimaSupportTest.class, history, monitor, false); Location l = new Location(jCas); l.setBegin(0); l.setEnd(0); l.addToIndexes(); Metadata md2 = new Metadata(jCas); md2.setBegin(0); md2.setEnd(0); md2.addToIndexes(); support.mergeWithExisting(l, location); support.mergeWithExisting(md2, md); List<Location> locations = new ArrayList<>(JCasUtil.select(jCas, Location.class)); List<Metadata> mds = new ArrayList<>(JCasUtil.select(jCas, Metadata.class)); assertEquals(1, locations.size()); assertEquals(l, locations.get(0)); assertEquals(1, mds.size()); assertEquals(md2, mds.get(0)); assertFalse(support.getDocumentHistory(jCas).getHistory(l.getInternalId()).isEmpty()); }
@Test public void testLocationIsAtNoRT() throws Exception { jCas.setDocumentText("The former school house is at GR 1234 5678."); Location l = new Location(jCas, 4, 23); l.addToIndexes(); Coordinate c = new Coordinate(jCas, 30, 42); c.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); assertNotNull(l.getReferent()); assertEquals(l.getReferent(), c.getReferent()); }
@Test public void testLocationNoRT() throws Exception { jCas.setDocumentText("The former school house at GR 1234 5678."); Location l = new Location(jCas, 4, 23); l.addToIndexes(); Coordinate c = new Coordinate(jCas, 27, 39); c.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); assertNotNull(l.getReferent()); assertEquals(l.getReferent(), c.getReferent()); }
@Test public void testLocationRT1() throws Exception { jCas.setDocumentText("The former school house at GR 1234 5678."); ReferenceTarget rt = new ReferenceTarget(jCas); rt.addToIndexes(); Location l = new Location(jCas, 4, 23); l.setReferent(rt); l.addToIndexes(); Coordinate c = new Coordinate(jCas, 27, 39); c.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); assertEquals(rt, c.getReferent()); }
@Test public void testLocationRT2() throws Exception { jCas.setDocumentText("The former school house at GR 1234 5678."); ReferenceTarget rt = new ReferenceTarget(jCas); rt.addToIndexes(); Location l = new Location(jCas, 4, 23); l.addToIndexes(); Coordinate c = new Coordinate(jCas, 27, 39); c.setReferent(rt); c.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); assertEquals(rt, l.getReferent()); }
@Test public void testRemoveQuantity() throws UIMAException { jCas.setDocumentText("The weapons were found 20 miles north of London"); Quantity q = new Quantity(jCas); q.setBegin(23); q.setEnd(31); q.setSubType("distance"); q.addToIndexes(); Location l = new Location(jCas, 41, 47); l.addToIndexes(); processJCas(ExpandLocationToDescription.PARAM_REMOVE_QUANTITY, true); assertEquals("20 miles north of London", l.getCoveredText()); assertEquals(0, JCasUtil.select(jCas, Quantity.class).size()); }
@Test public void test() throws UIMAException { jCas.setDocumentText("The weapons were found 50 miles south-west of London"); Quantity q = new Quantity(jCas); q.setBegin(23); q.setEnd(31); q.setSubType("distance"); q.addToIndexes(); Location l = new Location(jCas, 46, 52); l.addToIndexes(); processJCas(); assertEquals("50 miles south-west of London", l.getCoveredText()); assertEquals(1, JCasUtil.select(jCas, Quantity.class).size()); }
@Test public void testBoth() throws Exception { jCas.setDocumentText("The former school house at GR 1234 5678."); languageAE.process(jCas); Location l = new Location(jCas, 4, 23); l.addToIndexes(); Coordinate c = new Coordinate(jCas, 27, 39); c.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); assertNotNull(l.getReferent()); assertEquals(l.getReferent(), c.getReferent()); } }
@Before public void setUp() throws UIMAException { jCas = JCasSingleton.getJCasInstance(); jCas.setDocumentText("Dave saw is some of London"); location = new Location(jCas); location.setBegin(20); location.setEnd(26); location.setValue("London"); location.addToIndexes(); md = new Metadata(jCas); md.setKey("k"); md.setValue("v"); md.addToIndexes(); history = new InMemoryBaleenHistory(); history.initialize(new CustomResourceSpecifier_impl(), Maps.newHashMap()); }
@Test public void test2() throws Exception { jCas.setDocumentText( "John Smith (UID123) (JS) was last seen in London (LDN) (NFDK). JSmith has previously visited MAN."); Person p = new Person(jCas, 0, 10); p.addToIndexes(); Location l = new Location(jCas, 42, 48); l.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Person.class).size()); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); Person p0 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("John Smith", p0.getCoveredText()); ReferenceTarget rtP = p0.getReferent(); assertNotNull(rtP); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertEquals("JS", p1.getCoveredText()); assertEquals(rtP, p1.getReferent()); Location l0 = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("London", l0.getCoveredText()); ReferenceTarget rtL = l0.getReferent(); assertNotNull(rtL); Location l1 = JCasUtil.selectByIndex(jCas, Location.class, 1); assertEquals("LDN", l1.getCoveredText()); assertEquals(rtL, l1.getReferent()); }