private function HumanNameParser_Parser::parse in Bibliography Module 6.2
Same name and namespace in other branches
- 7 includes/Parser.php \HumanNameParser_Parser::parse()
1 call to HumanNameParser_Parser::parse()
- HumanNameParser_Parser::setName in includes/Parser.php
- Sets name string and parses it.
Takes Name object or a simple string (converts the string into a Name obj),
parses and loads its constituant parts.
File
- includes/Parser.php, line 168
Class
- HumanNameParser_Parser
- Works with a Name object to parse out the parts of a name.
Code
private function parse() {
$suffixes = implode("\\.*|\\s", $this->suffixes) . "\\.*";
$prefixes = implode(" |", $this->prefixes) . " ";
$nicknamesRegex = "/ ('|\"|\\(\"*'*)(.+?)('|\"|\"*'*\\)) /";
$suffixRegex = "/,* *({$suffixes})\$/";
$lastRegex = "/(?!^)\\b([^ ]+ y |{$prefixes})*[^ ]+\$/u";
$leadingInitRegex = "/^(.\\.*)(?= \\p{L}{2})/";
$firstRegex = "/^[^ ]+/";
$this->nicknames = $this->name
->chopWithRegex($nicknamesRegex, 2);
$this->suffix = $this->name
->chopWithRegex($suffixRegex, 1);
$this->name
->flip(",");
$this->last = $this->name
->chopWithRegex($lastRegex, 0);
if (!$this->last) {
throw new Exception("Couldn't find a last name in '{$this->name->getStr()}'.");
}
$this->leadingInit = $this->name
->chopWithRegex($leadingInitRegex, 1);
$this->first = $this->name
->chopWithRegex($firstRegex, 0);
if (!$this->first && $this->category != 5) {
throw new Exception("Couldn't find a first name in '{$this->name->getStr()}'");
}
$this->middle = $this->name
->getStr();
return true;
}