@Test public void suffixFix_per() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Doe, Sr; John"); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("John", ((NamePerson) name).getFirstName()); assertEquals("Doe", ((NamePerson) name).getLastName()); assertEquals("Sr", name.getSuffix()); }
public Name createName(String fullName) throws InvalidDataException { if (fullName == null || fullName.trim().isEmpty()) { throw new InvalidDataException("Name is missing"); } List<String> nameParts = Splitter.onPattern(";").limit(2).trimResults().splitToList(fullName); Name entityName = null; if (nameParts.size() == 2) { String lastName = nameParts.get(0); String firstName = nameParts.get(1); if ((firstName.length() > longNameLen || lastName.length() > longNameLen) && (isOrgName(firstName) || isOrgName(lastName))) { return new NameOrg(fullName); } firstName = FN_CLEAN.matcher(firstName).replaceFirst(""); lastName = LN_CLEAN.matcher(lastName).replaceFirst(""); lastName = LN_COMMA_FIX.matcher(lastName).replaceFirst("$1, $2 "); if (lastName.contains(",")) { String[] parts = suffixFix(lastName); if (parts != null && "per".equals(parts[0])) { lastName = parts[1]; entityName = new NamePerson(firstName, lastName); entityName.setSuffix(parts[2]); } else if (parts != null && "org".equals(parts[0])) { lastName = parts[1]; entityName = new NameOrg(fullName); entityName.setSuffix(parts[2]); } else if (parts != null && "per-syn".endsWith(parts[0])) { lastName = parts[1]; String suffix = parts[2]; String synonym = parts[3]; if (synonym.contains(firstName)) { synonym = synonym.replace(firstName, ""); } entityName = new NamePerson(firstName, lastName); entityName.setSuffix(suffix); entityName.addSynonym(synonym + ", " + firstName); entityName.addSynonym(synonym + ", " + firstName.subSequence(0, 1) + "."); } else { entityName = new NameOrg(fullName); } } else { entityName = new NamePerson(firstName, lastName); } } else { entityName = new NameOrg(fullName); } return entityName; }
NameNode extends ItemReader<Name> { public Name createName(String fullName) throws InvalidDataException { if (fullName == null || fullName.trim().isEmpty()) { throw new InvalidDataException("Name is missing"); } List<String> nameParts = Splitter.onPattern(";").limit(2).trimResults().splitToList(fullName); Name entityName = null; if (nameParts.size() == 2) { String lastName = nameParts.get(0); String firstName = nameParts.get(1); if ((firstName.length() > longNameLen || lastName.length() > longNameLen) && (isOrgName(firstName) || isOrgName(lastName))) { return new NameOrg(fullName); } firstName = FN_CLEAN.matcher(firstName).replaceFirst(""); lastName = LN_CLEAN.matcher(lastName).replaceFirst(""); lastName = LN_COMMA_FIX.matcher(lastName).replaceFirst("$1, $2 "); if (lastName.contains(",")) { String[] parts = suffixFix(lastName); if (parts != null && "per".equals(parts[0])) { lastName = parts[1]; entityName = new NamePerson(firstName, lastName); entityName.setSuffix(parts[2]); } else if (parts != null && "org".equals(parts[0])) { lastName = parts[1]; entityName = new NameOrg(fullName); entityName.setSuffix(parts[2]); } else if (parts != null && "per-syn".endsWith(parts[0])) { lastName = parts[1]; String suffix = parts[2]; String synonym = parts[3]; if (synonym.contains(firstName)) { synonym = synonym.replace(firstName, ""); } entityName = new NamePerson(firstName, lastName); entityName.setSuffix(suffix); entityName.addSynonym(synonym + ", " + firstName); entityName.addSynonym(synonym + ", " + firstName.subSequence(0, 1) + "."); } else { entityName = new NameOrg(fullName); } } else { entityName = new NamePerson(firstName, lastName); } } else { entityName = new NameOrg(fullName); } return entityName; } }
NameNode extends ItemReader<Name> { public Name createName(String fullName) throws InvalidDataException { if (fullName == null || fullName.trim().isEmpty()) { throw new InvalidDataException("Name is missing"); } List<String> nameParts = Splitter.onPattern(";").limit(2).trimResults().splitToList(fullName); Name entityName = null; if (nameParts.size() == 2) { String lastName = nameParts.get(0); String firstName = nameParts.get(1); if ((firstName.length() > longNameLen || lastName.length() > longNameLen) && (isOrgName(firstName) || isOrgName(lastName))) { return new NameOrg(fullName); } firstName = FN_CLEAN.matcher(firstName).replaceFirst(""); lastName = LN_CLEAN.matcher(lastName).replaceFirst(""); lastName = LN_COMMA_FIX.matcher(lastName).replaceFirst("$1, $2 "); if (lastName.contains(",")) { String[] parts = suffixFix(lastName); if (parts != null && "per".equals(parts[0])) { lastName = parts[1]; entityName = new NamePerson(firstName, lastName); entityName.setSuffix(parts[2]); } else if (parts != null && "org".equals(parts[0])) { lastName = parts[1]; entityName = new NameOrg(fullName); entityName.setSuffix(parts[2]); } else if (parts != null && "per-syn".endsWith(parts[0])) { lastName = parts[1]; String suffix = parts[2]; String synonym = parts[3]; if (synonym.contains(firstName)) { synonym = synonym.replace(firstName, ""); } entityName = new NamePerson(firstName, lastName); entityName.setSuffix(suffix); entityName.addSynonym(synonym + ", " + firstName); entityName.addSynonym(synonym + ", " + firstName.subSequence(0, 1) + "."); } else { entityName = new NameOrg(fullName); } } else { entityName = new NamePerson(firstName, lastName); } } else { entityName = new NameOrg(fullName); } return entityName; } NameNode(Node itemNode); }
NameNode extends ItemReader<Name> { public Name createName(String fullName) throws InvalidDataException { if (fullName == null || fullName.trim().isEmpty()) { throw new InvalidDataException("Name is missing"); } List<String> nameParts = Splitter.onPattern(";").limit(2).trimResults().splitToList(fullName); Name entityName = null; if (nameParts.size() == 2) { String lastName = nameParts.get(0); String firstName = nameParts.get(1); if ((firstName.length() > longNameLen || lastName.length() > longNameLen) && (isOrgName(firstName) || isOrgName(lastName))) { return new NameOrg(fullName); } firstName = FN_CLEAN.matcher(firstName).replaceFirst(""); lastName = LN_CLEAN.matcher(lastName).replaceFirst(""); lastName = LN_COMMA_FIX.matcher(lastName).replaceFirst("$1, $2 "); if (lastName.contains(",")) { String[] parts = suffixFix(lastName); if (parts != null && "per".equals(parts[0])) { lastName = parts[1]; entityName = new NamePerson(firstName, lastName); entityName.setSuffix(parts[2]); } else if (parts != null && "org".equals(parts[0])) { lastName = parts[1]; entityName = new NameOrg(fullName); entityName.setSuffix(parts[2]); } else if (parts != null && "per-syn".endsWith(parts[0])) { lastName = parts[1]; String suffix = parts[2]; String synonym = parts[3]; if (synonym.contains(firstName)) { synonym = synonym.replace(firstName, ""); } entityName = new NamePerson(firstName, lastName); entityName.setSuffix(suffix); entityName.addSynonym(synonym + ", " + firstName); entityName.addSynonym(synonym + ", " + firstName.subSequence(0, 1) + "."); } else { entityName = new NameOrg(fullName); } } else { entityName = new NamePerson(firstName, lastName); } } else { entityName = new NameOrg(fullName); } return entityName; } NameNode(Node itemNode); @Override Name read(); Name createName(String fullName); boolean isOrgName(String name); }
NameNode extends ItemReader<Name> { public Name createName(String fullName) throws InvalidDataException { if (fullName == null || fullName.trim().isEmpty()) { throw new InvalidDataException("Name is missing"); } List<String> nameParts = Splitter.onPattern(";").limit(2).trimResults().splitToList(fullName); Name entityName = null; if (nameParts.size() == 2) { String lastName = nameParts.get(0); String firstName = nameParts.get(1); if ((firstName.length() > longNameLen || lastName.length() > longNameLen) && (isOrgName(firstName) || isOrgName(lastName))) { return new NameOrg(fullName); } firstName = FN_CLEAN.matcher(firstName).replaceFirst(""); lastName = LN_CLEAN.matcher(lastName).replaceFirst(""); lastName = LN_COMMA_FIX.matcher(lastName).replaceFirst("$1, $2 "); if (lastName.contains(",")) { String[] parts = suffixFix(lastName); if (parts != null && "per".equals(parts[0])) { lastName = parts[1]; entityName = new NamePerson(firstName, lastName); entityName.setSuffix(parts[2]); } else if (parts != null && "org".equals(parts[0])) { lastName = parts[1]; entityName = new NameOrg(fullName); entityName.setSuffix(parts[2]); } else if (parts != null && "per-syn".endsWith(parts[0])) { lastName = parts[1]; String suffix = parts[2]; String synonym = parts[3]; if (synonym.contains(firstName)) { synonym = synonym.replace(firstName, ""); } entityName = new NamePerson(firstName, lastName); entityName.setSuffix(suffix); entityName.addSynonym(synonym + ", " + firstName); entityName.addSynonym(synonym + ", " + firstName.subSequence(0, 1) + "."); } else { entityName = new NameOrg(fullName); } } else { entityName = new NamePerson(firstName, lastName); } } else { entityName = new NameOrg(fullName); } return entityName; } NameNode(Node itemNode); @Override Name read(); Name createName(String fullName); boolean isOrgName(String name); static final Set<String> PERSON_SUFFIXES; static final Set<String> PERSON_LONG_SUFFIXES; static final Set<String> COMPANY_SUFFIXES; static final Set<String> PERSON_FORMERLY; static final Set<String> PER_SUFFIX_STARTS; }