Search in sources :

Example 1 with UriBearingPersonNames

use of nl.knaw.huygens.timbuctoo.rdf.UriBearingPersonNames in project timbuctoo by HuygensING.

the class PersonNameVariantTripleProcessor method mergeNames.

private UriBearingPersonNames mergeNames(String myRawValue, String theirRawValue) throws IOException {
    final UriBearingPersonNames theirs = objectMapper.readValue(theirRawValue, UriBearingPersonNames.class);
    final UriBearingPersonNames mine = objectMapper.readValue(myRawValue, UriBearingPersonNames.class);
    int startIndex = theirs.list.size();
    for (Map.Entry<String, Integer> entry : mine.nameUris.entrySet()) {
        theirs.list.add(mine.list.get(entry.getValue()));
        theirs.nameUris.put(entry.getKey(), entry.getValue() + startIndex);
    }
    return theirs;
}
Also used : UriBearingPersonNames(nl.knaw.huygens.timbuctoo.rdf.UriBearingPersonNames) Map(java.util.Map)

Example 2 with UriBearingPersonNames

use of nl.knaw.huygens.timbuctoo.rdf.UriBearingPersonNames 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());
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) UriBearingPersonNames(nl.knaw.huygens.timbuctoo.rdf.UriBearingPersonNames) IOException(java.io.IOException)

Aggregations

UriBearingPersonNames (nl.knaw.huygens.timbuctoo.rdf.UriBearingPersonNames)2 IOException (java.io.IOException)1 Map (java.util.Map)1 Entity (nl.knaw.huygens.timbuctoo.rdf.Entity)1