]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/Phrase.php
php: make word list a first-class object
[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.
13     private $sPhrase;
14     // Element type for structured searches.
15     private $sPhraseType;
16     // Possible segmentations of the phrase.
17     private $aWordSets;
18
19     public function __construct($sPhrase, $sPhraseType)
20     {
21         $this->sPhrase = trim($sPhrase);
22         $this->sPhraseType = $sPhraseType;
23     }
24
25     /**
26      * Get the orginal phrase of the string.
27      */
28     public function getPhrase()
29     {
30         return $this->sPhrase;
31     }
32
33     /**
34      * Return the element type of the phrase.
35      *
36      * @return string Pharse type if the phrase comes from a structured query
37      *                or empty string otherwise.
38      */
39     public function getPhraseType()
40     {
41         return $this->sPhraseType;
42     }
43
44     public function setWordSets($aWordSets)
45     {
46         $this->aWordSets = $aWordSets;
47     }
48
49     /**
50      * Return the array of possible segmentations of the phrase.
51      *
52      * @return string[][] Array of segmentations, each consisting of an
53      *                    array of terms.
54      */
55     public function getWordSets()
56     {
57         return $this->aWordSets;
58     }
59
60     /**
61      * Invert the set of possible segmentations.
62      *
63      * @return void
64      */
65     public function invertWordSets()
66     {
67         foreach ($this->aWordSets as $i => $aSet) {
68             $this->aWordSets[$i] = array_reverse($aSet);
69         }
70     }
71
72     public function debugInfo()
73     {
74         return array(
75                 'Type' => $this->sPhraseType,
76                 'Phrase' => $this->sPhrase,
77                 'WordSets' => $this->aWordSets
78                );
79     }
80 }