X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/001b2aa9f9e3476d3b70a1a2a408ea4f0a7786fc..1147b83b22a073db2f81ea177f9caa12e727e249:/lib-php/tokenizer/legacy_icu_tokenizer.php diff --git a/lib-php/tokenizer/legacy_icu_tokenizer.php b/lib-php/tokenizer/legacy_icu_tokenizer.php index ef79769c..ca224a22 100644 --- a/lib-php/tokenizer/legacy_icu_tokenizer.php +++ b/lib-php/tokenizer/legacy_icu_tokenizer.php @@ -2,13 +2,14 @@ namespace Nominatim; +require_once(CONST_LibDir.'/SimpleWordList.php'); + class Tokenizer { private $oDB; private $oNormalizer; private $oTransliterator; - private $aCountryRestriction; public function __construct(&$oDB) { @@ -19,23 +20,17 @@ class Tokenizer public function checkStatus() { - $sSQL = 'SELECT word_id FROM word limit 1'; + $sSQL = 'SELECT word_id FROM word WHERE word_id is not null limit 1'; $iWordID = $this->oDB->getOne($sSQL); if ($iWordID === false) { - throw new Exception('Query failed', 703); + throw new \Exception('Query failed', 703); } if (!$iWordID) { - throw new Exception('No value', 704); + throw new \Exception('No value', 704); } } - public function setCountryRestriction($aCountries) - { - $this->aCountryRestriction = $aCountries; - } - - public function normalizeString($sTerm) { if ($this->oNormalizer === null) { @@ -88,13 +83,10 @@ class Tokenizer $sNormQuery .= ','.$this->normalizeString($oPhrase->getPhrase()); $sPhrase = $this->makeStandardWord($oPhrase->getPhrase()); Debug::printVar('Phrase', $sPhrase); - if (strlen($sPhrase) > 0) { - $aWords = explode(' ', $sPhrase); - Tokenizer::addTokens($aTokens, $aWords); - $aWordLists[] = $aWords; - } else { - $aWordLists[] = array(); - } + + $oWordList = new SimpleWordList($sPhrase); + $aTokens = array_merge($aTokens, $oWordList->getTokens()); + $aWordLists[] = $oWordList; } Debug::printVar('Tokens', $aTokens); @@ -103,7 +95,7 @@ class Tokenizer $oValidTokens = $this->computeValidTokens($aTokens, $sNormQuery); foreach ($aPhrases as $iPhrase => $oPhrase) { - $oPhrase->computeWordSets($aWordLists[$iPhrase], $oValidTokens); + $oPhrase->setWordSets($aWordLists[$iPhrase]->getWordSets($oValidTokens)); } return $oValidTokens; @@ -162,10 +154,7 @@ class Tokenizer switch ($aWord['type']) { case 'C': // country name tokens - if ($aWord['word'] !== null - && (!$this->aCountryRestriction - || in_array($aWord['word'], $this->aCountryRestriction)) - ) { + if ($aWord['word'] !== null) { $oValidTokens->addToken( $sTok, new Token\Country($iId, $aWord['word']) @@ -220,27 +209,4 @@ class Tokenizer } } } - - - /** - * Add the tokens from this phrase to the given list of tokens. - * - * @param string[] $aTokens List of tokens to append. - * - * @return void - */ - private static function addTokens(&$aTokens, $aWords) - { - $iNumWords = count($aWords); - - for ($i = 0; $i < $iNumWords; $i++) { - $sPhrase = $aWords[$i]; - $aTokens[$sPhrase] = $sPhrase; - - for ($j = $i + 1; $j < $iNumWords; $j++) { - $sPhrase .= ' '.$aWords[$j]; - $aTokens[$sPhrase] = $sPhrase; - } - } - } }