private void populateJCasMergeTest(JCas jCas) { jCas.setDocumentText(LOC_TEXT); ReferenceTarget rt1 = Annotations.createReferenceTarget(jCas); ReferenceTarget rt2 = Annotations.createReferenceTarget(jCas); Location l1 = Annotations.createLocation(jCas, 0, 9, SOMEWHERE, null); l1.setReferent(rt1); Coordinate c1 = Annotations.createCoordinate(jCas, 11, 19, MRGS); c1.setReferent(rt2); }
@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()); }
@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()); }
locationRT1.setBegin(0); locationRT1.setEnd(0); locationRT1.setReferent(rt1); locationRT1.addToIndexes(); locationRT2.setBegin(0); locationRT2.setEnd(0); locationRT2.setReferent(rt2); locationRT2.addToIndexes(); locationRT2Again.setBegin(1); locationRT2Again.setEnd(1); locationRT2Again.setReferent(rt2); locationRT2Again.addToIndexes();
locationRT1.setBegin(0); locationRT1.setEnd(0); locationRT1.setReferent(rt1); locationRT1.addToIndexes(); locationRT2.setBegin(0); locationRT2.setEnd(0); locationRT2.setReferent(rt2); locationRT2.addToIndexes(); locationRT2Again.setBegin(1); locationRT2Again.setEnd(1); locationRT2Again.setReferent(rt2); locationRT2Again.addToIndexes();
london.setBegin(jCas.getDocumentText().indexOf("London")); london.setEnd(london.getBegin() + "london".length()); london.setReferent(londonRT); london.addToIndexes(); there.setBegin(jCas.getDocumentText().indexOf("there")); there.setEnd(there.getBegin() + "there".length()); there.setReferent(londonRT); there.addToIndexes();
@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 testExistingLocReferent() throws Exception { AnalysisEngine ae = AnalysisEngineFactory.createEngine(CorefBrackets.class); jCas.setDocumentText(LOC_TEXT); ReferenceTarget rt1 = Annotations.createReferenceTarget(jCas); Location l1 = Annotations.createLocation(jCas, 0, 9, SOMEWHERE, null); l1.setReferent(rt1); Annotations.createCoordinate(jCas, 11, 19, MRGS); ae.process(jCas); assertEquals(1, JCasUtil.select(jCas, ReferenceTarget.class).size()); ReferenceTarget rt = JCasUtil.selectByIndex(jCas, ReferenceTarget.class, 0); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); Coordinate c = JCasUtil.selectByIndex(jCas, Coordinate.class, 0); assertEquals(rt, l.getReferent()); assertEquals(rt, c.getReferent()); assertEquals(l.getReferent(), c.getReferent()); }
l.setEnd(20); l.setValue(LONDON); l.setReferent(new ReferenceTarget(jCas)); l.addToIndexes();
l.setEnd(20); l.setValue(LONDON); l.setReferent(new ReferenceTarget(jCas)); l.addToIndexes();
l.setEnd(20); l.setValue(LONDON); l.setReferent(new ReferenceTarget(jCas)); l.addToIndexes();