/** * Replace the mentions with the principal coreferent entity (if there is one). * * @param entities the entities * @param referentMap the referent map * @return the set */ public static Set<Entity> replaceWithCoreferent( Collection<Entity> entities, Map<ReferenceTarget, Entity> referentMap) { final Set<Entity> set = new HashSet<>(entities.size()); for (final Entity t : entities) { if (t.getReferent() == null) { set.add(t); } else { final Entity entity = referentMap.get(t.getReferent()); if (entity != null) { set.add(entity); } else { // Add the other in set.add(t); } } } return set; } }
/** * Replace the mentions with the principal coreferent entity (if there is one). * * @param entities the entities * @param referentMap the referent map * @return the set */ public static Set<Entity> replaceWithCoreferent( Collection<Entity> entities, Map<ReferenceTarget, Entity> referentMap) { final Set<Entity> set = new HashSet<>(entities.size()); for (final Entity t : entities) { if (t.getReferent() == null) { set.add(t); } else { final Entity entity = referentMap.get(t.getReferent()); if (entity != null) { set.add(entity); } else { // Add the other in set.add(t); } } } return set; } }
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); } }
private String generateSpanStart(Entity e) { String value = e.getValue() == null ? "" : e.getValue().replaceAll("\"", "'"); String referent = e.getReferent() == null ? "" : Long.toString(e.getReferent().getInternalId()); return String.format( "<span class=\"baleen %s\" id=\"%s\" value=\"%s\" data-referent=\"%s\">", e.getClass().getSimpleName(), e.getExternalId(), value, referent); }
/** * Copy entity. * * @param jCas the j cas * @param begin the begin * @param end the end * @param entity the entity * @return the entity */ public static Entity copyEntity(JCas jCas, int begin, int end, Entity entity) { // TODO: This could be better, but would suggest if better is need try { final Entity instance = entity.getClass().getConstructor(JCas.class).newInstance(jCas); instance.setBegin(begin); instance.setEnd(end); instance.setReferent(entity.getReferent()); instance.setValue(entity.getValue()); return instance; } catch (final Exception e) { LOGGER.warn("Unable to copy entity", e); return null; } }
/** * Copy entity. * * @param jCas the j cas * @param begin the begin * @param end the end * @param entity the entity * @return the entity */ public static Entity copyEntity(JCas jCas, int begin, int end, Entity entity) { // TODO: This could be better, but would suggest if better is need try { final Entity instance = entity.getClass().getConstructor(JCas.class).newInstance(jCas); instance.setBegin(begin); instance.setEnd(end); instance.setReferent(entity.getReferent()); instance.setValue(entity.getValue()); return instance; } catch (final Exception e) { LOGGER.warn("Unable to copy entity", e); return null; } }
list.add(e.getExternalId()); if (e.getReferent() != null) { list.add(Long.toString(e.getReferent().getInternalId())); } else { list.add("");
/** * 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 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; } }
for (Entity entity : JCasUtil.select(jCas, Entity.class)) { if (entity.getReferent() != null) { targetted.put(entity.getReferent(), entity); } else {