Nominatim/lib-php/Phrase.php

90 lines
2.0 KiB
PHP
Raw Normal View History

2017-10-12 23:37:44 +03:00
<?php
2022-01-03 18:23:58 +03:00
/**
* SPDX-License-Identifier: GPL-2.0-only
*
* This file is part of Nominatim. (https://nominatim.org)
*
* Copyright (C) 2022 by the Nominatim developer community.
* For a full list of authors see the git log.
*/
2017-10-12 23:37:44 +03:00
namespace Nominatim;
/**
* Segment of a query string.
*
* The parts of a query strings are usually separated by commas.
*/
class Phrase
{
// Complete phrase as a string (guaranteed to have no leading or trailing
// spaces).
2017-10-12 23:37:44 +03:00
private $sPhrase;
// Element type for structured searches.
private $sPhraseType;
// Possible segmentations of the phrase.
private $aWordSets;
public function __construct($sPhrase, $sPhraseType)
{
$this->sPhrase = trim($sPhrase);
$this->sPhraseType = $sPhraseType;
}
/**
2022-07-20 17:05:25 +03:00
* Get the original phrase of the string.
*/
public function getPhrase()
{
return $this->sPhrase;
2017-10-12 23:37:44 +03:00
}
2017-10-13 22:23:45 +03:00
/**
* Return the element type of the phrase.
*
* @return string Pharse type if the phrase comes from a structured query
* or empty string otherwise.
*/
2017-10-12 23:37:44 +03:00
public function getPhraseType()
{
return $this->sPhraseType;
}
public function setWordSets($aWordSets)
{
$this->aWordSets = $aWordSets;
}
2017-10-13 22:23:45 +03:00
/**
* Return the array of possible segmentations of the phrase.
*
* @return string[][] Array of segmentations, each consisting of an
* array of terms.
*/
2017-10-12 23:37:44 +03:00
public function getWordSets()
{
return $this->aWordSets;
}
2017-10-13 22:23:45 +03:00
/**
* Invert the set of possible segmentations.
*
* @return void
*/
2017-10-12 23:37:44 +03:00
public function invertWordSets()
{
foreach ($this->aWordSets as $i => $aSet) {
$this->aWordSets[$i] = array_reverse($aSet);
}
2017-10-12 23:37:44 +03:00
}
public function debugInfo()
{
return array(
'Type' => $this->sPhraseType,
'Phrase' => $this->sPhrase,
'WordSets' => $this->aWordSets
);
}
2017-10-14 00:11:09 +03:00
}