use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class PersonNameVariantTripleProcessor method processAssertion.
@Override
protected void processAssertion(String vreName, String subject, String predicate, String object) {
final Optional<Entity> subjectEntity = database.findEntity(vreName, subject);
final Optional<Entity> objectEntity = database.findEntity(vreName, object);
if (!subjectEntity.isPresent()) {
LOG.error("Entity with rdf uri '{}' not found", subject);
return;
}
if (!objectEntity.isPresent()) {
LOG.error("Entity with rdf uri '{}' not found", object);
}
final Optional<String> subjectRawNames = subjectEntity.get().getPropertyValue(NAMES_PROPERTY_NAME);
if (subjectRawNames.isPresent()) {
final Optional<String> objectRawNames = objectEntity.get().getPropertyValue(NAMES_PROPERTY_NAME);
if (objectRawNames.isPresent()) {
try {
final UriBearingPersonNames mergedNames = mergeNames(subjectRawNames.get(), objectRawNames.get());
objectEntity.get().addProperty(NAMES_PROPERTY_NAME, objectMapper.writeValueAsString(mergedNames), NAMES_TYPE_ID);
} catch (IOException e) {
LOG.error("Failed to read/write personNames json", e);
return;
}
} else {
objectEntity.get().addProperty(NAMES_PROPERTY_NAME, subjectRawNames.get(), NAMES_TYPE_ID);
}
}
database.purgeEntity(vreName, subjectEntity.get());
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class PersonNamesTripleProcessor method processAssertion.
@Override
protected void processAssertion(String vreName, String subject, String predicate, String lexicalValue, String typeUri) {
LOG.debug("Process PersonNames triple for subject '{}' with value '{}'", subject, lexicalValue);
Entity entity = database.findOrCreateEntity(vreName, subject);
String propertyName = getLocalName(predicate);
Optional<String> propertyValue = entity.getPropertyValue(propertyName);
try {
PersonName personName = objectMapper.readValue(lexicalValue, PersonName.class);
PersonNames personNames = getPersonNames(objectMapper, propertyValue);
personNames.list.add(personName);
String names = objectMapper.writeValueAsString(personNames);
// Because the person names is wrapped in a person names type, the type changes
entity.addProperty(propertyName, names, NAMES_TYPE_ID);
} catch (IOException e) {
LOG.error("Could not convert '{}' to PersonName", lexicalValue);
}
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class RelationTripleProcessor method processRetraction.
@Override
protected void processRetraction(String vreName, String subject, String predicate, String object) {
final Entity subjectEntity = database.findOrCreateEntity(vreName, subject);
final RelationType relationType = database.findOrCreateRelationType(predicate, getLocalName(predicate));
final Entity objectEntity = database.findOrCreateEntity(vreName, object);
subjectEntity.removeRelation(relationType, objectEntity);
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class RelationTripleProcessor method processAssertion.
@Override
protected void processAssertion(String vreName, String subject, String predicate, String object) {
final Entity subjectEntity = database.findOrCreateEntity(vreName, subject);
final RelationType relationType = database.findOrCreateRelationType(predicate, getLocalName(predicate));
final Entity objectEntity = database.findOrCreateEntity(vreName, object);
if (relationType.isInverted()) {
final Relation relation = objectEntity.addRelation(relationType, subjectEntity);
relation.setCommonVreProperties(vreName);
} else {
final Relation relation = subjectEntity.addRelation(relationType, objectEntity);
relation.setCommonVreProperties(vreName);
}
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class SameAsTripleProcessor method processAssertion.
@Override
protected void processAssertion(String vreName, String subject, String predicate, String object) {
if (StringUtils.isBlank(object)) {
return;
}
Optional<Entity> objectEntityOpt = database.findEntity(vreName, object);
Optional<Entity> subjectEntityOpt = database.findEntity(vreName, subject);
if (objectEntityOpt.isPresent() && subjectEntityOpt.isPresent()) {
final Entity objectEntity = objectEntityOpt.get();
final Entity subjectEntity = subjectEntityOpt.get();
if (LOG.isDebugEnabled()) {
LOG.debug("Merging object entity into subject entity: {} <-- {}", subjectEntity.getProperties(), objectEntity.getProperties());
}
// First make sure all the edges are copied (especially edges pointing to collections only the object is part of)
database.copyEdgesFromObjectIntoSubject(subjectEntity, objectEntity);
// Reload subject entity with any new collection added to it from the object (vertex must still be present here)
final Entity reloadedSubjectEntity = database.findEntity(vreName, subject).get();
// Merge the properties of the object entity into the reloaded subject entity via Entity model
mergeEntityProperties(reloadedSubjectEntity, objectEntity);
if (LOG.isDebugEnabled()) {
final Entity finalSubject = database.findEntity(vreName, subject).get();
LOG.debug("Final subject properties: {}", finalSubject.getProperties());
}
// purge the object entity from the database and index
database.purgeEntity(vreName, objectEntity);
// add the object uri as a synonym to the subject entity
database.addRdfSynonym(vreName, subjectEntity, object);
} else if (objectEntityOpt.isPresent()) {
database.addRdfSynonym(vreName, objectEntityOpt.get(), subject);
} else if (subjectEntityOpt.isPresent()) {
database.addRdfSynonym(vreName, subjectEntityOpt.get(), object);
} else {
Entity entity = database.findOrCreateEntity(vreName, object);
database.addRdfSynonym(vreName, entity, subject);
}
}
Aggregations