/** * This handles a 3 part name * * @param nameParts * @return */ private PersonNameAuthority maxThreePartNameSplit(String[] fullNameParts) { PersonName personName = new PersonName(); PersonNameAuthority nameAuthority = new PersonNameAuthority(personName); int size = fullNameParts.length; if (size >= 1) { personName.setSurname(fullNameParts[0].trim()); } if (size >= 2) { String firstNameParts = fullNameParts[1].trim(); if (firstNameParts.indexOf("(") == -1) { secondPartWithoutParens(personName, fullNameParts[1].trim()); } else { secondPartWithParens(personName, fullNameParts[1].trim()); } } if (size >= 3) { int birthYear = getBirthYear(fullNameParts[2]); if (birthYear > 0) { nameAuthority.addBirthDate(birthYear); } int deathYear = getDeathYear(fullNameParts[2]); if (deathYear > 0) { nameAuthority.addDeathDate(deathYear); } } return nameAuthority; }
/** * Handles a name that has four parts. * * @param fullNameParts * @return */ private PersonNameAuthority fourPartNameSplit(String[] fullNameParts) { PersonName personName = new PersonName(); PersonNameAuthority nameAuthority = new PersonNameAuthority(personName); // set the last name personName.setSurname(fullNameParts[0].trim()); // take care of last/middle name String firstNameParts = fullNameParts[1].trim(); if (firstNameParts.indexOf("(") == -1) { secondPartWithoutParens(personName, fullNameParts[1].trim()); } else { secondPartWithParens(personName, fullNameParts[1].trim()); } String title = fullNameParts[2]; personName.addPersonNameTitle(title); int birthYear = getBirthYear(fullNameParts[3]); if (birthYear > 0) { nameAuthority.addBirthDate(birthYear); } int deathYear = getDeathYear(fullNameParts[3]); if (deathYear > 0) { nameAuthority.addDeathDate(deathYear); } return nameAuthority; }
private void secondPartWithoutParens(PersonName personName, String firstAndMiddleNameParts) { int firstSpaceIndex = firstAndMiddleNameParts.indexOf(" "); if (firstSpaceIndex > -1) { String firstName = firstAndMiddleNameParts.substring(0, firstSpaceIndex).trim(); String middleName = firstAndMiddleNameParts .substring(firstSpaceIndex, firstAndMiddleNameParts.length()) .trim(); personName.setForename(firstName); personName.setMiddleName(middleName); } else { personName.setForename(firstAndMiddleNameParts); } }
/* (non-Javadoc) * @see edu.ur.dspace.load.AuthorNameSplitter#splitName(java.lang.String) */ public PersonNameAuthority splitName(String authorName) { PersonName personName = new PersonName(); PersonNameAuthority nameAuthority = new PersonNameAuthority(personName); // split on the name String[] fullNameParts = authorName.split(","); int size = fullNameParts.length; if (size < 4) { nameAuthority = maxThreePartNameSplit(fullNameParts); } if (size == 4) { nameAuthority = fourPartNameSplit(fullNameParts); } else { personName.setSurname(authorName); } return nameAuthority; }
/** * Handles a name part that looks like the following: H. C. (Hans Christian) * * @param personName * @param firstAndMiddleNameParts */ private void secondPartWithParens(PersonName personName, String firstAndMiddleNameParts) { if ((firstAndMiddleNameParts.indexOf("(") > -1) && (firstAndMiddleNameParts.indexOf(")") > -1) && (firstAndMiddleNameParts.indexOf("(") < firstAndMiddleNameParts.indexOf(")"))) { try { String initials = firstAndMiddleNameParts.substring(0, firstAndMiddleNameParts.indexOf("(") - 1); String firstAndMiddle = firstAndMiddleNameParts.substring( firstAndMiddleNameParts.indexOf("(") + 1, firstAndMiddleNameParts.indexOf(")")); secondPartWithoutParens(personName, firstAndMiddle); personName.setInitials(initials); } catch (StringIndexOutOfBoundsException sioobe) { log.debug("Error with name " + firstAndMiddleNameParts, sioobe); secondPartWithoutParens(personName, firstAndMiddleNameParts); } } else { // unbalanced take best guess secondPartWithoutParens(personName, firstAndMiddleNameParts); } }