You are here

public function ContributorNames::analyze in Bibliography Module 7.2

Analyze a string

Parameters

string $string:

return ContributorObject|boolean: false if not parsed

Overrides AnalyzerInterface::analyze

File

lib/msrc-authortool/src/Analyzer/ContributorNames.php, line 75

Class

ContributorNames
Match Contributor Names with Predefined Regex

Namespace

Analyzer

Code

public function analyze($string) {

  //String Trim
  $string = trim($string);

  //Some names have HTML escape codes
  $string = str_replace(''', "'", $string);
  $string = str_replace('Ö', 'Ö', $string);

  //If it's [anon], ignore it
  if (strcasecmp("[anon]", $string) == 0) {
    return false;
  }

  //If it contains organization keywords, it is an organization
  if ($this
    ->checkIsOrganization($string)) {
    $co = new ContributorObject();
    $co->organization = $string;
    return $co;
  }

  //Everything < 6 char w/no spaces and alphanum is organization
  if (strlen($string) < 6 && preg_match("/^[a-z0-9]+\$/i", $string)) {
    $co = new ContributorObject();
    $co->organization = $string;
    return $co;
  }
  elseif (strlen($string) < 6 && !preg_match("/[ +?]/", $string)) {
    return false;
  }

  //Before running the main regex patterns, see if there is a known lastName prefix,

  //and rip that out
  list($lnPrefix, $string) = $this
    ->checkAndSetLastNamePrefix($string);

  //Everything else we'll try to parse using the Nametools
  $object = $this->normalizer
    ->normalize($string);

  //Clean it up
  if ($object) {
    $object->lastNamePrefix = $lnPrefix;
    $object = $this
      ->cleanUp($object);
  }

  //Return it
  return $object;
}