/** * 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); }
/** * 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); }
private void saveRelations(String documentId, JCas jCas) { EntityRelationConverter converter = new EntityRelationConverter( getMonitor(), outputHistory, getSupport().getDocumentHistory(jCas), stopFeatures, fields); List<Document> rels = JCasUtil.select(jCas, Relation.class) .stream() .map(converter::convertRelation) .map(Document::new) .peek(d -> d.append(FIELD_DOCUMENT_ID, documentId)) .collect(toList()); if (!rels.isEmpty()) { relationsCollection.insertMany(rels); } } }
/** * Adds a event to the history for this CAS document. * * @param cas the target document for the event * @param event the event to add */ public void addToHistory(CAS cas, HistoryEvent event) { try { getDocumentHistory(cas.getJCas()).add(event); } catch (CASException e) { monitor.error("Unable to add to history on add", e); } }
/** * Adds a event to the history for this CAS document. * * @param cas the target document for the event * @param event the event to add */ public void addToHistory(CAS cas, HistoryEvent event) { try { getDocumentHistory(cas.getJCas()).add(event); } catch (CASException e) { monitor.error("Unable to add to history on add", e); } }
getMonitor(), outputHistory, getSupport().getDocumentHistory(jCas), stopFeatures, fields);
EntityRelationConverter entityRelationConverter = new EntityRelationConverter( monitor, false, support.getDocumentHistory(jCas), stopFeatures, fields);
HistoryConverter converter = new HistoryConverter( e, fields, getSupport().getDocumentHistory(jCas), getMonitor()); Map<String, Object> historyMap = converter.convert(); document.append(FIELD_HISTORY, historyMap);
@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()); }
getMonitor(), false, getSupport().getDocumentHistory(jCas), stopFeatures, new DefaultFields());
@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()); }
@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()); }
assertEquals(md2, mds.get(0)); assertTrue(support.getDocumentHistory(jCas).getHistory(locationRT1.getInternalId()).isEmpty()); assertFalse( support.getDocumentHistory(jCas).getHistory(locationRT2Again.getInternalId()).isEmpty());
support.getDocumentHistory(jCas).getHistory(locationRT2Again.getInternalId()).isEmpty());