.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Lingua::EN::NameParse 3pm" .TH Lingua::EN::NameParse 3pm "2013-11-11" "perl v5.18.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Lingua::EN::NameParse \- routines for manipulating a person's name .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Lingua::EN::NameParse qw(clean case_surname); \& \& # optional configuration arguments \& my %args = \& ( \& auto_clean => 1, \& force_case => 1, \& lc_prefix => 1, \& initials => 3, \& allow_reversed => 1, \& joint_names => 0, \& extended_titles => 0 \& ); \& \& my $name = new Lingua::EN::NameParse(%args); \& \& $error = $name\->parse("MR AC DE SILVA"); \& if ( $error ) \& { \& $bad_input = $my_properties{non_matching}; \& } \& else \& { \& %name_comps = $name\->components; \& $surname = $name_comps{surname_1}; # DE SILVA \& \& %name_comps = $name\->case_components; \& $surname = $name_comps{surname_1}; # De Silva \& \& $correct_casing = $name\->case_all; # Mr AC de Silva \& \& $correct_casing = $name\->case_all_reversed ; # de Silva, AC \& \& $good_name = clean("Bad Na9me "); # "Bad Name" \& \& $salutation = $name\->salutation(salutation => \*(AqDear\*(Aq,sal_default => \*(AqFriend\*(Aq)); # Dear Mr de Silva \& \& %my_properties = $name\->properties; \& $number_surnames = $my_properties{number}; # 1 \& } \& \& $name\->report; # create a report listing all information about the parsed name \& \& $lc_prefix = 0; \& $correct_case = case_surname("DE SILVA\-MACNAY",$lc_prefix); # De Silva\-MacNay .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module takes as input a person or persons name in free format text such as, .PP .Vb 3 \& Mr AB & M/s CD MacNay\-Smith \& MR J.L. D\*(AqANGELO \& Estate Of The Late Lieutenant Colonel AB Van Der Heiden .Ve .PP and attempts to parse it. If successful, the name is broken down into components and useful functions can be performed such as : .PP .Vb 4 \& converting upper or lower case values to name case (Mr AB MacNay ) \& creating a personalised greeting or salutation (Dear Mr MacNay ) \& extracting the names individual components (Mr,AB,MacNay ) \& determining the type of format the name is in (Mr_A_Smith ) .Ve .PP If the name cannot be parsed you have the option of cleaning the name of bad characters, or extracting any portion that was parsed and the portion that failed. .PP This module can be used for analysing and improving the quality of lists of names. .SH "DEFINITIONS" .IX Header "DEFINITIONS" The following terms are used by NameParse to define the components that can make up a name. .PP .Vb 6 \& Precursor \- Estate of (The Late), Right Honourable ... \& Title \- Mr, Mrs, Ms., Sir, Dr, Major, Reverend ... \& Conjunction \- word to separate names or initials, such as "And" \& Initials \- 1\-3 letters, each with an optional space and/or dot \& Surname \- De Silva, Van Der Heiden, MacNay\-Smith, O\*(AqReilly ... \& Suffix \- Snr., Jnr, III, V ... .Ve .PP Refer to the component grammar defined within the code for a complete list of combinations. .PP \&'Name casing' refers to the correct use of upper and lower case letters in peoples names, such as Mr \s-1AB\s0 McNay. .PP To describe the formats supported by NameParse, a short hand representation of the name is used. The following formats are currently supported : .PP .Vb 9 \& Mr_John_Smith_&Ms_Mary_Jones \& Mr_A_Smith_&Ms_B_Jones \& Mr_&Ms_A_&B_Smith \& Mr_A_&Ms_B_Smith \& Mr_&Ms_A_Smith \& Mr_A_&B_Smith \& John_Smith_&Mary_Jones \& John_&Mary_Smith \& A_Smith_&B_Jones \& \& Mr_John_Adam_Smith \& Mr_John_A_Smith \& Mr_J_Adam_Smith \& Mr_John_Smith \& Mr_A_Smith \& John_Adam_Smith \& John_A_Smith \& J_Adam_Smith \& John_Smith \& A_Smith \& John .Ve .PP Precursors and suffixes may be applied to single names that include a surname .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" The \f(CW\*(C`new\*(C'\fR method creates an instance of a name object and sets up the grammar used to parse names. This must be called before any of the following methods are invoked. Note that the object only needs to be created \s-1ONCE,\s0 and should be reused with new input data. Calling \f(CW\*(C`new\*(C'\fR repeatedly will significantly slow your program down. .PP Various setup options may be defined in a hash that is passed as an optional argument to the \f(CW\*(C`new\*(C'\fR method. Note that all the arguments are optional. You need to define the combination of arguments that are appropriate for your usage. .PP .Vb 8 \& my %args = \& ( \& auto_clean => 1, \& force_case => 1, \& lc_prefix => 1, \& initials => 3, \& allow_reversed => 1 \& ); \& \& \& my $name = new Lingua::EN::NameParse(%args); .Ve .IP "force_case" 4 .IX Item "force_case" This option will force the \f(CW\*(C`case_all\*(C'\fR method to name case the entire input string, including any unmatched sections that failed parsing. For example, in \&\*(L"\s-1MR A JONES & ASSOCIATES\*(R", \*(L"& ASSOCIATES\*(R"\s0 will also be name cased. The casing rules for unmatched sections are the same as for surnames. This is usually the best option, although any initials in the unmatched section will not be correctly cased. This option is useful when you know you data has invalid names, but you cannot filter out or reject them. .IP "auto_clean" 4 .IX Item "auto_clean" When this option is set to a positive value, any call to the \f(CW\*(C`parse\*(C'\fR method that fails will attempt to 'clean' the name and then reparse it. See the \&\f(CW\*(C`clean\*(C'\fR method for details. This is useful for dirty data with embedded unprintable or non alphabetic characters. .IP "lc_prefix" 4 .IX Item "lc_prefix" When this option is set to a positive value, it will force the \f(CW\*(C`case_all\*(C'\fR and \f(CW\*(C`case_component\*(C'\fR methods to lower case the first letter of each word that occurs in the prefix portion of a surname. For example, Mr \s-1AB\s0 de Silva, or Ms \s-1AS\s0 von der Heiden. .IP "initials" 4 .IX Item "initials" Allows the user to control the number of letters that can occur in the initials. Valid settings are 1,2 or 3. If no value is supplied a default of 2 is used. .IP "allow_reversed" 4 .IX Item "allow_reversed" When this option is set to a positive value, names in reverse order will be processed. The only valid format is the surname followed by a comma and the rest of the name, which can be in any of the combinations allowed by non reversed names. Some examples are: .Sp Smith, Mr \s-1AB\s0 Jones, Jim De Silva, Professor A.B. .Sp The program changes the order of the name back to the non reversed format, and then performs the normal parsing. Note that if the name can be parsed, the fact that it's order was originally reversed, is not recorded as a property of the name object. .IP "joint_names" 4 .IX Item "joint_names" When this option is set to a positive value, joint names are accounted for: .Sp Mr_A_Smith_&Ms_B_Jones Mr_&Ms_A_&B_Smith Mr_A_&Ms_B_Smith Mr_&Ms_A_Smith Mr_A_&B_Smith .Sp Note that if this option is not specified, than by default joint names are ignored. Disabling joint names speeds up the processing a lot. .IP "extended_titles" 4 .IX Item "extended_titles" When this option is set to a positive value, all combinations of titles, such as Colonel, Mother Superior are used. If this value is not set, only the following titles are accounted for: .Sp .Vb 8 \& Mr \& Ms \& M/s \& Mrs \& Miss \& Dr \& Sir \& Dame .Ve .Sp Note that if this option is not specified, than by default extended titles are ignored. Disabling extended titles speeds up the processing. .SS "parse" .IX Subsection "parse" .Vb 1 \& $error = $name\->parse("MR AC DE SILVA"); .Ve .PP The \f(CW\*(C`parse\*(C'\fR method takes a single parameter of a text string containing a name. It attempts to parse the name and break it down into the components .PP Returns an error flag, if the name was parsed successfully, it's value is 0, otherwise a 1. This step is a prerequisite for the following methods. .SS "case_all" .IX Subsection "case_all" .Vb 1 \& $correct_casing = $name\->case_all; .Ve .PP The \f(CW\*(C`case_all\*(C'\fR method converts the first letter of each component to capitals and the remainder to lower case, with the following exceptions\- .PP .Vb 3 \& initials remain capitalised \& surname spelling such as MacNay\-Smith, O\*(AqBrien and Van Der Heiden are preserved \& \- see C for user defined exceptions .Ve .PP A complete definition of the capitalising rules can be found by studying the component grammar defined within the code. .PP The method returns the entire cased name as text. .SS "case_all_reversed" .IX Subsection "case_all_reversed" .Vb 1 \& $correct_casing = $name\->case_all_reversed; .Ve .PP The \f(CW\*(C`case_all_reversed\*(C'\fR method applies the same type of casing as \&\f(CW\*(C`case_all\*(C'\fR. However, the name is returned as surname followed by a comma and the rest of the name, which can be any of the combinations allowed for a name, except the title. Some examples are: \*(L"Smith, John\*(R", \*(L"De Silva, A.B.\*(R" This is useful for sorting names alphabetically by surname. .PP The method returns the entire reverse order cased name as text. .SS "case_components" .IX Subsection "case_components" .Vb 2 \& %my_name = $name\->case_components; \& $cased_surname = $my_name{surname_1}; .Ve .PP The \f(CW\*(C`case_components\*(C'\fR method does the same thing as the \f(CW\*(C`case_all\*(C'\fR method, but returns the name cased components in a hash. The following keys are used for each component: .PP .Vb 10 \& precursor \& title_1 \& title_2 \& given_name_1 \& given_name_2 \& initials_1 \& initials_2 \& middle_name \& conjunction_1 \& conjunction_2 \& surname_1 \& surname_2 \& suffix .Ve .PP If a component has no matching data for a given name, it's values will be set to the empty string. .PP If the name could not be parsed, this method returns null. If you assign the return value to a hash, you should check the error status returned by the \f(CW\*(C`parse\*(C'\fR method first. Ohterwise, you will get an odd number of values addigned to the hash. .SS "components" .IX Subsection "components" .Vb 2 \& %name = $name\->components; \& $surname = $my_name{surname_1}; .Ve .PP The \f(CW\*(C`components\*(C'\fR method does the same thing as the \f(CW\*(C`case_components\*(C'\fR method, but each component is returned as it appears in the input string, with no case conversion. .SS "case_surname" .IX Subsection "case_surname" .Vb 1 \& $correct_casing = case_surname("DE SILVA\-MACNAY" [,$lc_prefix]); .Ve .PP \&\f(CW\*(C`case_surname\*(C'\fR is a stand alone function that does not require a name object. The input is a text string. An optional input argument controls the casing rules for prefix portions of a surname, as described above in the \&\f(CW\*(C`lc_prefix\*(C'\fR section. .PP The output is a string converted to the correct casing for surnames. See \f(CW\*(C`surname_prefs.txt\*(C'\fR for user defined exceptions .PP This function is useful when you know you are only dealing with names that do not have initials like \*(L"Mr John Jones\*(R". It is much faster than the case_all method, but does not understand context, and cannot detect errors on strings that are not personal names. .SS "surname_prefs.txt" .IX Subsection "surname_prefs.txt" Some surnames can have more than one form of valid capitalisation, such as MacQuarie or Macquarie. Where the user wants to specify one form as the default, a text file called surname_prefs.txt should be created and placed in the same location as the NameParse module. The text file should contain one surname per line, in the capitalised form you want, such as .PP .Vb 2 \& Macquarie \& MacHado .Ve .PP NameParse will still operate if the file does not exist .SS "salutation" .IX Subsection "salutation" .Vb 1 \& $salutation = $name\->salutation(salutation => \*(AqDear\*(Aq,sal_default => \*(AqFriend\*(Aq,sal_type => \*(Aqgiven_name\*(Aq)); .Ve .PP The \f(CW\*(C`salutation\*(C'\fR method converts a name into a personal greeting, such as \*(L"Dear Mr & Mrs O'Brien\*(R" or \*(L"Dear Sue and John\*(R" .PP Optional parameters may be specided in a hash as follows: .PP .Vb 1 \& salutation: \& \& The greeting word such as \*(AqDear\*(Aq or \*(AqGreetings\*(Aq. If not spefied than \*(AqDear\*(Aq is used \& \& sal_default: \& \& The default word used when a personalised salution cannot be generated. If not \& specified, than \*(AqFriend\*(Aq is used. \& \& sal_type: \& \& Can be either \*(Aqgiven_name\*(Aq such as \*(AqDear Sue\*(Aq or \*(Aqtitle_plus_name\*(Aq such as \*(AqDear Ms Smith\*(Aq \& If not specified, than \*(Aqgiven_name\*(Aq is used. .Ve .PP If an error is detected during parsing, such as with the name \*(L"\s-1AB\s0 Smith & Associates\*(R", then the value of sal_default is used instead of a given name, or a title and surname. If the input string contains a conjunction, an 's' is added to the value of sal_default. .PP If the name contains a precursor, a default salutation is produced. .SS "clean" .IX Subsection "clean" .Vb 1 \& $good_name = clean("Bad Na9me"); .Ve .PP \&\f(CW\*(C`clean\*(C'\fR is a stand alone function that does not require a name object. The input is a text string and the output is the string with: .PP .Vb 2 \& all repeating spaces removed \& all characters not in the set (A\-Z a\-z \- \*(Aq , . &) removed .Ve .SS "properties" .IX Subsection "properties" The \f(CW\*(C`properties\*(C'\fR method returns all the properties of the name, non_matching, number and type, as a hash. .IP "type" 4 .IX Item "type" The type of format a name is in, as one of the following strings: .Sp .Vb 10 \& Mr_A_Smith_&Ms_B_Jones \& Mr_&Ms_A_&B_Smith \& Mr_A_&Ms_B_Smith \& Mr_&Ms_A_Smith \& Mr_A_&B_Smith \& Mr_John_Adam_Smith \& Mr_John_A_Smith \& Mr_J_Adam_Smith \& Mr_John_Smith \& Mr_A_Smith \& John_Adam_Smith \& John_A_Smith \& J_Adam_Smith \& John_Smith \& A_Smith \& John \& unknown .Ve .IP "non_matching" 4 .IX Item "non_matching" Returns any unmatched section that was found. .SS "report" .IX Subsection "report" Create a formatted text report to standard output listing \&\- the input string, \&\- the name and value of each defined component \&\- any non matching component .SH "LIMITATIONS" .IX Header "LIMITATIONS" The huge number of character combinations that can form a valid names makes it is impossible to correctly identify them all. Firstly, there are many ambiguities, which have no right answer. .PP .Vb 4 \& Macbeth or MacBeth, are both valid spellings \& Is ED WOOD E.D. Wood or Edward Wood \& Is \*(AqMr Rapid Print\*(Aq a name or a company \& Does John Bradfield Smith have a middle name of Bradfield, or a surname of Bradfield\-Smith? .Ve .PP One approach is to have large lookup files of names and words, statistical rules and fuzzy logic to attempt to derive context. This approach gives high levels of accuracy but uses a lot of your computers time and resources. .PP NameParse takes the approach of using a limited set of rules, based on the formats that are commonly used by business to represent peoples names. This gives us fairly high accuracy, with acceptable speed and program size. .PP NameParse will accept names from many countries, like Van Der Heiden, De La Mare and Le Fontain. Having said that, it is still biased toward English, because the precursors, titles and conjunctions are based on English usage. .PP Names with two or more words, but no separating hyphen are not recognized. This is a real quandary as Indian, Chinese and other names can have several components. If these are allowed for, any component after the surname will also be picked up. For example in \*(L"Mr \s-1AB\s0 Jones Trading As Jones Pty Ltd\*(R" will return a surname of \*(L"Jones Trading\*(R". .PP Because of the large combination of possible names defined in the grammar, the program is not very fast, except for the more limited \f(CW\*(C`case_surname\*(C'\fR subroutine. See the \*(L"Future Directions\*(R" section for possible speed ups. .PP As the parser has a very limited understanding of context, the \*(L"John_Adam_Smith\*(R" name type is most likely to cause problems, as it contains no known tokens like a title. A string such as \*(L"National Australia Bank\*(R" would be accepted as a valid name, first name National etc. Supplying a list of common pronouns as exceptions could solve this problem. .SH "REFERENCES" .IX Header "REFERENCES" \&\*(L"The Wordsworth Dictionary of Abbreviations & Acronyms\*(R" (1997) .PP Australian Standard \s-1AS4212\-1994 \s0\*(L"Geographic Information Systems \- Data Dictionary for transfer of street addressing information\*(R" .SH "FUTURE DIRECTIONS" .IX Header "FUTURE DIRECTIONS" .Vb 4 \& Add filtering of very long names \& Add diagnostic messages explaining why parsing failed \& Add transforming methods to do things like remove dots from initials \& Try to derive gender (Mr... is male, Ms, Mrs... is female) .Ve .PP Define grammar for other languages. Hopefully, all that would be needed is to specify a new module with its own grammar, and inherit all the existing methods. I don't have the knowledge of the naming conventions for non-english languages. .SH "SEE ALSO" .IX Header "SEE ALSO" Lingua::EN::AddressParse, Lingua::EN::MatchNames, Lingua::EN::NickNames, Lingua::EN::NameCase, Parse::RecDescent .SH "TO DO" .IX Header "TO DO" .SH "BUGS" .IX Header "BUGS" The dot in a suffix of Jnr. or Snr. will be consumed as unmatched text, and not be retained with the suffix. .PP Names with accented characters (acute, circumfelx etc) will not be parsed correctly. A work around is to replace the character class [a\-z] with \ew in the appropriate rules in the grammar tree, but this could lower the accuracy of names based purely on \s-1ASCII\s0 text. .SH "CREDITS" .IX Header "CREDITS" Thanks to all the people who provided ideas and suggestions, including \- .PP .Vb 5 \& QM Industries \& Damian Conway, author of Parse::RecDescent \& Mark Summerfield author of Lingua::EN::NameCase, \& Ron Savage, Alastair Adam Huffman, Douglas Wilson \& Peter Schendzielorz .Ve .SH "AUTHOR" .IX Header "AUTHOR" NameParse was written by Kim Ryan .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (c) 2013 Kim Ryan. All rights reserved. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "case_all_reversed" .IX Header "case_all_reversed" Apply correct capitalisation to a person's entire name and reverse the order so that surname is first, followed by the other components, such as: Smith, Mr John A Useful for creating a list of names that can be sorted by surname. .PP If name type is unknown , returns null .PP If the name type has a joint name, such as 'Mr_A_Smith_Ms_B_Jones', return null, as it is ambiguous which surname to place at the start of the string .PP Else, returns a string of all cased components in correct reversed order