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