From f08115927501b48d10ca61e4143426d39b90d9b7 Mon Sep 17 00:00:00 2001 From: Vlad Byndych Date: Fri, 29 Sep 2023 17:02:06 +0200 Subject: [PATCH 1/3] feat: ontology import/export for neo4j. --- core/kernel/persistence/file/FileModel.php | 2 +- .../persistence/smoothsql/class.SmoothRdf.php | 23 +-- .../starsql/FlatRecursiveIterator.php | 36 +++++ .../persistence/starsql/class.Class.php | 10 +- .../persistence/starsql/class.Resource.php | 29 ++-- .../starsql/class.StarIterator.php | 71 +++++++++ .../persistence/starsql/class.StarModel.php | 9 +- .../persistence/starsql/class.StarRdf.php | 149 +++++++++--------- .../starsql/search/CountSerializer.php | 2 +- .../starsql/search/QuerySerializer.php | 28 +++- helpers/class.RdfDiff.php | 2 +- 11 files changed, 245 insertions(+), 116 deletions(-) create mode 100644 core/kernel/persistence/starsql/FlatRecursiveIterator.php create mode 100644 core/kernel/persistence/starsql/class.StarIterator.php diff --git a/core/kernel/persistence/file/FileModel.php b/core/kernel/persistence/file/FileModel.php index 6acba77eb..eac4b624d 100755 --- a/core/kernel/persistence/file/FileModel.php +++ b/core/kernel/persistence/file/FileModel.php @@ -58,7 +58,7 @@ public static function toFile($filePath, $triples) if (!empty($triple->lg)) { $graph->addLiteral($triple->subject, $triple->predicate, $triple->object, $triple->lg); } elseif (\common_Utils::isUri($triple->object)) { - $graph->add($triple->subject, $triple->predicate, $triple->object); + $graph->addResource($triple->subject, $triple->predicate, $triple->object); } else { $graph->addLiteral($triple->subject, $triple->predicate, $triple->object); } diff --git a/core/kernel/persistence/smoothsql/class.SmoothRdf.php b/core/kernel/persistence/smoothsql/class.SmoothRdf.php index dda69ced7..94edb3b1e 100644 --- a/core/kernel/persistence/smoothsql/class.SmoothRdf.php +++ b/core/kernel/persistence/smoothsql/class.SmoothRdf.php @@ -76,6 +76,15 @@ public function get($subject, $predicate) throw new \common_Exception('Not implemented'); } + /** + * (non-PHPdoc) + * @see \oat\generis\model\data\RdfInterface::search() + */ + public function search($predicate, $object) + { + throw new \common_Exception('Not implemented'); + } + /** * (non-PHPdoc) * @see \oat\generis\model\data\RdfInterface::add() @@ -155,18 +164,12 @@ public function remove(core_kernel_classes_Triple $triple) ); } - /** - * (non-PHPdoc) - * @see \oat\generis\model\data\RdfInterface::search() - */ - public function search($predicate, $object) - { - throw new \common_Exception('Not implemented'); - } - public function getIterator() { - return new core_kernel_persistence_smoothsql_SmoothIterator($this->getPersistence()); + return new core_kernel_persistence_smoothsql_SmoothIterator( + $this->getPersistence(), + array_diff($this->model->getReadableModels(), ['1']) + ); } /** diff --git a/core/kernel/persistence/starsql/FlatRecursiveIterator.php b/core/kernel/persistence/starsql/FlatRecursiveIterator.php new file mode 100644 index 000000000..881c06030 --- /dev/null +++ b/core/kernel/persistence/starsql/FlatRecursiveIterator.php @@ -0,0 +1,36 @@ +(startNode) + MATCH (descendantNode)-[:`{$relationship}`*]->(startNode) RETURN descendantNode.uri CYPHER; } else { $query = <<(startNode) + MATCH (descendantNode)-[:`{$relationship}`]->(startNode) RETURN descendantNode.uri CYPHER; } @@ -94,13 +94,13 @@ public function getParentClasses(core_kernel_classes_Class $resource, $recursive if (!empty($recursive)) { $query = <<(ancestorNode) + MATCH (startNode)-[:`{$relationship}`*]->(ancestorNode) RETURN ancestorNode.uri CYPHER; } else { $query = <<(ancestorNode) + MATCH (startNode)-[:`{$relationship}`]->(ancestorNode) RETURN ancestorNode.uri CYPHER; } @@ -122,7 +122,7 @@ public function getProperties(core_kernel_classes_Class $resource, $recursive = $relationship = OntologyRdfs::RDFS_DOMAIN; $query = <<(startNode) + MATCH (descendantNode)-[:`{$relationship}`]->(startNode) RETURN descendantNode.uri CYPHER; $results = $this->getPersistence()->run($query, ['uri' => $uri]); diff --git a/core/kernel/persistence/starsql/class.Resource.php b/core/kernel/persistence/starsql/class.Resource.php index e909dc207..223b538fe 100644 --- a/core/kernel/persistence/starsql/class.Resource.php +++ b/core/kernel/persistence/starsql/class.Resource.php @@ -339,7 +339,10 @@ public function removePropertyValueByLg(core_kernel_classes_Resource $resource, public function getRdfTriples(core_kernel_classes_Resource $resource): core_kernel_classes_ContainerCollection { - $relationship = relationshipTo()->withVariable($relationshipVar = variable()); + $relationship = relationshipTo() + ->withVariable($relationshipVar = variable()) + ->withMinHops(0) + ->withMaxHops(1); $relatedNode = node()->withLabels(['Resource'])->withVariable($relatedNodeVar = variable()); $node = node()->withProperties(['uri' => $uriParameter = parameter()]) ->withVariable($nodeVar = variable()) @@ -352,20 +355,20 @@ public function getRdfTriples(core_kernel_classes_Resource $resource): core_kern $results = $this->getPersistence()->run($query, [$uriParameter->getParameter() => $resource->getUri()]); $returnValue = new core_kernel_classes_ContainerCollection(new common_Object(__METHOD__)); + $nodeProcessed = false; foreach ($results as $result) { $resultNode = $result->get($nodeVar->getName()); + /** @var \Laudis\Neo4j\Types\CypherMap $resultRelationship */ $resultRelationship = $result->get($relationshipVar->getName()); $resultRelatedNode = $result->get($relatedNodeVar->getName()); - $updatedAt = $resultNode->getProperty(TaoOntology::PROPERTY_UPDATED_AT); -// $updatedBy = $resultNode->getProperty(TaoOntology::PROPERTY_UPDATED_BY); if (!$nodeProcessed) { - $returnValue = $this->buildTriplesFromNode($returnValue, $resource->getUri(), $updatedAt, $resultNode); + $returnValue = $this->buildTriplesFromNode($returnValue, $resource->getUri(), $resultNode); $nodeProcessed = true; } - if ($resultRelationship) { + if (!$resultRelationship->isEmpty()) { + $resultRelationship = $resultRelationship->first(); $triple = new core_kernel_classes_Triple(); $triple->subject = $resource->getUri(); - $triple->epoch = $updatedAt; $triple->predicate = $resultRelationship->getType(); $triple->object = $resultRelatedNode->getProperty('uri'); $returnValue->add($triple); @@ -593,19 +596,21 @@ private function parseTranslatedLang($value): string return $matches[2] ?? ''; } - private function buildTriplesFromNode(core_kernel_classes_ContainerCollection $tripleCollection, $uri, $updatedAt, $resultNode) + private function buildTriplesFromNode(core_kernel_classes_ContainerCollection $tripleCollection, $uri, $resultNode) { foreach ($resultNode->getProperties() as $propKey => $propValue) { + if ($propKey === 'uri') { + continue; + } $triple = new core_kernel_classes_Triple(); $triple->subject = $uri; -// $triple->author = $updatedBy; - $triple->epoch = $updatedAt; $triple->predicate = $propKey; if (is_iterable($propValue)) { foreach ($propValue as $value) { - $triple->lg = $this->parseTranslatedLang($value); - $triple->object = $this->parseTranslatedValue($value); - $tripleCollection->add($triple); + $langTriple = clone $triple; + $langTriple->lg = $this->parseTranslatedLang($value); + $langTriple->object = $this->parseTranslatedValue($value); + $tripleCollection->add($langTriple); } } else { $triple->lg = $this->parseTranslatedLang($propValue); diff --git a/core/kernel/persistence/starsql/class.StarIterator.php b/core/kernel/persistence/starsql/class.StarIterator.php new file mode 100644 index 000000000..b96401296 --- /dev/null +++ b/core/kernel/persistence/starsql/class.StarIterator.php @@ -0,0 +1,71 @@ + + * @package generis + */ +class core_kernel_persistence_starsql_StarIterator extends \IteratorIterator implements \RecursiveIterator +{ + public function __construct(Model $model) + { + /** @var ComplexSearchService $search */ + $search = $model->getSearchInterface(); + $query = $search->query(); + + $queryOptions = $query->getOptions(); + $queryOptions['system_only'] = true; + $query->setOptions($queryOptions); + + parent::__construct($search->getGateway()->search($query)); + } + + public function hasChildren() + { + return true; + } + + public function current() + { + $current = parent::current(); + + if ($current instanceof \core_kernel_classes_Literal) { + $current = new \core_kernel_classes_Resource($current->literal); + } + + return $current; + } + + + public function getChildren() + { + /** @var \core_kernel_classes_Resource $currentResource */ + $currentResource = $this->current(); + + return new FlatRecursiveIterator($currentResource->getRdfTriples()); + } +} diff --git a/core/kernel/persistence/starsql/class.StarModel.php b/core/kernel/persistence/starsql/class.StarModel.php index 121167c40..eb3df26a7 100644 --- a/core/kernel/persistence/starsql/class.StarModel.php +++ b/core/kernel/persistence/starsql/class.StarModel.php @@ -26,8 +26,7 @@ use oat\generis\model\kernel\persistence\smoothsql\install\SmoothRdsModel; use oat\oatbox\cache\SimpleCache; -class core_kernel_persistence_starsql_StarModel extends ConfigurableService implements Ontology, - SchemaProviderInterface +class core_kernel_persistence_starsql_StarModel extends ConfigurableService implements Ontology { const OPTION_PERSISTENCE = 'persistence'; const OPTION_READABLE_MODELS = 'readable'; @@ -198,10 +197,4 @@ public static function getUpdatableModelIds() } return $model->getWritableModels(); } - - public function provideSchema(SchemaCollection $schemaCollection) - { -// $schema = $schemaCollection->getSchema($this->getOption(self::OPTION_PERSISTENCE)); -// SmoothRdsModel::addSmoothTables($schema); - } } diff --git a/core/kernel/persistence/starsql/class.StarRdf.php b/core/kernel/persistence/starsql/class.StarRdf.php index c05de7373..bd0443edc 100644 --- a/core/kernel/persistence/starsql/class.StarRdf.php +++ b/core/kernel/persistence/starsql/class.StarRdf.php @@ -19,31 +19,14 @@ declare(strict_types=1); -use Doctrine\DBAL\ParameterType; -use oat\generis\model\data\Ontology; +use EasyRdf\Format; +use EasyRdf\Graph; +use Laudis\Neo4j\Databags\Statement; use oat\generis\model\data\RdfInterface; +use WikibaseSolutions\CypherDSL\Query; class core_kernel_persistence_starsql_StarRdf implements RdfInterface { - public const BATCH_SIZE = 100; - - public const TRIPLE_PARAMETER_TYPE = [ - // modelid - ParameterType::INTEGER, - // subject - ParameterType::STRING, - // predicate - ParameterType::STRING, - // object - ParameterType::STRING, - // l_language - ParameterType::STRING, - // epoch - ParameterType::STRING, - // author - ParameterType::STRING, - ]; - /** * @var core_kernel_persistence_starsql_StarModel */ @@ -60,8 +43,7 @@ protected function getPersistence() } /** - * (non-PHPdoc) - * @see \oat\generis\model\data\RdfInterface::get() + * {@inheritDoc} */ public function get($subject, $predicate) { @@ -69,88 +51,109 @@ public function get($subject, $predicate) } /** - * (non-PHPdoc) - * @see \oat\generis\model\data\RdfInterface::add() + * {@inheritDoc} */ - public function add(core_kernel_classes_Triple $triple) + public function search($predicate, $object) { - throw new common_Exception('Not implemented! ' . __FILE__ . ' line: ' . __LINE__); + throw new common_Exception('Not implemented'); } /** - * @inheritDoc + * {@inheritDoc} */ - public function addTripleCollection(iterable $triples) + public function add(core_kernel_classes_Triple $triple) { - throw new common_Exception('Not implemented! ' . __FILE__ . ' line: ' . __LINE__); + $this->addTripleCollection([$triple]); } - protected function insertTriples(array $triples) + /** + * {@inheritDoc} + */ + public function addTripleCollection(iterable $triples) { - $values = array_map([$this, "tripleToValue"], $triples); - return $this->insertValues($values); - } + $nTriple = $this->triplesToValues($triples, Format::getFormat('ntriples')); - protected function insertValues(array $valuesToInsert) - { - $types = []; - foreach ($valuesToInsert as $value) { - array_push($types, ...$this->getTripleParameterTypes()); - } + $persistence = $this->getPersistence(); + $persistence->run( + 'CALL n10s.rdf.import.inline($nTriple,"N-Triples")', + ['nTriple' => $nTriple] + ); - return $this->getPersistence()->insertMultiple('statements', $valuesToInsert, $types); + $systemTripleQuery = $this->createSystemTripleQuery($triples); + if ($systemTripleQuery instanceof Statement) { + $persistence->runStatement($systemTripleQuery); + } } /** - * (non-PHPdoc) - * @see \oat\generis\model\data\RdfInterface::remove() + * {@inheritDoc} */ public function remove(core_kernel_classes_Triple $triple) { - throw new common_Exception('Not implemented! ' . __FILE__ . ' line: ' . __LINE__); + $nTriple = $this->triplesToValues([$triple], Format::getFormat('ntriples')); + + $persistence = $this->getPersistence(); + $persistence->run( + 'CALL n10s.rdf.delete.inline($nTriple,"N-Triples")', + ['nTriple' => $nTriple] + ); } /** - * (non-PHPdoc) - * @see \oat\generis\model\data\RdfInterface::search() + * {@inheritDoc} */ - public function search($predicate, $object) - { - throw new common_Exception('Not implemented'); - } - public function getIterator() { - throw new common_Exception('Not implemented! ' . __FILE__ . ' line: ' . __LINE__); + return new RecursiveIteratorIterator(new core_kernel_persistence_starsql_StarIterator($this->model)); } /** - * @return Ontology + * @param iterable $tripleList + * @param Format $format + * + * @return string */ - protected function getModel() + private function triplesToValues(iterable $tripleList, Format $format): string { - return $this->model; - } + $graph = new Graph(); + + /** @var core_kernel_classes_Triple $triple */ + foreach ($tripleList as $triple) { + if (!empty($triple->lg)) { + $graph->addLiteral( + $triple->subject, + $triple->predicate, + $triple->object, + $triple->lg + ); + } elseif (\common_Utils::isUri($triple->object)) { + $graph->addResource($triple->subject, $triple->predicate, $triple->object); + } else { + $graph->addLiteral($triple->subject, $triple->predicate, $triple->object); + } + } - /** - * @param core_kernel_classes_Triple $triple - * @return array - */ - protected function tripleToValue(core_kernel_classes_Triple $triple): array - { - return [ - 'modelid' => $triple->modelid, - 'subject' => $triple->subject, - 'predicate' => $triple->predicate, - 'object' => $triple->object, - 'l_language' => is_null($triple->lg) ? '' : $triple->lg, - 'author' => is_null($triple->author) ? '' : $triple->author, - 'epoch' => $this->getPersistence()->getPlatForm()->getNowExpression() - ]; + return $graph->serialise($format); } - protected function getTripleParameterTypes(): array + private function createSystemTripleQuery(iterable $tripleList): ?Statement { - return self::TRIPLE_PARAMETER_TYPE; + $systemSubjectList = []; + /** @var core_kernel_classes_Triple $triple */ + foreach ($tripleList as $triple) { + if (!empty($triple->modelid) && $triple->modelid != \core_kernel_persistence_starsql_StarModel::DEFAULT_WRITABLE_MODEL) { + $systemSubjectList[$triple->subject] = true; + } + } + + $query = null; + if (!empty($systemSubjectList)) { + $systemNode = Query::node('Resource'); + $query = Query::new()->match($systemNode) + ->where($systemNode->property('uri')->in(array_keys($systemSubjectList))) + ->set($systemNode->labeled('System')); + } + + return Statement::create($query->build()); } } diff --git a/core/kernel/persistence/starsql/search/CountSerializer.php b/core/kernel/persistence/starsql/search/CountSerializer.php index 5680d02ff..daa31d5d9 100644 --- a/core/kernel/persistence/starsql/search/CountSerializer.php +++ b/core/kernel/persistence/starsql/search/CountSerializer.php @@ -29,7 +29,7 @@ class CountSerializer extends QuerySerializer { public function serialyse() { - $subject = Query::node('Resource')->withVariable(Query::variable('subject')); + $subject = $this->getMainNode(); $this->buildMatchPatterns($subject); $this->buildWhereConditions($subject); diff --git a/core/kernel/persistence/starsql/search/QuerySerializer.php b/core/kernel/persistence/starsql/search/QuerySerializer.php index dde781ad9..dcd713851 100644 --- a/core/kernel/persistence/starsql/search/QuerySerializer.php +++ b/core/kernel/persistence/starsql/search/QuerySerializer.php @@ -116,7 +116,7 @@ public function setOptions(array $options) public function serialyse() { - $subject = Query::node('Resource')->withVariable(Query::variable('subject')); + $subject = $this->getMainNode(); $this->buildMatchPatterns($subject); $this->buildWhereConditions($subject); @@ -141,7 +141,7 @@ public function serialyse() return Statement::create($query->build(), $this->parameters); } - public function buildMatchPatterns(Node $subject): void + protected function buildMatchPatterns(Node $subject): void { $queryOptions = $this->criteriaList->getOptions(); @@ -181,10 +181,12 @@ public function buildMatchPatterns(Node $subject): void $this->matchPatterns[] = $parentPath; $this->whereConditions[] = $parentWhere; + } else { + $this->matchPatterns[] = $subject; } } - public function buildWhereConditions(Node $subject): void + protected function buildWhereConditions(Node $subject): void { $whereCondition = null; foreach ($this->criteriaList->getStoredQueries() as $query) { @@ -218,7 +220,7 @@ public function buildWhereConditions(Node $subject): void } } - public function buildCondition(QueryCriterionInterface $operation, Node $subject): BooleanType + protected function buildCondition(QueryCriterionInterface $operation, Node $subject): BooleanType { $property = ModelManager::getModel()->getProperty($operation->getName()); if ($property->isRelationship()) { @@ -248,7 +250,7 @@ public function buildCondition(QueryCriterionInterface $operation, Node $subject return $fieldCondition; } - private function buildPropertyQuery( + protected function buildPropertyQuery( $predicate, $values, string $operation @@ -343,4 +345,20 @@ protected function buildOrderCondition(Node $subject): void $this->orderCondition = Query::rawExpression(implode(', ', $sort)); } } + + /** + * @return Node + */ + protected function getMainNode(): Node + { + $queryOptions = $this->criteriaList->getOptions(); + + if (isset($queryOptions['system_only']) && $queryOptions['system_only']) { + $node = Query::node('System'); + } else { + $node = Query::node('Resource'); + } + + return $node->withVariable(Query::variable('subject')); + } } diff --git a/helpers/class.RdfDiff.php b/helpers/class.RdfDiff.php index 67f89c7cf..5c4a733cb 100755 --- a/helpers/class.RdfDiff.php +++ b/helpers/class.RdfDiff.php @@ -77,7 +77,7 @@ protected function generateSerial(core_kernel_classes_Triple $triple) return md5( implode( ' ', - [$triple->subject, $triple->predicate, $triple->object, $triple->lg, $triple->modelid] + [$triple->subject, $triple->predicate, $triple->object, (string)$triple->lg] ) ); } From 48288819f9450b4522e06e9d5e33924876e40abc Mon Sep 17 00:00:00 2001 From: Vlad Byndych Date: Fri, 29 Sep 2023 17:02:25 +0200 Subject: [PATCH 2/3] fix: removed duplicated properties. --- core/ontology/widgetdefinitions.rdf | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/ontology/widgetdefinitions.rdf b/core/ontology/widgetdefinitions.rdf index e1bcb1461..4f449f67d 100644 --- a/core/ontology/widgetdefinitions.rdf +++ b/core/ontology/widgetdefinitions.rdf @@ -109,7 +109,6 @@ - @@ -124,7 +123,6 @@ - From 0df3a8c8149ccf0559e849937d517bea98599340 Mon Sep 17 00:00:00 2001 From: Vlad Byndych Date: Fri, 13 Oct 2023 10:24:31 +0200 Subject: [PATCH 3/3] fix: fixed tests and typo in functions. --- .../persistence/starsql/class.StarIterator.php | 4 +--- core/kernel/persistence/starsql/class.StarRdf.php | 4 +++- test/unit/core/data/import/RdfImportTest.php | 4 ++-- .../core/kernel/persistence/OntologyRdfTest.php | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/kernel/persistence/starsql/class.StarIterator.php b/core/kernel/persistence/starsql/class.StarIterator.php index b96401296..77255440c 100644 --- a/core/kernel/persistence/starsql/class.StarIterator.php +++ b/core/kernel/persistence/starsql/class.StarIterator.php @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2002-2008 (original work) 2014 Open Assessment Technologies SA + * Copyright (c) 2023 (original work) Open Assessment Technologies SA * */ @@ -26,8 +26,6 @@ /** * Iterator over all triples * - * @author joel bout - * @package generis */ class core_kernel_persistence_starsql_StarIterator extends \IteratorIterator implements \RecursiveIterator { diff --git a/core/kernel/persistence/starsql/class.StarRdf.php b/core/kernel/persistence/starsql/class.StarRdf.php index bd0443edc..1ac072b17 100644 --- a/core/kernel/persistence/starsql/class.StarRdf.php +++ b/core/kernel/persistence/starsql/class.StarRdf.php @@ -152,8 +152,10 @@ private function createSystemTripleQuery(iterable $tripleList): ?Statement $query = Query::new()->match($systemNode) ->where($systemNode->property('uri')->in(array_keys($systemSubjectList))) ->set($systemNode->labeled('System')); + + $query = Statement::create($query->build()); } - return Statement::create($query->build()); + return $query; } } diff --git a/test/unit/core/data/import/RdfImportTest.php b/test/unit/core/data/import/RdfImportTest.php index 8bf6bec64..23411f520 100644 --- a/test/unit/core/data/import/RdfImportTest.php +++ b/test/unit/core/data/import/RdfImportTest.php @@ -34,8 +34,8 @@ class RdfImportTest extends GenerisTestCase public function testRdfTripleImport(Ontology $ontology) { $this->assertEquals(0, $this->getTripleCount($ontology)); - $triple1 = core_kernel_classes_Triple::createTriple(0, 'subject', 'predicate', 'object'); - $triple2 = core_kernel_classes_Triple::createTriple(0, 'subject', 'predicate', 'object2'); + $triple1 = core_kernel_classes_Triple::createTriple(2, 'subject', 'predicate', 'object'); + $triple2 = core_kernel_classes_Triple::createTriple(2, 'subject', 'predicate', 'object2'); $importer = new RdfImporter(); $importer->setServiceLocator($ontology->getServiceLocator()); $importer->importTriples([$triple1, $triple2]); diff --git a/test/unit/core/kernel/persistence/OntologyRdfTest.php b/test/unit/core/kernel/persistence/OntologyRdfTest.php index f7ef03104..615af062b 100644 --- a/test/unit/core/kernel/persistence/OntologyRdfTest.php +++ b/test/unit/core/kernel/persistence/OntologyRdfTest.php @@ -38,8 +38,8 @@ class OntologyRdfTest extends GenerisTestCase public function testRdfInterface(Ontology $ontology) { $this->assertEquals(0, $this->getTripleCount($ontology)); - $triple1 = core_kernel_classes_Triple::createTriple(0, 'subject', 'predicate', 'object'); - $triple2 = core_kernel_classes_Triple::createTriple(0, 'subject', 'predicate', 'object2'); + $triple1 = core_kernel_classes_Triple::createTriple(2, 'subject', 'predicate', 'object'); + $triple2 = core_kernel_classes_Triple::createTriple(2, 'subject', 'predicate', 'object2'); $ontology->getRdfInterface()->add($triple1); $this->assertEquals(1, $this->getTripleCount($ontology)); $ontology->getRdfInterface()->remove($triple2); @@ -55,7 +55,7 @@ public function testRdfInterface(Ontology $ontology) public function testAdd(Ontology $ontology) { $this->assertEquals(0, $this->getTripleCount($ontology)); - $triple1 = core_kernel_classes_Triple::createTriple(0, 'subject', 'predicate', 'object'); + $triple1 = core_kernel_classes_Triple::createTriple(2, 'subject', 'predicate', 'object'); $ontology->getRdfInterface()->add($triple1); $this->assertEquals(1, $this->getTripleCount($ontology)); $triples = $ontology->getRdfInterface(); @@ -79,9 +79,9 @@ public function testAddTripleCollection(Ontology $ontology) $this->assertInstanceOf(Ontology::class, $ontology); $this->assertEquals(0, $this->getTripleCount($ontology)); - $triple1 = core_kernel_classes_Triple::createTriple(0, 'subject', 'predicate', 'object'); - $triple2 = core_kernel_classes_Triple::createTriple(0, 'subject2', OntologyRdf::RDF_TYPE, 'object2'); - $triple3 = core_kernel_classes_Triple::createTriple(0, 'subject3', OntologyRdfs::RDFS_SUBCLASSOF, 'object2'); + $triple1 = core_kernel_classes_Triple::createTriple(2, 'subject', 'predicate', 'object'); + $triple2 = core_kernel_classes_Triple::createTriple(2, 'subject2', OntologyRdf::RDF_TYPE, 'object2'); + $triple3 = core_kernel_classes_Triple::createTriple(2, 'subject3', OntologyRdfs::RDFS_SUBCLASSOF, 'object2'); $ontology->getRdfInterface()->addTripleCollection([$triple1, $triple2, $triple3]); $this->assertEquals(3, $this->getTripleCount($ontology)); @@ -95,7 +95,7 @@ public function testRemove(Ontology $ontology) { $this->assertInstanceOf(Ontology::class, $ontology); $this->assertEquals(0, $this->getTripleCount($ontology)); - $triple1 = core_kernel_classes_Triple::createTriple(0, 'subject', 'predicate', 'object'); + $triple1 = core_kernel_classes_Triple::createTriple(2, 'subject', 'predicate', 'object'); $ontology->getRdfInterface()->add($triple1); $this->assertEquals(1, $this->getTripleCount($ontology)); $ontology->getRdfInterface()->remove($triple1);