Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| OntologyIndex | |
0.00% |
0 / 26 |
|
0.00% |
0 / 6 |
210 | |
0.00% |
0 / 1 |
| getOneCached | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| getIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTokenizer | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| isFuzzyMatching | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
12 | |||
| isDefaultSearchable | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
12 | |||
| isStored | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2014-2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\tao\model\search\index; |
| 22 | |
| 23 | use oat\generis\model\GenerisRdf; |
| 24 | use oat\generis\model\OntologyRdfs; |
| 25 | use oat\tao\model\search\tokenizer\PropertyValueTokenizer; |
| 26 | use oat\tao\model\search\tokenizer\ResourceClasses; |
| 27 | |
| 28 | class OntologyIndex extends \core_kernel_classes_Resource |
| 29 | { |
| 30 | public const RDF_TYPE = 'http://www.tao.lu/Ontologies/TAO.rdf#Index'; |
| 31 | public const PROPERTY_INDEX = 'http://www.tao.lu/Ontologies/TAO.rdf#PropertyIndex'; |
| 32 | public const PROPERTY_INDEX_FUZZY_MATCHING = 'http://www.tao.lu/Ontologies/TAO.rdf#IndexFuzzyMatching'; |
| 33 | public const PROPERTY_INDEX_IDENTIFIER = 'http://www.tao.lu/Ontologies/TAO.rdf#IndexIdentifier'; |
| 34 | public const PROPERTY_INDEX_TOKENIZER = 'http://www.tao.lu/Ontologies/TAO.rdf#IndexTokenizer'; |
| 35 | public const PROPERTY_DEFAULT_SEARCH = 'http://www.tao.lu/Ontologies/TAO.rdf#IndexDefaultSearch'; |
| 36 | private const INDEX_CLASS = 'class'; |
| 37 | |
| 38 | private $cached = null; |
| 39 | |
| 40 | /** |
| 41 | * Preload all the index properties and return the |
| 42 | * property requested |
| 43 | * |
| 44 | * @param string $propertyUri |
| 45 | * @return Ambigous <NULL, mixed> |
| 46 | */ |
| 47 | private function getOneCached($propertyUri) |
| 48 | { |
| 49 | if (is_null($this->cached)) { |
| 50 | $props = [ |
| 51 | static::PROPERTY_INDEX_IDENTIFIER, |
| 52 | static::PROPERTY_INDEX_TOKENIZER, |
| 53 | static::PROPERTY_INDEX_FUZZY_MATCHING, |
| 54 | static::PROPERTY_DEFAULT_SEARCH |
| 55 | ]; |
| 56 | $this->cached = $this->getPropertiesValues($props); |
| 57 | } |
| 58 | return empty($this->cached[$propertyUri]) ? null : reset($this->cached[$propertyUri]); |
| 59 | } |
| 60 | |
| 61 | public function getIdentifier() |
| 62 | { |
| 63 | return (string)$this->getOneCached(static::PROPERTY_INDEX_IDENTIFIER); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @throws \common_exception_Error |
| 68 | * @return PropertyValueTokenizer |
| 69 | */ |
| 70 | public function getTokenizer() |
| 71 | { |
| 72 | if ($this->getIdentifier() === self::INDEX_CLASS) { |
| 73 | return new ResourceClasses(); |
| 74 | } |
| 75 | |
| 76 | $tokenizer = $this->getOneCached(static::PROPERTY_INDEX_TOKENIZER); |
| 77 | $implClass = (string) $tokenizer->getUniquePropertyValue( |
| 78 | $this->getProperty("http://www.tao.lu/Ontologies/TAO.rdf#TokenizerClass") |
| 79 | ); |
| 80 | if (!class_exists($implClass)) { |
| 81 | throw new \common_exception_Error( |
| 82 | 'Tokenizer class "' . $implClass . '" not found for ' . $tokenizer->getUri() |
| 83 | ); |
| 84 | } |
| 85 | return new $implClass(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Should the string matching be fuzzy |
| 90 | * defaults to false if no information present |
| 91 | * |
| 92 | * @return boolean |
| 93 | */ |
| 94 | public function isFuzzyMatching() |
| 95 | { |
| 96 | $res = $this->getOneCached(static::PROPERTY_INDEX_FUZZY_MATCHING); |
| 97 | return !is_null($res) && is_object($res) && $res->getUri() == GenerisRdf::GENERIS_TRUE; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Should the property be used by default if no index key is specified |
| 102 | * defaults to false if no information present |
| 103 | * |
| 104 | * @return boolean |
| 105 | */ |
| 106 | public function isDefaultSearchable() |
| 107 | { |
| 108 | $res = $this->getOneCached(static::PROPERTY_DEFAULT_SEARCH); |
| 109 | return !is_null($res) && is_object($res) && $res->getUri() == GenerisRdf::GENERIS_TRUE; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | /** |
| 114 | * Should the value be stored |
| 115 | * |
| 116 | * @return boolean |
| 117 | */ |
| 118 | public function isStored() |
| 119 | { |
| 120 | return $this->getUri() === OntologyRdfs::RDFS_LABEL; |
| 121 | } |
| 122 | } |