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; }
String id = coord.getExternalId(); String geoJson = coord.getGeoJson(); String coordinate = null; json.put(FIELD_DOC_ID, docId); json.put(FIELD_EXTERNAL_ID, id); json.put(FIELD_BEGIN, coord.getBegin()); json.put(FIELD_END, coord.getEnd()); json.put(FIELD_VALUE, coord.getValue()); json.put(FIELD_CONFIDENCE, coord.getConfidence()); if (geoJson != null) { try {
/** * @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 Location(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
@Test public void testExactStringMatch() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "Chris went to London and in London he saw Big Ben."; // london - london jCas.setDocumentText(text); Person chris = new Person(jCas); chris.setBegin(text.indexOf("Chris")); chris.setEnd(chris.getBegin() + "Chris".length()); chris.addToIndexes(); Location london = new Location(jCas); london.setBegin(text.indexOf("London")); london.setEnd(london.getBegin() + "London".length()); london.addToIndexes(); Location london2 = new Location(jCas); london2.setBegin(text.indexOf("London", london.getEnd())); london2.setEnd(london2.getBegin() + "London".length()); london2.addToIndexes(); processJCas(); processJCasWithSieve(1); List<ReferenceTarget> targets = new ArrayList<>(JCasUtil.select(jCas, ReferenceTarget.class)); List<Location> location = new ArrayList<>(JCasUtil.select(jCas, Location.class)); assertEquals(1, targets.size()); assertSame(targets.get(0), location.get(0).getReferent()); assertSame(targets.get(0), location.get(1).getReferent()); }
@Test public void testExtractReferenceTargets() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "Chris went to London and he saw Big Ben there."; // there - london jCas.setDocumentText(text); Person chris = new Person(jCas); chris.setBegin(text.indexOf("Chris")); chris.setEnd(chris.getBegin() + "Chris".length()); chris.addToIndexes(); ReferenceTarget target = new ReferenceTarget(jCas); target.addToIndexes(); Location london = new Location(jCas); london.setBegin(text.indexOf("London")); london.setEnd(london.getBegin() + "London".length()); london.setReferent(target); london.addToIndexes(); Location there = new Location(jCas); there.setBegin(text.indexOf("there")); there.setEnd(there.getBegin() + "there".length()); there.setReferent(target); there.addToIndexes(); processJCas(); processJCasWithSieve(0); // We should have a reference target and it should be different to the previous, as its been // recreated. Collection<ReferenceTarget> targets = JCasUtil.select(jCas, ReferenceTarget.class); assertEquals(1, targets.size()); assertTrue(targets.iterator().next().getInternalId() != target.getInternalId()); }
p.addToIndexes(); Location l = new Location(jCas); l.setBegin(14); l.setEnd(20); l.setValue(LONDON); l.addToIndexes(); assertEquals(p.getType().getName(), relation.get(FIELD_SOURCE_TYPE_FULL)); assertEquals(p.getExternalId(), relation.get(FIELD_SOURCE)); assertEquals(l.getValue(), relation.get(FIELD_TARGET_VALUE)); assertEquals(l.getType().getShortName(), relation.get(FIELD_TARGET_TYPE)); assertEquals(l.getType().getName(), relation.get(FIELD_TARGET_TYPE_FULL)); assertEquals(l.getExternalId(), relation.get(FIELD_TARGET)); assertEquals(r.getRelationshipType(), relation.get(FIELD_RELATIONSHIP_TYPE)); assertEquals(r.getRelationSubType(), relation.get(FIELD_RELATIONSHIP_SUBTYPE));
@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()); }
docId, BALEEN_DOC_ID, toId(e4.getExternalId()), e4.getExternalId(), toId("ent1"), "ent1", e4.getBegin(), e4.getEnd(), e4.getType().getShortName(), e4.getValue()); final BaleenMention m5 = new BaleenMention( m4.getProperties().put("geoJson", e4.getGeoJson()); m4.getProperties().put(AnalysisConstants.POI, Arrays.asList(new LatLon(3, -1))); m5.getProperties().put("precision", e5.getPrecision()); docId, BALEEN_DOC_ID, toId(e4.getExternalId()), e4.getExternalId(), e4.getTypeName(), e4.getValue()); final BaleenEntity be4 = new BaleenEntity(
@Test public void test() throws Exception { jCas.setDocumentText("Hello world, this is a test"); processJCas(MONGO, erd, COLLECTION, MONGO_COLL, TYPE, LOCATION); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals(WORLD, l.getValue()); assertEquals(WORLD, l.getCoveredText()); }
@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()); }
jCas.setDocumentText(cca3); Location l = new Location(jCas, 0, cca3.length()); l.setValue(cca3); l.setGeoJson(scr.getGeoJson(cca3)); l.addToIndexes();
@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()); }
@Test public void testProperty() throws Exception { jCas.setDocumentText("Guy Fawkes was caught in London"); processJCas(MONGO, erd, COLLECTION, MONGO_COLL, TYPE, LOCATION); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location lLon = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("London", lLon.getValue()); assertEquals("London", lLon.getCoveredText()); assertEquals(LONDON_GEOJSON.toJson(), lLon.getGeoJson()); }
@Override public Collection<Candidate> getCandidates(EntityInformation<Location> entityInformation) { Collection<Location> locations = entityInformation.getMentions(); Collection<Candidate> candidates = new HashSet<>(); for (Location location : locations) { try { candidates.addAll(queryByNameContains(location.getValue())); } catch (ParseException e) { LOGGER.error(e.getMessage()); } } return candidates; }
graph .traversal() .V(location.getExternalId()) .hasLabel(MENTION) .has("value", location.getValue()) .has(FIELD_DOCUMENT_ID, documentId) .has("geoJson", location.getGeoJson()) .hasNext());
@Override public void validate(Location t) { super.validate(t); assertEquals(value, t.getValue()); assertEquals(geometry, t.getGeoJson()); } }
@Test public void testLocationBothRT() throws Exception { jCas.setDocumentText( "The former school house at GR 1234 5678. The school house has a blue door."); ReferenceTarget rt1 = new ReferenceTarget(jCas); rt1.addToIndexes(); ReferenceTarget rt2 = new ReferenceTarget(jCas); rt2.addToIndexes(); Location l1 = new Location(jCas, 4, 23); l1.setReferent(rt1); l1.addToIndexes(); Coordinate c = new Coordinate(jCas, 27, 39); c.setReferent(rt2); c.addToIndexes(); Location l2 = new Location(jCas, 45, 57); l2.setReferent(rt1); l2.addToIndexes(); processJCas(); assertEquals(3, JCasUtil.select(jCas, Location.class).size()); assertEquals(rt2, c.getReferent()); assertEquals(rt2, l1.getReferent()); assertEquals(rt2, l2.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 testmultipleHitsWithText() throws Exception { AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( List.class, List.PARAM_TERMS, terms, List.PARAM_TYPE, LOCATION); AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed); // the same search term appears multiple times in text... jCas.setDocumentText("Hello world, and hello world again."); // but then subset using a Text annotation new Text(jCas, 10, jCas.getDocumentText().length()).addToIndexes(); ae.process(jCas); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals(WORLD, l.getValue()); assertEquals(WORLD, l.getCoveredText()); assertTrue(l.getBegin() > 10); ae.destroy(); } }
@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)); }