/** * Try to disambiguate the ambiguous values. If not possible, pass the values to the successor and try to * disambiguate with the successor. If possible, store ambiguous and disambiguated values. */ public function disambiguate() { Container::getContext()->removeDisambiguationOptions('Geissler\\CSL\\Names\\Name'); $this->tmpDisambiguate = $this->getDisambiguate(); $this->tmpAmbiguous = $this->getAmbiguous(); $firstDifferent = false; // disambiguate years and missing years $this->regExp = '/([0-9]{2,4}'; if (Container::getLocale()->getTerms('do date', 'short') !== null) { $this->regExp .= '|' . Container::getLocale()->getTerms('do date', 'short'); } elseif (Container::getLocale()->getTerms('do date', 'short') !== null) { $this->regExp .= '|' . Container::getLocale()->getTerms('do date'); } $this->regExp .= ')/'; // disambiguate only where names and year are identical foreach ($this->tmpAmbiguous as $id => $name) { if (preg_match($this->regExp, $name) == 0) { $citation = Container::getRendered()->getFirstById($id); if (preg_match($this->regExp, $citation) == 1 && preg_match('/^' . preg_quote($this->tmpAmbiguous[$id], '/') . '/', $citation) == 1) { $this->tmpAmbiguous[$id] = $citation; } } } $ambiguous = ArrayData::ambiguous($this->tmpAmbiguous); if (count($ambiguous) > 0) { $this->tmpAmbiguous = $ambiguous; $this->addYearSuffix(); } elseif ($firstDifferent == true) { // test if second citation is ambiguous $this->tmpAmbiguous = $this->getAmbiguous(); $this->addYearSuffix(); } elseif (is_array($this->tmpDisambiguate) == true) { $this->tmpDisambiguate = array_merge($this->tmpDisambiguate, $this->getAmbiguous()); } else { $this->tmpDisambiguate = $this->getAmbiguous(); } if (count($ambiguous) > 0) { // store already disambiguated values $succeedAmbiguous = array(); if ($this->getAmbiguous() == $ambiguous) { $succeedAmbiguous = $ambiguous; } $this->succeed($this->getDisambiguate(), $succeedAmbiguous); } }
/** * Disambiguate citations if citation-label is used but no name. * * @param array $citations */ private function disambiguateByCitationLabel($citations) { $ambiguous = ArrayData::ambiguous($citations); new Chain($ambiguous); }
/** * Add by et-al suppressed names to disambiguate the cites. * * @param array $ambiguous * @return array */ private function addNames($ambiguous) { $last = ''; $original = $this->renderNames($ambiguous); $highestEtAl = $this->etAl; $names = array(); do { $this->etAl++; Container::getContext()->setDisambiguationOptions('Geissler\\CSL\\Names\\Name', array('etAlUseFirst' => $this->etAl)); $values = $this->renderNames($ambiguous); // keep disambiguate values $keep = ArrayData::disambiguate($values); foreach ($keep as $id => $newValue) { $this->tmpDisambiguate[$id] = str_replace($original[$id], $newValue, $this->tmpAmbiguous[$id]); unset($this->tmpAmbiguous[$id]); $highestEtAl = $this->etAl; $names[$id] = $newValue; } $ambiguous = ArrayData::ambiguous($values); if ($last == implode('', $ambiguous)) { break; } else { $last = implode('', $ambiguous); } } while (1 == 1); return array('etAl' => $highestEtAl, 'ambiguous' => $ambiguous, 'names' => $names); }