private void addMentionProperties(Map<String, Object> mention, Traverser<Vertex> vt) { Vertex vertex = vt.get(); mention .entrySet() .stream() .filter(property -> property.getValue() != null) .filter(property -> property.getKey() != fields.getExternalId()) .forEach(property -> vertex.property(property.getKey(), coerce(property.getValue()))); }
private void addRelationProperties( Map<String, Object> relation, Traverser<? extends Element> relationElement) { Element rel = relationElement.get(); relation .entrySet() .stream() .filter(property -> property.getValue() != null) .filter(property -> property.getKey() != fields.getExternalId()) .forEach(property -> setProperty(rel, property.getKey(), property.getValue())); }
private void addRelationProperties( Map<String, Object> relation, Traverser<? extends Element> relationElement) { Element rel = relationElement.get(); relation .entrySet() .stream() .filter(property -> property.getValue() != null) .filter(property -> property.getKey() != fields.getExternalId()) .forEach(property -> setProperty(rel, property.getKey(), property.getValue())); }
private void addMentionProperties(Map<String, Object> mention, Traverser<Vertex> vt) { Vertex vertex = vt.get(); mention .entrySet() .stream() .filter(property -> property.getValue() != null) .filter(property -> property.getKey() != fields.getExternalId()) .forEach(property -> vertex.property(property.getKey(), coerce(property.getValue()))); }
/** Get the mongo db, collection and create some indexes */ @Override public void doInitialize(UimaContext aContext) throws ResourceInitializationException { MongoDatabase db = mongoResource.getDB(); entitiesCollection = db.getCollection(entitiesCollectionName); relationsCollection = db.getCollection(relationsCollectionName); documentsCollection = db.getCollection(documentsCollectionName); documentsCollection.createIndex(new Document(fields.getExternalId(), 1)); entitiesCollection.createIndex(new Document(fields.getExternalId(), 1)); relationsCollection.createIndex(new Document(fields.getExternalId(), 1)); relationsCollection.createIndex(new Document(FIELD_DOCUMENT_ID, 1)); entitiesCollection.createIndex(new Document(FIELD_DOCUMENT_ID, 1)); stopFeatures = new HashSet<>(); stopFeatures.add("uima.cas.AnnotationBase:sofa"); stopFeatures.add("uk.gov.dstl.baleen.types.BaleenAnnotation:internalId"); }
private void deleteAnyExistingContent(String documentId) { entitiesCollection.deleteMany(new Document(FIELD_DOCUMENT_ID, documentId)); relationsCollection.deleteMany(new Document(FIELD_DOCUMENT_ID, documentId)); documentsCollection.deleteMany(new Document(fields.getExternalId(), documentId)); }
/** Get the mongo db, collection and create some indexes */ @Override public void doInitialize(UimaContext aContext) throws ResourceInitializationException { MongoDatabase db = mongoResource.getDB(); relationsCollection = db.getCollection(relationsCollectionName); relationsCollection.createIndex(new Document(fields.getExternalId(), 1)); relationsCollection.createIndex(new Document(FIELD_SOURCE_VALUE, 1)); relationsCollection.createIndex(new Document(FIELD_VALUE, 1)); relationsCollection.createIndex(new Document(FIELD_TARGET_VALUE, 1)); relationsCollection.createIndex( new Document(ImmutableMap.of(FIELD_SOURCE_VALUE, 1, FIELD_TARGET_VALUE, 1))); relationsCollection.createIndex(new Document(FIELD_DOCUMENT_ID, 1)); }
/** Get the mongo db, collection and create some indexes */ @Override public void doInitialize(UimaContext aContext) throws ResourceInitializationException { MongoDatabase db = mongoResource.getDB(); eventsCollection = db.getCollection(eventsCollectionName); eventsCollection.createIndex(new Document(fields.getExternalId(), 1)); eventsCollection.createIndex(new Document(FIELD_DOCUMENT_ID, 1)); eventsCollection.createIndex(new Document(FIELD_TYPE, 1)); eventsCollection.createIndex(new Document(FIELD_TYPES, 1)); eventsCollection.createIndex(new Document(FIELD_TOKENS, 1)); Set<String> stopFeatures = new HashSet<>(); stopFeatures.add("uima.cas.AnnotationBase:sofa"); stopFeatures.add("uk.gov.dstl.baleen.types.BaleenAnnotation:internalId"); textClass = getTextClass(); }
/** * Convert from a relation to a map. * * @param relation the relation to convert * @return a map containing the relation's fields (and history is required) */ public Map<String, Object> convertRelation(Relation relation) { Map<String, Object> map = new IgnoreEmptyKeyMapDecorator<>(Maps.newHashMap()); convertFeatures(map, relation); if (outputHistory && documentHistory != null) { convertHistory(map, relation); } map.put(fields.getExternalId(), relation.getExternalId()); return map; }
/** * Convert from an entity to a map. * * @param entity the entity to convert * @return a map containing the entity's fields (and history is required) */ public Map<String, Object> convertEntity(Entity entity) { Map<String, Object> map = new IgnoreEmptyKeyMapDecorator<>(Maps.newHashMap()); convertFeatures(map, entity); if (outputHistory && documentHistory != null) { convertHistory(map, entity); } map.put(fields.getExternalId(), entity.getExternalId()); return map; }
/** * Convert from an event to a map. * * @param event the relation to convert * @return a map containing the relation's fields (and history is required) */ public Map<String, Object> convertEvent(Event event) { Map<String, Object> map = new IgnoreEmptyKeyMapDecorator<>(Maps.newHashMap()); convertFeatures(map, event); if (outputHistory && documentHistory != null) { convertHistory(map, event); } map.put(fields.getExternalId(), event.getExternalId()); return map; }
.stream() .map(converter::convertEvent) .filter(e -> !traversal.V(coerce(e.get(fields.getExternalId()))).hasNext()) .forEach( e -> { traversal .addV(EVENT) .property(T.id, coerce(e.get(fields.getExternalId()))) .sideEffect( vt -> .stream() .filter(property -> property.getValue() != null) .filter(property -> property.getKey() != fields.getExternalId()) .filter(property -> property.getKey() != "entities") .forEach(
return new Document() .append(FIELD_DOCUMENT_ID, documentId) .append(fields.getExternalId(), ConsumerUtils.getExternalId(e.getValue())) .append(FIELD_LINKING, referenceTarget.getLinking()) .append(
setIfValue(variables, fields.getExternalId(), getDocumentId(jCas));
setIfValue(variables, fields.getExternalId(), getDocumentId(jCas));
private void saveDocument(String documentId, JCas jCas) { Document doc = new Document(); DocumentAnnotation da = getDocumentAnnotation(jCas); doc.append(fields.getExternalId(), documentId) .append( FIELD_DOCUMENT, new Document() .append(FIELD_DOCUMENT_TYPE, da.getDocType()) .append(FIELD_DOCUMENT_SOURCE, da.getSourceUri()) .append(FIELD_DOCUMENT_LANGUAGE, da.getLanguage()) .append(FIELD_DOCUMENT_TIMESTAMP, new Date(da.getTimestamp())) .append(FIELD_DOCUMENT_CLASSIFICATION, da.getDocumentClassification()) .append(FIELD_DOCUMENT_CAVEATS, toList(da.getDocumentCaveats())) .append(FIELD_DOCUMENT_RELEASABILITY, toList(da.getDocumentReleasability()))); addPublishedIds(jCas, doc); addMetadata(jCas, doc); if (outputContent) { doc.append(FIELD_CONTENT, jCas.getDocumentText()); } documentsCollection.insertOne(doc); }
traversal.V(sourceId).as(SOURCE).V(targetId).as(TARGET); Object relationId = relation.get(fields.getExternalId());
traversal.V(sourceId).as(SOURCE).V(targetId).as(TARGET); Object relationId = relation.get(fields.getExternalId());
@SuppressWarnings("unchecked") @Test public void testReferenceTargets() throws AnalysisEngineProcessException { jCas.setDocumentText("Bill went to London. William came back."); String link = "http://test"; Person p = Annotations.createPerson(jCas, 0, 4, "Bill"); Person q = Annotations.createPerson(jCas, 21, 28, NAME_2); ReferenceTarget referenceTarget = Annotations.createReferenceTarget(jCas, p, q); referenceTarget.setLinking(link); ae.process(jCas); assertEquals(1, documents.count()); assertEquals(1, entities.count()); Document a = entities.find().first(); assertEquals(2, ((List<Object>) a.get(Mongo.FIELD_ENTITIES)).size()); assertEquals(2, ((List<Object>) a.get(Mongo.FIELD_ENTITIES)).size()); assertEquals(link, a.getString(Mongo.FIELD_LINKING)); assertEquals( ConsumerUtils.getExternalId(ImmutableList.of(p, q)), a.getString(fields.getExternalId())); }
.toArray()); assertEquals(getDocumentAnnotation(jCas).getHash(), result.get(fields.getExternalId()));