diff --git a/lib/Path.ts b/lib/Path.ts index 8911c07..81a4baa 100644 --- a/lib/Path.ts +++ b/lib/Path.ts @@ -211,6 +211,10 @@ 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, @@ -218,14 +222,11 @@ export abstract class MultiPath implements Path { 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, + }); } } diff --git a/package-lock.json b/package-lock.json index e7b3b16..ddfe5bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "extract-cbd-shape", - "version": "0.1.5", + "version": "0.1.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "extract-cbd-shape", - "version": "0.1.5", + "version": "0.1.6", "license": "MIT", "dependencies": { "@treecg/types": "^0.4.5", diff --git a/tests/05 - paths/extraction.test.ts b/tests/05 - paths/extraction.test.ts index 17ed336..d6cd7e1 100644 --- a/tests/05 - paths/extraction.test.ts +++ b/tests/05 - paths/extraction.test.ts @@ -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, diff --git a/tests/05 - paths/shape.ttl b/tests/05 - paths/shape.ttl index 5b6ff66..acaa84b 100644 --- a/tests/05 - paths/shape.ttl +++ b/tests/05 - paths/shape.ttl @@ -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 [