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 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 testSinglePersonWithReferences() throws Exception { jCas.setDocumentText("Mr Simon Brown, was caught stealing sausages. Brown was found guilty."); Person p = new Person(jCas, 0, 14); p.setReferent(new ReferenceTarget(jCas)); p.addToIndexes(); processJCas(); assertEquals(2, JCasUtil.select(jCas, Person.class).size()); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertEquals("Mr Simon Brown", p1.getCoveredText()); Person p2 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertEquals("Brown", p2.getCoveredText()); assertNotNull(p1.getReferent()); assertEquals(p1.getReferent(), p2.getReferent()); }
/** * @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 Person(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
@Test public void testEntities() throws UIMAException { final Person s = new Person(jCas); s.setValue("source"); s.addToIndexes(); SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngine(Entities.class)); }
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); }
jCas.setDocumentText(text); Person chrisSmith = new Person(jCas); chrisSmith.setBegin(text.indexOf("Chris Smith")); chrisSmith.setEnd(chrisSmith.getBegin() + "Chris Smith".length()); chrisSmith.setValue("Chris Smith"); chrisSmith.addToIndexes(); Person chris = new Person(jCas); chris.setBegin(text.indexOf("Chris", chrisSmith.getEnd())); chris.setEnd(chris.getBegin() + "Chris".length()); chris.setValue("Chris"); chris.addToIndexes(); List<WordToken> words = new ArrayList<>(JCasUtil.select(jCas, WordToken.class)); long referenceId = people.get(0).getReferent().getInternalId(); assertEquals("Chris Smith", people.get(0).getValue()); assertEquals("Chris", people.get(1).getValue()); assertEquals(referenceId, people.get(1).getReferent().getInternalId());
s.addToIndexes(); Person p = new Person(jCas); p.setBegin(0); p.setEnd(5); p.setValue(PERSON); p.addToIndexes(); assertEquals(r.getEnd(), relation.get(FIELD_END)); assertEquals(r.getConfidence(), relation.get(FIELD_CONFIDENCE)); assertEquals(p.getValue(), relation.get(FIELD_SOURCE_VALUE)); assertEquals(p.getType().getShortName(), relation.get(FIELD_SOURCE_TYPE)); 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));
e1.setConfidence(0.5); e1.setGender("male"); e1.addToIndexes(); docId, BALEEN_DOC_ID, toId(e1.getExternalId()), e1.getExternalId(), toId(rt1.getExternalId()), rt1.getExternalId(), e1.getBegin(), e1.getEnd(), e1.getType().getShortName(), e1.getValue()); final BaleenMention m2 = new BaleenMention( docId, BALEEN_DOC_ID, toId(e2.getExternalId()), e2.getExternalId(), toId(rt1.getExternalId()), rt1.getExternalId(), e2.getBegin(), e2.getEnd(), e2.getType().getShortName(), e2.getValue()); final BaleenMention m3 = new BaleenMention( docId,
public void assertPersonMatches() { final Person inPerson = JCasUtil.selectSingle(in, Person.class); final Person outPerson = JCasUtil.selectSingle(out, Person.class); assertEquals(inPerson.getGender(), outPerson.getGender()); assertEquals(inPerson.getBegin(), outPerson.getBegin()); assertEquals(inPerson.getEnd(), outPerson.getEnd()); assertEquals(inPerson.getValue(), outPerson.getValue()); assertEquals(0, inPerson.getConfidence(), outPerson.getConfidence()); // Check that person to entity is deferenced and its the same as the one we get... final ReferenceTarget inRt = JCasUtil.selectSingle(in, ReferenceTarget.class); final ReferenceTarget outRtFromJCas = JCasUtil.selectSingle(out, ReferenceTarget.class); final ReferenceTarget outRt = outPerson.getReferent(); assertNotNull(outRt); assertEquals(inRt.getBegin(), outRt.getBegin()); assertEquals(inRt.getEnd(), outRt.getEnd()); assertSame(outRt, outRtFromJCas); }
@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))); } }
@Test public void testSameAnnotationSameUUID() throws UIMAException { final SharedIdGenerator generator = createSharedIdGenerator(); final JCas jCas = JCasSingleton.getJCasInstance(); final Person p2 = new Person(jCas); p2.setBegin(0); p2.setEnd(10); final Person p1 = new Person(jCas); p1.setBegin(0); p1.setEnd(9); final String p1UUID = generator.generateForAnnotation(p1); final String p2UUID = generator.generateForAnnotation(p2); assertNotEquals(p1UUID, p2UUID); assertEquals(p1UUID, generator.generateForAnnotation(p1)); assertEquals(p2UUID, generator.generateForAnnotation(p2)); }
private void createDocument() { DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); da.setSourceUri(TEST1_TXT); CommsIdentifier ci = new CommsIdentifier(jCas); ci.addToIndexes(); Person p = new Person(jCas); p.addToIndexes(); }
@Test public void testCaseInsensitive() throws Exception { AnalysisEngine regexAE = AnalysisEngineFactory.createEngine( Custom.class, Custom.PARAM_TYPE, UK_GOV_DSTL_BALEEN_TYPES_COMMON_PERSON, Custom.PARAM_PATTERN, DIGIT_REGEX, Custom.PARAM_CASE_SENSITIVE, false); jCas.setDocumentText(TEXT); regexAE.process(jCas); assertEquals(2, JCasUtil.select(jCas, Person.class).size()); Person p1 = JCasUtil.selectByIndex(jCas, Person.class, 0); assertNotNull(p1); assertEquals(P123, p1.getCoveredText()); assertEquals(P123, p1.getValue()); Person p2 = JCasUtil.selectByIndex(jCas, Person.class, 1); assertNotNull(p2); assertEquals(P456, p2.getCoveredText()); assertEquals(P456, p2.getValue()); regexAE.destroy(); }
@Test public void testWholeDocument() { final TextBlock block = new TextBlock(jCas); assertTrue(block.isWholeDocument()); assertEquals(0, block.getBegin()); assertEquals(DOC_TEXT, block.getCoveredText()); assertEquals(DOC_TEXT, block.getDocumentText()); assertEquals(DOC_TEXT.length(), block.getEnd()); assertSame(jCas, block.getJCas()); assertNull(block.getText()); final Entity annotation = block.newAnnotation(Entity.class, 3, 7); assertNotNull(annotation); assertEquals(3, annotation.getBegin()); assertEquals(7, annotation.getEnd()); final Person p = new Person(jCas); block.setBeginAndEnd(p, 2, 10); assertEquals(2, p.getBegin()); assertEquals(10, p.getEnd()); assertEquals(1, block.toDocumentOffset(1)); assertEquals(1, block.toBlockOffset(1)); assertEquals(3, block.select(Buzzword.class).size()); } }
@Test public void testAthleteIsMadePersonNoSource() throws AnalysisEngineProcessException, ResourceInitializationException { processJCas( TemplateFieldToEntityAnnotator.PARAM_ENTITY_TYPE, "common.Person", TemplateFieldToEntityAnnotator.PARAM_FIELD_NAME, "athlete", TemplateFieldToEntityAnnotator.PARAM_RECORD_NAME, "report"); Person person = JCasUtil.selectSingle(jCas, Person.class); assertEquals("fox", person.getValue()); assertEquals(16, person.getBegin()); assertEquals(19, person.getEnd()); }
@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 testTab() throws Exception { AnalysisEngine nwAE = AnalysisEngineFactory.createEngine(NormalizeWhitespace.class); jCas.setDocumentText("Peter\tSmith lives in Salisbury"); Annotations.createPerson(jCas, 0, 11, "Peter\tSmith"); nwAE.process(jCas); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals(CORRECT_WHITESPACING, JCasUtil.selectByIndex(jCas, Person.class, 0).getValue()); assertEquals(true, JCasUtil.selectByIndex(jCas, Person.class, 0).getIsNormalised()); }
@Test public void testTwoExistingReferent() throws Exception { AnalysisEngine corefCapAE = AnalysisEngineFactory.createEngine(CorefCapitalisationAndApostrophe.class); jCas.setDocumentText(TEXT + " James has not been to Guatemala."); ReferenceTarget rt = Annotations.createReferenceTarget(jCas); Person p1 = Annotations.createPerson(jCas, 0, 5, JAMES); p1.setReferent(rt); Person p2 = Annotations.createPerson(jCas, 22, 27, JAMES_UC); p2.setReferent(rt); Annotations.createPerson(jCas, 56, 61, JAMES); corefCapAE.process(jCas); assertEquals(1, JCasUtil.select(jCas, ReferenceTarget.class).size()); ReferenceTarget rtt = JCasUtil.selectByIndex(jCas, ReferenceTarget.class, 0); Person p1t = JCasUtil.selectByIndex(jCas, Person.class, 0); Person p2t = JCasUtil.selectByIndex(jCas, Person.class, 1); Person p3t = JCasUtil.selectByIndex(jCas, Person.class, 2); assertEquals(rtt, p1t.getReferent()); assertEquals(rtt, p2t.getReferent()); assertEquals(rtt, p3t.getReferent()); }