PersonStringNlm30NameSchemaFilter::_parsePersonsString PHP Method

_parsePersonsString() public method

Converts a string with multiple persons to an array of NLM name descriptions.
public _parsePersonsString ( $personsString, $title, $degrees ) : array
$personsString string
$title boolean true to parse for title
$degrees boolean true to parse for degrees
return array an array of NLM name descriptions or null if the string could not be converted plus optionally a single 'et-al' string.
    function &_parsePersonsString($personsString, $title, $degrees)
    {
        // Check for 'et al'.
        $personsStringBeforeEtal = PKPString::strlen($personsString);
        $personsString = PKPString::regexp_replace('/et ?al$/', '', $personsString);
        $etAl = $personsStringBeforeEtal == PKPString::strlen($personsString) ? false : true;
        // Remove punctuation.
        $personsString = trim($personsString, ':;, ');
        // Cut the authors string into pieces.
        $personStrings = PKPString::iterativeExplode(array(':', ';'), $personsString);
        // If we did not have success with simple patterns then try more complex
        // patterns to tokenize multiple-person strings.
        if (count($personStrings) == 1) {
            // The first pattern must match the whole string, the second is used
            // to extract names.
            $complexPersonsPatterns = array(array('/^((([^ \\t\\n\\r\\f\\v,.&]{2,}\\s*)+,\\s*([A-Z]\\.\\s*)+),\\s*)+(\\&|\\.\\s\\.\\s\\.)\\s*([^ \\t\\n\\r\\f\\v,.&]{2,}\\s*,\\s*([A-Z]\\.\\s*)+)$/i', '/(?:[^ \\t\\n\\r\\f\\v,.&]{2,}\\s*)+,\\s*(?:[A-Z]\\.\\s*)+/i'), array('/^((([^ \\t\\n\\r\\f\\v,&]+\\s+)+[^ \\t\\n\\r\\f\\v,&]+\\s*)[,&]\\s*)+(([^ \\t\\n\\r\\f\\v,&]+\\s+)+[^ \\t\\n\\r\\f\\v,&]+)/i', '/(?:(?:[^ \\t\\n\\r\\f\\v,&.]+|[^ \\t\\n\\r\\f\\v,&]{2,})\\s+)+(?:[^ \\t\\n\\r\\f\\v,&.]+|[^ \\t\\n\\r\\f\\v,&]{2,})/i'));
            $matched = false;
            foreach ($complexPersonsPatterns as $complexPersonsPattern) {
                // Break at the first pattern that matches.
                if ($matched = PKPString::regexp_match($complexPersonsPattern[0], $personsString)) {
                    // Retrieve names.
                    $success = PKPString::regexp_match_all($complexPersonsPattern[1], $personsString, $personStrings);
                    assert((bool) $success && count($personStrings) == 1);
                    $personStrings = $personStrings[0];
                    break;
                }
            }
            if (!$matched) {
                // If nothing matches then try to parse as a single person.
                $personStrings = array($personsString);
            }
        }
        // Parse persons.
        $persons = array();
        foreach ($personStrings as $personString) {
            $persons[] =& $this->_parsePersonString($personString, $title, $degrees);
        }
        // Add et-al string.
        if ($etAl) {
            $persons[] = PERSON_STRING_FILTER_ETAL;
        }
        return $persons;
    }