/** * Return the document annotation. * * @param jCas * @return the document annotation */ protected DocumentAnnotation getDocumentAnnotation(JCas jCas) { return UimaSupport.getDocumentAnnotation(jCas); }
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Annotation... annotations) { add(Arrays.asList(annotations)); }
/** * Adds a event to the history for this jcas document. * * @param jCas the target document for the event * @param event the event to add */ public void addToHistory(JCas jCas, HistoryEvent event) { getDocumentHistory(jCas).add(event); }
/** * Add a new annotation, which is merged from the old annotations, removing the old annotations. * * @param newAnnotation The annotation which is to be added to the document as the merged result * of the old annotations * @param annotations Annotation(s) which have been merged and should be removed */ public void mergeWithNew(Annotation newAnnotation, Collection<? extends Annotation> annotations) { add(newAnnotation); mergeWithExisting(newAnnotation, annotations); }
final DocumentAnnotation da = UimaSupport.getDocumentAnnotation(jCas); da.setTimestamp(System.currentTimeMillis()); da.setDocType("re3d"); a.setConfidence(e.getConfidence()); getSupport().add(a); a.setSource(source.get()); a.setTarget(target.get()); getSupport().add(a);
EntityRelationConverter entityRelationConverter = new EntityRelationConverter( monitor, false, support.getDocumentHistory(jCas), stopFeatures, fields); DocumentAnnotation da = UimaSupport.getDocumentAnnotation(jCas); output.putAll(createDocumentAnnotationMap(da));
@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()); }
verify(support, only()).add(annotation); resetMocked(); verify(support, only()).add(list); resetMocked(); verify(support, only()).mergeWithExisting(existingAnnotation, annotation); resetMocked(); verify(support, only()).mergeWithExisting(existingAnnotation, list); resetMocked(); verify(support, only()).mergeWithNew(existingAnnotation, annotation); resetMocked(); verify(support, only()).mergeWithNew(existingAnnotation, list); resetMocked(); verify(support, only()).remove(annotation); resetMocked(); verify(support, only()).remove(list); resetMocked();
@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 testRemoveAnnotationArray() { UimaSupport support = new UimaSupport(PIPELINE, UimaSupportTest.class, history, monitor, false); support.remove(location, md); assertEquals(0, JCasUtil.select(jCas, Location.class).size()); assertEquals(0, JCasUtil.select(jCas, Metadata.class).size()); // Location should not have history and id assertNotNull(location.getInternalId()); assertFalse(support.getDocumentHistory(jCas).getHistory(location.getInternalId()).isEmpty()); }
@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()); }
/** * Merge entity onto targetEntity (assuming they have the same ReferentTarget), updating * relationships as required. * * @return True if merge was successful, false otherwise */ private boolean mergeEntities(Entity entity, Entity targetEntity) { ReferenceTarget targetRef = targetEntity.getReferent(); ReferenceTarget entityRef = entity.getReferent(); if (mergeDistinctEntities || isSameTarget(targetRef, entityRef)) { addMergeToHistory(targetEntity, entity); // Update relationship pointers for (Relation r : getRelations(entity)) { if (r.getSource() == entity) { r.setSource(targetEntity); } if (r.getTarget() == entity) { r.setTarget(targetEntity); } } remove(entity); return true; } else { monitor.debug( "Not merging objects {} and {} as they have different referents", targetEntity.getInternalId(), entity.getInternalId()); return false; } }
/** * Merge an existing annotation with old annotations, removing the old annotations. * * @param existingAnnotation The annotation which exists and is to be left in the document * (merged) * @param annotations Annotation(s) which have been merged wiht existingAnnotation and then * removed */ public void mergeWithExisting(Annotation existingAnnotation, Annotation... annotations) { mergeWithExisting(existingAnnotation, Arrays.asList(annotations)); }
protected UimaSupport createSupport(String pipelineName, UimaContext context) { return new UimaSupport( pipelineName, this.getClass(), history, monitor, UimaUtils.isMergeDistinctEntities(context)); }
/** * Add a new annotation, which is merged from the old annotations, removing the old annotations. * * @param newAnnotation The annotation which is to be added to the document as the merged result * of the old annotations * @param annotations Annotation(s) which have been merged and should be removed */ public void mergeWithNew(Annotation newAnnotation, Annotation... annotations) { mergeWithNew(newAnnotation, Arrays.asList(annotations)); }
@Test public void testGetRelations() { UimaSupport support = new UimaSupport(PIPELINE, UimaSupportTest.class, history, monitor, false); r2.addToIndexes(); List<Relation> relations = new ArrayList<>(support.getRelations(p1)); relations = new ArrayList<>(support.getRelations(p2)); assertEquals(r2, relations.get(1)); relations = new ArrayList<>(support.getRelations(p3));
@Test public void testMergeWithRelation() { UimaSupport support = new UimaSupport(PIPELINE, UimaSupportTest.class, history, monitor, false); r.addToIndexes(); support.mergeWithExisting(p1, p2);
/** * Remove an annotation to the JCas index, notifying UimaMonitor of the fact we have done so. * * <p>Relations that refer to the given annotation will also be removed. * * @param annot Annotation(s) to remove */ public void remove(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { if (annot instanceof Recordable) { try { addToHistory( annot.getCAS().getJCas(), HistoryEvents.createAdded((Recordable) annot, referrer)); } catch (CASException e) { monitor.error("Unable to add to history on remove", e); } } if (annot instanceof Entity) { for (Relation r : getRelations((Entity) annot)) { monitor.entityRemoved(r.getType().getName()); r.removeFromIndexes(); } } monitor.entityRemoved(annot.getType().getName()); annot.removeFromIndexes(); } }
final DocumentAnnotation da = UimaSupport.getDocumentAnnotation(jCas); da.setTimestamp(System.currentTimeMillis()); da.setDocType("re3d"); a.setConfidence(e.getConfidence()); getSupport().add(a); a.setSource(source.get()); a.setTarget(target.get()); getSupport().add(a);
@Test public void testMergeWithDontMergeDifferentReferent() { UimaSupport support = new UimaSupport(PIPELINE, UimaSupportTest.class, history, monitor, false); md2.addToIndexes(); support.mergeWithExisting(locationRT2Again, location, locationRT1, locationRT2); support.mergeWithExisting(md2, md); assertEquals(md2, mds.get(0)); assertTrue(support.getDocumentHistory(jCas).getHistory(locationRT1.getInternalId()).isEmpty()); assertFalse( support.getDocumentHistory(jCas).getHistory(locationRT2Again.getInternalId()).isEmpty());