Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue 22: zeroOrMorePaths should return all options, not just one #31

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading