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; }
@Test public void person_aka() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Cory, a/k/a Cynthia S. Timmerman, executrix; by Cynthia S."); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Cynthia S.", ((NamePerson) name).getFirstName()); assertEquals("Cory", ((NamePerson) name).getLastName()); assertEquals("a/k/a Cynthia S. Timmerman, executrix", name.getSuffix()); assertEquals("Timmerman, Cynthia S.", ((NamePerson) name).getLongestSynonym().trim()); }
@Test public void person_aka_2() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Kurz-Beerli, also known as Elisabeth H. Kurz; by Elizabeth"); assertFalse(name == null); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Elizabeth", ((NamePerson) name).getFirstName()); assertEquals("Kurz-Beerli", ((NamePerson) name).getLastName()); }
@Test public void person_aka_3() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Kurz-Beerli, executrix, also known as Elisabeth H. Kurz; by Elizabeth"); assertFalse(name == null); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Elizabeth", ((NamePerson) name).getFirstName()); assertEquals("Kurz-Beerli", ((NamePerson) name).getLastName()); }
@Test public void person_bySaid() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Schutz, by said Murdoch N. McIntosh; Juris E."); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Juris E.", ((NamePerson) name).getFirstName()); assertEquals("Schutz", ((NamePerson) name).getLastName()); assertEquals("by said Murdoch N. McIntosh", name.getSuffix()); }
@Test public void person_multicomma() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Crisafulli, Jr., executor; by Joseph"); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Jr., executor", name.getSuffix()); }
@Test public void person_deceased() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Gee, Sr., deceased; Samuel"); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Sr.", name.getSuffix()); }
@Test public void semicolon_andsign_person() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser .createName("Fletcher; James C. Administrator of the National Aeronautics & Space Administration"); assertTrue("expect NamePerson", name instanceof NamePerson); }
@Test public void suffixFix_org() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Flint Steel, LLC"); assertTrue("expect NameOrg", name instanceof NameOrg); }
@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()); }
@Test public void suffixFix_per_org() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Flint, LLC; Steel"); assertTrue("expect NameOrg", name instanceof NameOrg); }
@Test public void suffixFix_nee() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Flintstone, nee Dinotopia; Betty"); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Betty", ((NamePerson) name).getFirstName()); assertEquals("Flintstone", ((NamePerson) name).getLastName()); assertEquals("Flintstone, Betty, nee Dinotopia", ((NamePerson) name).getName()); assertEquals("Flintstone, B.", ((NamePerson) name).getAbbreviatedName()); assertEquals("Dinotopia, B.", ((NamePerson) name).getShortestSynonym()); assertEquals("Dinotopia, Betty", ((NamePerson) name).getLongestSynonym()); assertEquals("nee Dinotopia", name.getSuffix()); }
@Test public void suffixFix_nee_2() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Flintstone nee Dinotopia, legal guardian; Betty"); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Betty", ((NamePerson) name).getFirstName()); assertEquals("Flintstone", ((NamePerson) name).getLastName()); assertEquals("nee Dinotopia, legal guardian", name.getSuffix()); }
@Test public void suffixFix_born() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Flintstone born Dinotopia, legal representative; Betty"); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Betty", ((NamePerson) name).getFirstName()); assertEquals("Flintstone", ((NamePerson) name).getLastName()); assertEquals("born Dinotopia, legal representative", name.getSuffix()); }
@Test public void suffixFix_changeOfName() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Doe, now by change of name Jane Doe Smith; Jane"); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Jane", ((NamePerson) name).getFirstName()); assertEquals("Doe", ((NamePerson) name).getLastName()); assertEquals("Doe Smith, Jane", ((NamePerson) name).getLongestSynonym().trim()); assertEquals("Doe Smith, J.", ((NamePerson) name).getShortestSynonym().trim()); assertEquals("Doe, J.", ((NamePerson) name).getAbbreviatedName()); assertEquals("JD", ((NamePerson) name).getInitials()); }
@Test public void company_semicolon_final_comma() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Schecter; Manny W. Felsman, Bradley, Vaden, Gunter & Dillon, LLP"); assertTrue("expect NameOrg", name instanceof NameOrg); assertEquals("Schecter; Manny W. Felsman, Bradley, Vaden, Gunter & Dillon, LLP", ((NameOrg) name).getName()); }
@Test public void company_semicolon() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("AT&T Information Systems Inc; AT&T Bell Laboratories"); assertFalse(name == null); assertTrue("expect NameOrg", name instanceof NameOrg); assertEquals("AT&T Information Systems Inc; AT&T Bell Laboratories", ((NameOrg) name).getName()); }
@Test public void company_semicolon_final_word() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Bongini; Stephen Fleit, Kahn, Gibbons, Gutman & Bongini P.L."); assertTrue("expect NameOrg", name instanceof NameOrg); assertEquals("Bongini; Stephen Fleit, Kahn, Gibbons, Gutman & Bongini P.L.", ((NameOrg) name).getName()); }
@Test public void company_semicolon_final_words() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Christine; Christine, Roberts and Cushman, Intellectual Property Practice Group"); assertTrue("expect NameOrg", name instanceof NameOrg); assertEquals("Christine; Christine, Roberts and Cushman, Intellectual Property Practice Group", ((NameOrg) name).getName()); }
@Test public void long_suffix() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Hayashi, President, University of Tokyo; Kentaro"); assertFalse(name == null); assertTrue("expect NamePerson", name instanceof NamePerson); assertEquals("Kentaro",((NamePerson) name).getFirstName()); assertEquals("Hayashi",((NamePerson) name).getLastName()); assertEquals("Hayashi, Kentaro, President, University of Tokyo",((NamePerson) name).getName()); }
@Test public void name_space_company() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Eugene M. The Law Offices of Eugene M. Lee P.L.L.C."); assertFalse(name == null); assertTrue("expect NameOrg", name instanceof NameOrg); assertEquals("Eugene M. The Law Offices of Eugene M. Lee P.L.L.C.",((NameOrg) name).getName()); }
@Test public void company_prof_corp() throws InvalidDataException { NameNode parser = new NameNode(null); Name name = parser.createName("Schatzel; Thomas E. Law Offices of Thomas E. Schatzel, A Prof. Corp."); assertFalse(name == null); assertTrue("expect NameOrg", name instanceof NameOrg); assertEquals("Schatzel; Thomas E. Law Offices of Thomas E. Schatzel, A Prof. Corp.",((NameOrg) name).getName()); }