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 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 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 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 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 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 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 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 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 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 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 testRelations() throws UIMAException { final Person s = new Person(jCas); s.setValue("source"); final Location t = new Location(jCas); t.setValue("target"); final Relation r = new Relation(jCas); r.setSource(s); r.setTarget(t); r.setRelationshipType("check"); r.addToIndexes(); SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngine(Relations.class)); }
@Test public void testEvents() throws UIMAException { final Location t = new Location(jCas); t.setValue("target"); final Event e = new Event(jCas); e.setArguments(new StringArray(jCas, 1)); e.setArguments(0, "test"); e.setEntities(new FSArray(jCas, 1)); e.setEntities(0, t); e.addToIndexes(); SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngine(Events.class)); }