]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/Phrase.php
only instantiate indexer once for replication
[nominatim.git] / lib-php / Phrase.php
1 <?php
2
3 namespace Nominatim;
4
5 /**
6  * Segment of a query string.
7  *
8  * The parts of a query strings are usually separated by commas.
9  */
10 class Phrase
11 {
12     // Complete phrase as a string (guaranteed to have no leading or trailing
13     // spaces).
14     private $sPhrase;
15     // Element type for structured searches.
16     private $sPhraseType;
17     // Possible segmentations of the phrase.
18     private $aWordSets;
19
20     public function __construct($sPhrase, $sPhraseType)
21     {
22         $this->sPhrase = trim($sPhrase);
23         $this->sPhraseType = $sPhraseType;
24     }
25
26     /**
27      * Get the orginal phrase of the string.
28      */
29     public function getPhrase()
30     {
31         return $this->sPhrase;
32     }
33
34     /**
35      * Return the element type of the phrase.
36      *
37      * @return string Pharse type if the phrase comes from a structured query
38      *                or empty string otherwise.
39      */
40     public function getPhraseType()
41     {
42         return $this->sPhraseType;
43     }
44
45     public function setWordSets($aWordSets)
46     {
47         $this->aWordSets = $aWordSets;
48     }
49
50     /**
51      * Return the array of possible segmentations of the phrase.
52      *
53      * @return string[][] Array of segmentations, each consisting of an
54      *                    array of terms.
55      */
56     public function getWordSets()
57     {
58         return $this->aWordSets;
59     }
60
61     /**
62      * Invert the set of possible segmentations.
63      *
64      * @return void
65      */
66     public function invertWordSets()
67     {
68         foreach ($this->aWordSets as $i => $aSet) {
69             $this->aWordSets[$i] = array_reverse($aSet);
70         }
71     }
72
73     public function debugInfo()
74     {
75         return array(
76                 'Type' => $this->sPhraseType,
77                 'Phrase' => $this->sPhrase,
78                 'WordSets' => $this->aWordSets
79                );
80     }
81 }