Skip to content

Commit

Permalink
Merge pull request #31 from TREEcg/fix-22
Browse files Browse the repository at this point in the history
Fixing issue 22: zeroOrMorePaths should return all options, not just one
  • Loading branch information
pietercolpaert authored May 14, 2024
2 parents 66e3978 + 95f8162 commit f468973
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
17 changes: 9 additions & 8 deletions lib/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,22 @@ export abstract class MultiPath implements Path {
const newTargets: PathResult[] = [];

for (const t of targets) {
if (this.filter(i, t)) {
out.push(t);
}

for (const found of this.path.match(
store,
t.cbdExtracted,
t.target,
graphsToIgnore,
inverse,
)) {
if (this.filter(i, found)) {
out.push({
path: [...t.path, ...found.path],
cbdExtracted: t.cbdExtracted,
target: found.target,
});
}
newTargets.push(found);
newTargets.push({
path: [...t.path, ...found.path],
cbdExtracted: t.cbdExtracted,
target: found.target,
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/05 - paths/extraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ describe("Check whether paths trigger the right extraction process", function ()
//writer.end((err, res) => {console.error(res);});
assert.equal(result.length, 2);
});
it("Test a zeroOrMore path where zero and multiple both match", async () => {
let result = await extractor.extract(
dataStore,
new NamedNode("http://example.org/B"),
new NamedNode("http://example.org/ZeroOrMorePathShape2"),
);
//ISSUE 22: the triple ex:B ex:p2 ex:C also matches the zeroOrMorePath, but this is not being returned
assert.equal(result.length, 3);
});
it("Test a oneOrMore path", async () => {
let result = await extractor.extract(
dataStore,
Expand Down
6 changes: 6 additions & 0 deletions tests/05 - paths/shape.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ ex:ZeroOrOnePathShape a sh:NodeShape ;
sh:minCount 1
] .

ex:ZeroOrMorePathShape2 a sh:NodeShape ;
sh:closed true;
sh:property [
sh:path ([sh:zeroOrMorePath ex:p1 ] ex:p2) ;
] .

ex:AlternativePathShape a sh:NodeShape ;
sh:closed true;
sh:property [
Expand Down

0 comments on commit f468973

Please sign in to comment.