/** * @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(); }
/** * @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(); }
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 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()); }
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 testMergeWithNewAnnotationAnnotationArray() { UimaSupport support = new UimaSupport(PIPELINE, UimaSupportTest.class, history, monitor, false); Location l = new Location(jCas); l.setBegin(0); l.setEnd(0); Metadata md2 = new Metadata(jCas); md2.setBegin(0); md2.setEnd(0); support.mergeWithNew(l, location); support.mergeWithNew(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 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()); }
l.setBegin(text.indexOf("London")); l.setEnd(l.getBegin() + "London".length()); l.setValue("London");
@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()); }
private void createDocument(JCas jCas) { jCas.reset(); jCas.setDocumentText("Simon was born in November 1980 in London, UK"); Person p = new Person(jCas); p.setValue("Simon"); p.setBegin(0); p.setEnd(5); p.addToIndexes(); Temporal d = new Temporal(jCas); d.setValue(NOVEMBER); d.setBegin(18); d.setEnd(26); d.addToIndexes(); Location l = new Location(jCas); l.setValue(LONDON); l.setBegin(35); l.setEnd(41); l.addToIndexes(); // entity value different to covering text "UK" Location l2 = new Location(jCas); l2.setValue(UNITED_KINGDOM); l2.setBegin(43); l2.setEnd(45); l2.addToIndexes(); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals(1, JCasUtil.select(jCas, Temporal.class).size()); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); }
@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()); }
london.setBegin(jCas.getDocumentText().indexOf("London")); london.setEnd(london.getBegin() + "london".length()); london.setReferent(londonRT); there.setBegin(jCas.getDocumentText().indexOf("there")); there.setEnd(there.getBegin() + "there".length()); there.setReferent(londonRT); bigBen.setBegin(jCas.getDocumentText().indexOf("Big Ben")); bigBen.setEnd(london.getBegin() + "Big Ben".length()); bigBen.addToIndexes();
l.setBegin(15); l.setEnd(19); l.setConfidence(0.66);
london.setBegin(25); london.setEnd(31); london.addToIndexes();
@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 }
@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()); }
public JCasSerializationTester() throws UIMAException { out = JCasFactory.createJCas(); in = JCasFactory.createJCas(); in.setDocumentText("This is a test"); final DocumentAnnotation inDA = (DocumentAnnotation) in.getDocumentAnnotationFs(); inDA.setDocumentClassification("CLASS"); final Location l = new Location(in); l.setBegin(10); l.setEnd(12); l.setGeoJson(GEO_JSON); l.setValue("Dinagat Islands"); l.setConfidence(0.9d); l.addToIndexes(in); final ReferenceTarget rt = new ReferenceTarget(in); rt.setBegin(0); rt.setEnd(1); rt.addToIndexes(in); final Person p = new Person(in); p.setBegin(2); p.setEnd(8); p.setGender("Male"); p.setValue("Peter"); p.setConfidence(0.5d); p.setReferent(rt); p.addToIndexes(in); }