public static Person createPerson(JCas jCas, int begin, int end, String value) { Person p = new Person(jCas); p.setValue(value); p.setBegin(begin); p.setEnd(end); p.addToIndexes(); return p; }
@Test public void test() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("John went to London. I saw John there."); Person p = new Person(jCas); p.setBegin(0); p.setEnd(4); p.setValue("John"); p.addToIndexes(); processJCas(); List<Entity> select = new ArrayList<>(JCasUtil.select(jCas, Person.class)); assertEquals(2, select.size()); assertEquals("John", select.get(0).getValue()); assertEquals("John", select.get(1).getValue()); }
@Test public void testEntities() throws UIMAException { final Person s = new Person(jCas); s.setValue("source"); s.addToIndexes(); SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngine(Entities.class)); }
@Test public void testMultiple() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("John went to London. I saw John there. He's a great guy John."); Person p1 = new Person(jCas); p1.setBegin(0); p1.setEnd(4); p1.setValue("John"); p1.addToIndexes(); Person p2 = new Person(jCas); p2.setBegin(27); p2.setEnd(31); p2.setValue("John"); p2.addToIndexes(); processJCas(); List<Entity> select = new ArrayList<>(JCasUtil.select(jCas, Person.class)); assertEquals(3, select.size()); assertEquals("John", select.get(0).getValue()); assertEquals("John", select.get(1).getValue()); assertEquals("John", select.get(2).getValue()); }
p.setBegin(text.indexOf("John")); p.setEnd(p.getBegin() + "John".length()); p.setValue("John"); p.addToIndexes();
@Test public void testAddAnnotationArray() { UimaSupport support = new UimaSupport(PIPELINE, UimaSupportTest.class, history, monitor, false); Person withValue = new Person(jCas); withValue.setBegin(0); withValue.setEnd(4); withValue.setValue("David"); Person withoutValue = new Person(jCas); withoutValue.setBegin(0); withoutValue.setEnd(4); support.add(new ProtectiveMarking(jCas), withValue, withoutValue); assertEquals(1, JCasUtil.select(jCas, ProtectiveMarking.class).size()); List<Person> persons = new ArrayList<Person>(JCasUtil.select(jCas, Person.class)); assertEquals(2, persons.size()); // Check value is set / not overridden assertNotEquals(persons.get(0).getCoveredText(), persons.get(0).getValue()); assertEquals(persons.get(1).getCoveredText(), persons.get(1).getValue()); // Check Id set assertNotEquals(persons.get(0).getInternalId(), persons.get(1).getInternalId()); // Check had history of addition assertFalse( support.getDocumentHistory(jCas).getHistory(persons.get(1).getInternalId()).isEmpty()); }
@Test public void testEntityExternalId() throws UIMAException, BaleenException { JCas jCas = JCasSingleton.getJCasInstance(); jCas.setDocumentText("Hello World"); Person p1 = new Person(jCas); p1.setGender("female"); p1.setValue("Jane Doe"); p1.addToIndexes(jCas); Person p2 = new Person(jCas); p2.setGender("female"); p2.setValue("J. Doe"); p2.addToIndexes(jCas); assertEquals( ConsumerUtils.getExternalId(ImmutableSet.of(p1, p2)), ConsumerUtils.getExternalId(ImmutableSet.of(p1, p2))); assertEquals( "d3c514ea1fb3367430959255917ee4de12468004897d683d60114b475d37264a", ConsumerUtils.getExternalId(ImmutableSet.of(p1, p2))); assertNotEquals( ConsumerUtils.getExternalId(ImmutableSet.of(p1)), ConsumerUtils.getExternalId(ImmutableSet.of(p1, p2))); } }
p.setBegin(text.indexOf("John")); p.setEnd(p.getBegin() + "John".length()); p.setValue("John"); p.addToIndexes();
@Test public void testWithText() throws AnalysisEngineProcessException, ResourceInitializationException { jCas.setDocumentText("John went to London. I saw John there. He's a great guy John."); new Text(jCas, 0, 21).addToIndexes(); // Omit the middle John new Text(jCas, 40, jCas.getDocumentText().length()).addToIndexes(); Person p = new Person(jCas); p.setBegin(0); p.setEnd(4); p.setValue("John"); p.addToIndexes(); processJCas(); List<Entity> select = new ArrayList<>(JCasUtil.select(jCas, Person.class)); assertEquals(2, select.size()); assertEquals("John", select.get(0).getValue()); assertEquals("John", select.get(1).getValue()); assertTrue(select.get(1).getBegin() > 40); }
p1.setBegin(0); p1.setEnd(4); p1.setValue("John"); p1.addToIndexes();
@Test public void testEnhancePerson() { Person p = new Person(jCas); p.setValue("Sir Lancelot"); p.setTitle("Sir"); Mention m = new Mention(p); genderEnhancer.enhance(m); assertEquals(Gender.M, m.getGender()); }
@Test public void testNoValue() throws Exception { AnalysisEngine nwAE = AnalysisEngineFactory.createEngine(NormalizeWhitespace.class); jCas.setDocumentText("Peter Smith lives in Salisbury"); Annotations.createPerson(jCas, 0, 11, "Peter Smith"); JCasUtil.selectByIndex(jCas, Person.class, 0).setValue(null); nwAE.process(jCas); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals(null, JCasUtil.selectByIndex(jCas, Person.class, 0).getValue()); assertEquals(false, JCasUtil.selectByIndex(jCas, Person.class, 0).getIsNormalised()); } }
@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 }
@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()); }
p.setValue("James"); p.setBegin(0); p.setEnd(5);
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 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)); }
@Before public void setup() throws IOException { jCas.setDocumentText(TEXT); tempDirectory = Files.createTempDirectory(AllAnnotationsJsonConsumerTest.class.getSimpleName()); tempDirectory.toFile().deleteOnExit(); DocumentAnnotation documentAnnotation = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); documentAnnotation.setSourceUri(SOURCEURI); Paragraph paragraph1 = new Paragraph(jCas); paragraph1.setBegin(0); paragraph1.setDepth(1); paragraph1.setEnd(52); paragraph1.addToIndexes(); Person entity1 = new Person(jCas); entity1.setBegin(70); entity1.setEnd(73); entity1.setValue("cat"); entity1.addToIndexes(); Event event = new Event(jCas); event.setBegin(53); event.setEnd(105); event.setArguments(new StringArray(jCas, 2)); event.setArguments(0, "cat"); event.setArguments(1, "dog"); event.setEntities(new FSArray(jCas, 1)); event.setEntities(0, entity1); event.addToIndexes(); }
@Test public void test() throws Exception { jCas.setDocumentText("Pierre is French"); Person p = new Person(jCas); p.setBegin(0); p.setEnd(6); p.setValue("Pierre"); p.addToIndexes(); Nationality n = new Nationality(jCas); n.setBegin(10); n.setEnd(16); n.setValue("French"); n.setCountryCode("fra"); n.addToIndexes(); ae.process(jCas); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("French", l.getValue()); assertNotNull(l.getGeoJson()); } }
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); }