@Override protected void doProcess(JCas jCas) throws AnalysisEngineProcessException { Map<String, Object> json = SingleDocumentConsumerFormat.formatCas( jCas, fields, contentHashAsId, getMonitor(), getSupport()); String id = (String) json.getOrDefault("externalId", ""); // Persist to ElasticSearch addDocument(id, json); }
/** Add history to the map */ public Map<String, Object> convert() { Map<String, Object> map = new IgnoreEmptyKeyMapDecorator<>(new LinkedHashMap<>()); List<Object> list = createEventsList(); map.put(fields.getHistory(), list); return map; }
private void convertHistory(Map<String, Object> map, Base entity) { HistoryConverter historyConverter = new HistoryConverter(entity, fields, documentHistory, monitor); map.putAll(historyConverter.convert()); } }
/** * 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; }
/** * Gets the unique id for a document (if contentHashAsId is true then as hash of the content is * used, otherwise a hash of the source URI is used). * * @param jCas the JCas * @return the unique id */ private String getUniqueId(JCas jCas) { return ConsumerUtils.getExternalId(getDocumentAnnotation(jCas), contentHashAsId); } }
private void createERC() { final IEntityConverterFields fields = new DefaultFields(); final HashSet<String> stopFeatures = new HashSet<>(); stopFeatures.add("uima.cas.AnnotationBase:sofa"); stopFeatures.add("uk.gov.dstl.baleen.types.BaleenAnnotation:internalId"); erc = new EntityRelationConverter(monitor, stopFeatures, fields, false); }
@Override public void doInitialize(UimaContext aContext) throws ResourceInitializationException { boolean indexCreated = createIndex(); if (indexCreated) { try { addMapping(createMappingObject()); } catch (IOException ioe) { getMonitor() .error( "Unable to create mapping, you may get unexpected results in your Elasticsearch index", ioe); } } }
protected static String normalizeFeatureName(final Feature f) { return ConsumerUtils.toCamelCase(f.getShortName()); } }
private void convertFeatures(Map<String, Object> map, Base base) { for (Feature f : base.getType().getFeatures()) { processFeature(map, base, f); } map.put(fields.getType(), base.getType().getShortName()); if (map.get(FIELD_VALUE) == null || Strings.isNullOrEmpty(map.get(FIELD_VALUE).toString())) { map.put(FIELD_VALUE, base.getCoveredText()); } }
private void putGeoJson(Map<String, Object> map, String geojson) { try { if (!Strings.isNullOrEmpty(geojson)) { map.put(fields.getGeoJSON(), mapper.readValue(geojson, mapLikeType)); } } catch (IOException e) { getMonitor().warn("Unable to persist geoJson", e); } }
@Override protected void doProcess(JCas jCas) throws AnalysisEngineProcessException { String documentSourceName = SourceUtils.getDocumentSourceBaseName(jCas); Graph entityGraph = factory.create(jCas); processGraph(documentSourceName, entityGraph); }
private void createEventsList(List<Object> list, Collection<HistoryEvent> mergedHistoryEvents) { for (HistoryEvent mergedHistoryEvent : mergedHistoryEvents) { Map<String, Object> map = createEventMap(mergedHistoryEvent); list.add(map); } }
@Override public void doInitialize(UimaContext aContext) throws ResourceInitializationException { super.doInitialize(aContext); structuralClasses = StructureUtil.getStructureClasses(typeNames); }
/** * 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; }
/** * Gets the unique id for a document (if contentHashAsId is true then as hash of the content is * used, otherwise a hash of the source URI is used). * * @param jCas the JCas * @return the unique id */ private String getUniqueId(JCas jCas) { return ConsumerUtils.getExternalId(getDocumentAnnotation(jCas), contentHashAsId); } }
/** * 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; }
protected String getUniqueId(JCas jCas) { return ConsumerUtils.getExternalId(getDocumentAnnotation(jCas), contentHashAsId); }
protected String getUniqueId(JCas jCas) { return ConsumerUtils.getExternalId(getDocumentAnnotation(jCas), contentHashAsId); }
private String getUniqueId(JCas jCas) { return ConsumerUtils.getExternalId(getDocumentAnnotation(jCas), contentHashAsId); }
private String getDocumentId(JCas jCas) { return ConsumerUtils.getExternalId( UimaSupport.getDocumentAnnotation(jCas), options.isContentHashAsId()); }