Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| GenericLomOntologyClassificationExtractor | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 1 |
| extract | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
56 | |||
| 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) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model\qti\metadata\ontology; |
| 23 | |
| 24 | use oat\generis\model\OntologyAwareTrait; |
| 25 | use oat\generis\model\OntologyRdf; |
| 26 | use oat\generis\model\OntologyRdfs; |
| 27 | use oat\taoQtiItem\model\qti\metadata\imsManifest\classificationMetadata\ClassificationEntryMetadataValue; |
| 28 | use oat\taoQtiItem\model\qti\metadata\imsManifest\classificationMetadata\ClassificationMetadataValue; |
| 29 | use oat\taoQtiItem\model\qti\metadata\imsManifest\classificationMetadata\ClassificationSourceMetadataValue; |
| 30 | use oat\taoQtiItem\model\qti\metadata\MetadataExtractionException; |
| 31 | use oat\taoQtiItem\model\qti\metadata\MetadataExtractor; |
| 32 | use taoItems_models_classes_ItemsService; |
| 33 | use taoTests_models_classes_TestsService; |
| 34 | |
| 35 | class GenericLomOntologyClassificationExtractor implements MetadataExtractor |
| 36 | { |
| 37 | use OntologyAwareTrait; |
| 38 | |
| 39 | public static $excludedProperties = [ |
| 40 | OntologyRdf::RDF_TYPE, |
| 41 | taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT, |
| 42 | taoItems_models_classes_ItemsService::PROPERTY_ITEM_MODEL, |
| 43 | taoTests_models_classes_TestsService::PROPERTY_TEST_TESTMODEL, |
| 44 | taoTests_models_classes_TestsService::PROPERTY_TEST_CONTENT, |
| 45 | ]; |
| 46 | |
| 47 | /** |
| 48 | * Extract resource metadata and transform it to ClassificationMetadataValue |
| 49 | * |
| 50 | * @param \core_kernel_classes_Resource $resource |
| 51 | * |
| 52 | * @return array |
| 53 | * |
| 54 | * @throws MetadataExtractionException |
| 55 | * @throws \oat\tao\model\metadata\exception\writer\MetadataWriterException |
| 56 | */ |
| 57 | public function extract($resource) |
| 58 | { |
| 59 | if (! $resource instanceof \core_kernel_classes_Resource) { |
| 60 | throw new MetadataExtractionException( |
| 61 | __('The given target is not an instance of core_kernel_classes_Resource') |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | $identifier = \tao_helpers_Uri::getUniqueId($resource->getUri()); |
| 66 | $metadata = [$identifier => []]; |
| 67 | |
| 68 | $triples = $resource->getRdfTriples(); |
| 69 | |
| 70 | |
| 71 | /** @var \core_kernel_classes_Triple $triple */ |
| 72 | foreach ($triples->getIterator() as $triple) { |
| 73 | |
| 74 | /** @var \core_kernel_classes_Resource $property */ |
| 75 | $property = $this->getResource($triple->predicate); |
| 76 | $value = $triple->object; |
| 77 | |
| 78 | if ( |
| 79 | trim($value) != '' |
| 80 | && $property->isProperty() |
| 81 | && !in_array($property->getUri(), self::$excludedProperties) |
| 82 | ) { |
| 83 | $metadata[$identifier][] = new ClassificationMetadataValue( |
| 84 | new ClassificationSourceMetadataValue($resource->getUri(), $property->getUri()), |
| 85 | [new ClassificationEntryMetadataValue($resource->getUri(), $value)] |
| 86 | ); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if (empty($metadata[$identifier])) { |
| 91 | return []; |
| 92 | } |
| 93 | |
| 94 | return $metadata; |
| 95 | } |
| 96 | } |