Esempio n. 1
0
  private void processCoreferencedEntities(Integer docKey, List<Entity> entities)
      throws SQLException {
    Set<String> values = new HashSet<>();
    Set<String> externalIds = new HashSet<>();
    Set<String> geoJsons = new HashSet<>();

    Class<? extends Entity> type = null;

    for (Entity e : entities) {
      values.add(e.getValue());
      externalIds.add(e.getExternalId());

      if (e instanceof Location) {
        Location l = (Location) e;
        try {
          geoJsons.add(addCrsToGeoJSON(l.getGeoJson()));
        } catch (BaleenException ex) {
          getMonitor().warn("Unable to add CRS to GeoJSON", ex);
        }
      }

      type = getSuperclass(type, e.getClass());
    }

    Integer entityKey = executeEntityInsert(docKey, values, externalIds, type.getName());
    if (entityKey != null) {
      for (String geoJson : geoJsons) {
        executeEntityGeoInsert(entityKey, geoJson);
      }
    }
  }
  private List<String> getEntityIds(FSArray entityArray) {
    List<String> entities = new ArrayList<>();

    for (int x = 0; x < entityArray.size(); x++) {
      Entity ent = (Entity) entityArray.get(x);
      entities.add(ent.getExternalId());
    }

    return entities;
  }
  /**
   * 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 = Maps.newHashMap();

    convertFeatures(map, entity);

    if (outputHistory && documentHistory != null) {
      Collection<HistoryEvent> events = documentHistory.getHistory(entity.getInternalId());
      convertHistory(map, events, entity.getInternalId());
    }
    putIfExists(map, fields.getExternalId(), entity.getExternalId());

    return map;
  }
Esempio n. 4
0
  private void processEntities(JCas jCas, Integer docKey) throws SQLException {
    // Insert entities
    Map<ReferenceTarget, List<Entity>> coreferenceEntities = new HashMap<>();

    for (Entity ent : JCasUtil.select(jCas, Entity.class)) {
      ReferenceTarget rt = ent.getReferent();
      if (rt == null) {
        rt = new ReferenceTarget(jCas);
      }
      List<Entity> entities = coreferenceEntities.getOrDefault(rt, new ArrayList<>());
      entities.add(ent);
      coreferenceEntities.put(rt, entities);
    }

    for (List<Entity> entities : coreferenceEntities.values()) {
      processCoreferencedEntities(docKey, entities);
    }
  }
  @Override
  public void doProcess(JCas aJCas) throws AnalysisEngineProcessException {
    List<Entity> toRemove = new ArrayList<Entity>();

    FSIterator<Annotation> iter = aJCas.getAnnotationIndex(Entity.type).iterator();
    while (iter.hasNext()) {
      Entity e = (Entity) iter.next();

      if (e.getConfidence() < confidenceThreshold
          && (!ignoreZeroConfidence || e.getConfidence() > 0.0)) {
        toRemove.add(e);
        getMonitor()
            .debug(
                "Low confidence entity found (ID: {}) - this entity will be removed",
                e.getInternalId());
      }
    }

    removeFromJCasIndex(toRemove);
  }