PHP Класс FullNameParser

Author: Josh Fraser Contribution from Clive Verrall www.cliveverrall.com February 2016 other contributions: - eric willis list of honorifics - TomThak for raising issue #16 and providing wikepedia resource - atla5 for closing the issue.
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$dict - Common honorific prefixes (english) - Common compound surname identifiers - Common suffixes (lineage and professional) Note: longer professional titles should appear earlier in the array than shorter titles to reduce the risk of mis-identification e.g. BEng before BE Also note that case and periods are part of the matching for professional titles and therefore need to be correct, there are no case conversions
$not_nicknames

Открытые методы

Метод Описание
break_words ( string $name ) : array Breaks name into individual words
fix_case ( $word ) # ucfirst all upper/lower strings, but leave camelcase words alone
get_pro_suffix ( string $name ) : mixed Checks for the existence of, and returns professional suffix
parse ( string $name ) : array Parse Static entry point.
parse_name ( $full_name ) : array This is the primary method which calls all other methods
safe_ucfirst ( $seperator, $word ) # helper public function for fix_case

Защищенные методы

Метод Описание
get_nickname ( string $name ) : mixed Function to check name for existence of nickname based on these stipulations - String wrapped in parentheses (string) - String wrapped in double quotes "string" x String wrapped in single quotes 'string'
is_camel_case ( string $word ) : boolean Checks for camelCase words such as McDonald and MacElroy
is_compound ( string $word ) : boolean Checks our dictionary of compound indicators to see if last name is compound
is_initial ( string $word ) : boolean Test string to see if it's a single letter/initial (period optional)
is_line_suffix ( string $word, string $name ) : mixed Checks word against array of common lineage suffixes
is_salutation ( string $word ) : boolean Checks word against list of common honorific prefixes

Описание методов

break_words() публичный Метод

Breaks name into individual words
public break_words ( string $name ) : array
$name string the full name you wish to parse
Результат array full list of words broken down by spaces

fix_case() публичный Метод

# ucfirst all upper/lower strings, but leave camelcase words alone
public fix_case ( $word )

get_nickname() защищенный Метод

I removed the check for strings in single quotes 'string' due to possible conflicts with names that may include apostrophes. Arabic transliterations, for example
protected get_nickname ( string $name ) : mixed
$name string the name you wish to test against
Результат mixed returns nickname if exists, false otherwise

get_pro_suffix() публичный Метод

Checks for the existence of, and returns professional suffix
public get_pro_suffix ( string $name ) : mixed
$name string the name you wish to test
Результат mixed returns the suffix if exists, false otherwise

is_camel_case() защищенный Метод

Checks for camelCase words such as McDonald and MacElroy
protected is_camel_case ( string $word ) : boolean
$word string the single word you wish to test
Результат boolean

is_compound() защищенный Метод

Checks our dictionary of compound indicators to see if last name is compound
protected is_compound ( string $word ) : boolean
$word string the single word you wish to test
Результат boolean

is_initial() защищенный Метод

Test string to see if it's a single letter/initial (period optional)
protected is_initial ( string $word ) : boolean
$word string the single word you wish to test
Результат boolean

is_line_suffix() защищенный Метод

Checks word against array of common lineage suffixes
protected is_line_suffix ( string $word, string $name ) : mixed
$word string the single word you wish to test
$name string full name for context in determining edge-cases
Результат mixed boolean if false, string if true (returns suffix)

is_salutation() защищенный Метод

Checks word against list of common honorific prefixes
protected is_salutation ( string $word ) : boolean
$word string the single word you wish to test
Результат boolean

parse() публичный статический Метод

Parse Static entry point.
public static parse ( string $name ) : array
$name string the full name you wish to parse
Результат array returns associative array of name parts

parse_name() публичный Метод

This is the primary method which calls all other methods
public parse_name ( $full_name ) : array
Результат array returns associative array of name parts

safe_ucfirst() публичный Метод

# helper public function for fix_case
public safe_ucfirst ( $seperator, $word )

Описание свойств

$dict защищенное свойство

- Common honorific prefixes (english) - Common compound surname identifiers - Common suffixes (lineage and professional) Note: longer professional titles should appear earlier in the array than shorter titles to reduce the risk of mis-identification e.g. BEng before BE Also note that case and periods are part of the matching for professional titles and therefore need to be correct, there are no case conversions
protected $dict

$not_nicknames защищенное свойство

protected $not_nicknames