Skip to content

Commit

Permalink
Adjusted to rdfInterface 0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Apr 13, 2021
1 parent ccbe7ba commit 23a4ad2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"php": ">=8.0",
"zozlak/rdf-constants": "^1.1",
"sweetrdf/rdf-helpers": "*",
"sweetrdf/rdf-interface": "~0.9.0"
"sweetrdf/rdf-interface": "~0.10.0"
},
"suggest": {
"sweetrdf/quick-rdf-io": "*"
Expand All @@ -32,7 +32,7 @@
"phpstan/phpstan": "*",
"squizlabs/php_codesniffer": "*",
"php-coveralls/php-coveralls": "^2.4",
"sweetrdf/rdf-interface-tests": "~0.9.0",
"sweetrdf/rdf-interface-tests": "~0.10.0",
"sweetrdf/term-templates": "*"
},
"autoload-dev": {
Expand Down
44 changes: 22 additions & 22 deletions src/simpleRdf/Dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
use Generator;
use Iterator;
use OutOfBoundsException;
use rdfHelpers\GenericTermIterator;
use rdfInterface\BlankNode as iBlankNode;
use rdfInterface\Quad as iQuad;
use rdfInterface\QuadCompare as iQuadCompare;
use rdfInterface\QuadIterator as iQuadIterator;
use rdfInterface\TermIterator as iTermIterator;
use rdfInterface\Dataset as iDataset;
use rdfInterface\DatasetMapReduce as iDatasetMapReduce;
use rdfInterface\DatasetListQuadParts as iDatasetListQuadParts;
Expand Down Expand Up @@ -347,46 +349,44 @@ public function none(iQuadCompare | iQuadIterator | callable $filter): bool {
/**
*
* @param iQuadCompare|iQuadIterator|callable $filter
* @return Generator<iTerm>
* @return iTermIterator
*/
public function listSubjects(iQuadCompare | iQuadIterator | callable $filter = null): Generator {
yield from $this->listQuadElement($filter, 'getSubject');
public function listSubjects(iQuadCompare | iQuadIterator | callable $filter = null): iTermIterator {
return $this->listQuadElement($filter, 'getSubject');
}

/**
*
* @param iQuadCompare|iQuadIterator|callable $filter
* @return Generator<iNamedNode>
* @return iTermIterator
*/
public function listPredicates(iQuadCompare | iQuadIterator | callable $filter = null): Generator {
yield from $this->listQuadElement($filter, 'getPredicate');
public function listPredicates(iQuadCompare | iQuadIterator | callable $filter = null): iTermIterator {
return $this->listQuadElement($filter, 'getPredicate');
}

/**
*
* @param iQuadCompare|iQuadIterator|callable $filter
* @return Generator<iTerm>
* @return iTermIterator
*/
public function listObjects(iQuadCompare | iQuadIterator | callable $filter = null): Generator {
yield from $this->listQuadElement($filter, 'getObject');
public function listObjects(iQuadCompare | iQuadIterator | callable $filter = null): iTermIterator {
return $this->listQuadElement($filter, 'getObject');
}

/**
*
* @param iQuadCompare|iQuadIterator|callable $filter
* @return Generator<iNamedNode | iBlankNode | iDefaultGraph>
* @return iTermIterator
*/
public function listGraphs(iQuadCompare | iQuadIterator | callable $filter = null): Generator {
yield from $this->listQuadElement($filter, 'getGraph');
public function listGraphs(iQuadCompare | iQuadIterator | callable $filter = null): iTermIterator {
return $this->listQuadElement($filter, 'getGraph');
}

private function listQuadElement(iQuadCompare | iQuadIterator | callable | null $filter,
string $elementFn): Generator {
string $elementFn): iTermIterator {
$spotted = [];
try {
$spotted = [];
// materialize to avoid problems with parallel quads iterations
$idx = iterator_to_array($this->findMatchingQuads($filter));
foreach ($idx as $i) {
foreach ($this->findMatchingQuads($filter) as $i) {
$i = $this->quads[$i]->$elementFn();
$flag = true;
foreach ($spotted as $j) {
Expand All @@ -396,13 +396,13 @@ private function listQuadElement(iQuadCompare | iQuadIterator | callable | null
}
}
if ($flag) {
yield $i;
$spotted[] = $i;
}
}
} catch (OutOfBoundsException $ex) {
yield from [];

}
return new GenericTermIterator($spotted);
}
// Private Part

Expand Down Expand Up @@ -445,17 +445,17 @@ private function findNotMatchingQuads(
}

private function prepareMatchFunction(iQuadCompare | iQuadIterator | callable | bool $offset): callable {
$fn = function() use ($offset) {
$fn = function () use ($offset) {
return $offset;
};
if (is_callable($offset)) {
$fn = $offset;
} elseif ($offset instanceof iQuad || $offset instanceof iQuadCompare) {
$fn = function(iQuad $x) use($offset): bool {
$fn = function (iQuad $x) use ($offset): bool {
return $offset->equals($x);
};
} elseif ($offset instanceof iQuadIterator) {
$fn = function(iQuad $x) use($offset): bool {
$fn = function (iQuad $x) use ($offset): bool {
foreach ($offset as $i) {
if ($i->equals($x)) {
return true;
Expand Down

0 comments on commit 23a4ad2

Please sign in to comment.