Search in sources :

Example 1 with PersonName

use of nl.knaw.huygens.timbuctoo.model.PersonName in project timbuctoo by HuygensING.

the class PersonNamesDefaultNamePropertyParserTest method parseReturnsTheShortNameOfTheFirstNameOfThePersonNames.

@Test
public void parseReturnsTheShortNameOfTheFirstNameOfThePersonNames() throws JsonProcessingException {
    PersonNames names = new PersonNames();
    PersonName name1 = PersonName.newInstance("forename", "surname");
    names.list.add(name1);
    names.list.add(PersonName.newInstance("forename2", "surname2"));
    String input = new ObjectMapper().writeValueAsString(names);
    String value = instance.parse(input);
    assertThat(value, is(name1.getShortName()));
}
Also used : PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) PersonName(nl.knaw.huygens.timbuctoo.model.PersonName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with PersonName

use of nl.knaw.huygens.timbuctoo.model.PersonName in project timbuctoo by HuygensING.

the class WwPersonDisplayNameTest method getPersonName.

private String getPersonName(String foreName, String surName) {
    PersonName name = new PersonName();
    name.addNameComponent(PersonNameComponent.Type.FORENAME, foreName);
    name.addNameComponent(PersonNameComponent.Type.SURNAME, surName);
    String nameProp;
    try {
        nameProp = new ObjectMapper().writeValueAsString(name);
    } catch (IOException e) {
        nameProp = "";
    }
    return "{\"list\": [" + nameProp + "]}";
}
Also used : PersonName(nl.knaw.huygens.timbuctoo.model.PersonName) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with PersonName

use of nl.knaw.huygens.timbuctoo.model.PersonName in project timbuctoo by HuygensING.

the class PersonNamesDefaultNamePropertyParserTest method parseForSortReturnsAStringThatConsistsOfSortNameVariantOfTheDefaultName.

@Test
public void parseForSortReturnsAStringThatConsistsOfSortNameVariantOfTheDefaultName() throws JsonProcessingException {
    PersonNames names = new PersonNames();
    PersonName name1 = PersonName.newInstance("forename", "surname");
    names.list.add(name1);
    PersonName name2 = PersonName.newInstance("forename2", "surname2");
    names.list.add(name2);
    String input = new ObjectMapper().writeValueAsString(names);
    Object value = instance.parseForSort(input);
    assertThat(value, is(names.defaultName().getSortName()));
}
Also used : PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) PersonName(nl.knaw.huygens.timbuctoo.model.PersonName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with PersonName

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

Example 5 with PersonName

use of nl.knaw.huygens.timbuctoo.model.PersonName in project timbuctoo by HuygensING.

the class UriBearingPersonNames method removeComponent.

public void removeComponent(String nameUri, PersonNameComponent.Type nameType, String value) {
    if (!nameUris.containsKey(nameUri)) {
        LoggerFactory.getLogger(UriBearingPersonNames.class).error("Uri '{}' not known", nameUri);
        return;
    }
    PersonName personName = list.get(nameUris.get(nameUri));
    personName.getComponents().remove(new PersonNameComponent(nameType, value));
    if (personName.getComponents().isEmpty()) {
        list.remove(personName);
        Integer indexOfRemoved = nameUris.remove(nameUri);
        // reindex the name uri's, because the list will do this automatically.
        Map<String, Integer> newNameUris = Maps.newHashMap();
        nameUris.forEach((key, val) -> {
            if (val > indexOfRemoved) {
                val--;
            }
            newNameUris.put(key, val);
        });
        nameUris = newNameUris;
    }
}
Also used : PersonName(nl.knaw.huygens.timbuctoo.model.PersonName) PersonNameComponent(nl.knaw.huygens.timbuctoo.model.PersonNameComponent)

Aggregations

PersonName (nl.knaw.huygens.timbuctoo.model.PersonName)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 PersonNames (nl.knaw.huygens.timbuctoo.model.PersonNames)3 IOException (java.io.IOException)2 Test (org.junit.Test)2 PersonNameComponent (nl.knaw.huygens.timbuctoo.model.PersonNameComponent)1 Entity (nl.knaw.huygens.timbuctoo.rdf.Entity)1