function buildTrie($fileName)
{
    $playerData = json_decode(file_get_contents($fileName));
    $trie = new \Tries\RadixTrie();
    foreach ($playerData as $player) {
        $playerName = $player->surname . ', ' . $player->firstname;
        $trie->add(strtolower($playerName), $player);
    }
    return $trie;
}
Beispiel #2
0
function buildTries($fileName)
{
    echo 'Loading dictionary', PHP_EOL;
    $wordData = json_decode(file_get_contents($fileName));
    $trie = new \Tries\RadixTrie();
    $rtrie = new \Tries\RadixTrie();
    $wordCount = 0;
    foreach ($wordData as $word) {
        if ($wordCount > 0 && $wordCount % 1000 == 0) {
            echo '.';
        }
        if ($word > '') {
            $trie->add($word, $word);
            $rtrie->add(strrev($word), $word);
            ++$wordCount;
        }
    }
    echo PHP_EOL, "Added {$wordCount} words from dictionary", PHP_EOL;
    return array('trie' => $trie, 'rtrie' => $rtrie);
}