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());
@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()); }
l.setEnd(l.getBegin() + "London".length()); l.setValue("London"); l.addToIndexes();
l.setEnd(l.getBegin() + "London".length()); l.setValue("London"); l.addToIndexes();
l.setEnd(l.getBegin() + "London".length()); l.setValue("London"); l.addToIndexes();
l.setEnd(l.getBegin() + "London".length()); l.setValue("London"); l.addToIndexes();
@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()); }
assertEquals(WORLD, l.getValue()); assertEquals(WORLD, l.getCoveredText()); assertTrue(l.getBegin() > 10);
l.setEnd(l.getBegin() + "London".length()); l.setValue("London"); l.addToIndexes();
public void assertLocationMatches() { final Location inLocation = JCasUtil.selectSingle(in, Location.class); final Location outLocation = JCasUtil.selectSingle(out, Location.class); assertEquals(inLocation.getGeoJson(), outLocation.getGeoJson()); assertEquals(inLocation.getBegin(), outLocation.getBegin()); assertEquals(inLocation.getEnd(), outLocation.getEnd()); assertEquals(inLocation.getValue(), outLocation.getValue()); assertEquals(0, inLocation.getConfidence(), outLocation.getConfidence()); }
@Test public void test() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "John say that he would visit London"; jCas.setDocumentText(text); ReferenceTarget rt = new ReferenceTarget(jCas); rt.addToIndexes(); Person p = new Person(jCas); p.setBegin(0); p.setEnd(4); p.setReferent(rt); p.setValue("John"); p.addToIndexes(); WordToken he = new WordToken(jCas); he.setBegin(text.indexOf("he")); he.setEnd(he.getBegin() + "he".length()); he.setReferent(rt); he.addToIndexes(); Location l = new Location(jCas); l.setBegin(text.indexOf("London")); l.setEnd(l.getBegin() + "London".length()); l.setValue("London"); l.addToIndexes(); processJCas(); List<Entity> list = new ArrayList<>(JCasUtil.select(jCas, Entity.class)); assertEquals(3, list.size()); assertEquals("John", list.get(0).getValue()); assertEquals("John", list.get(1).getValue()); assertTrue(list.get(1) instanceof Person); assertEquals("London", list.get(2).getValue()); }
@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 testAlreadyExists() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "John say that he would visit London"; jCas.setDocumentText(text); ReferenceTarget rt = new ReferenceTarget(jCas); rt.addToIndexes(); Person p = new Person(jCas); p.setBegin(0); p.setEnd(4); p.setReferent(rt); p.setValue("John"); p.addToIndexes(); Person pHe = new Person(jCas); pHe.setBegin(14); pHe.setEnd(16); pHe.setReferent(rt); pHe.setValue("he"); pHe.addToIndexes(); Location l = new Location(jCas); l.setBegin(text.indexOf("London")); l.setEnd(l.getBegin() + "London".length()); l.setValue("London"); l.addToIndexes(); processJCas(); List<Entity> list = new ArrayList<>(JCasUtil.select(jCas, Entity.class)); assertEquals(3, list.size()); // Check no additional entities have been created }
toId("ent1"), "ent1", e4.getBegin(), e4.getEnd(), e4.getType().getShortName(),