Skip to content

Commit

Permalink
Merge pull request #36 from TREEcg/fix/35
Browse files Browse the repository at this point in the history
Fix/35
  • Loading branch information
pietercolpaert authored Dec 3, 2024
2 parents 33a00dd + 6eea9a9 commit 76a9002
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/CBDShapeExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {RdfStore} from "rdf-stores";
import {Quad, Term} from "@rdfjs/types";
import debug from "debug";
import {ShapesGraph} from "./ShapesGraph";
import { Writer } from "n3";

const log = debug("extract-cbd-shape");

Expand Down Expand Up @@ -420,7 +421,7 @@ class ExtractInstance {
* @param id starting subject
* @param graphsToIgnore
*/
private async CBD(
private CBD(
id: Term,
result: Quad[],
extractedStar: CbdExtracted,
Expand All @@ -444,7 +445,7 @@ class ExtractInstance {
q.object.termType === "BlankNode" &&
!extractedStar.cbdExtracted(q.object)
) {
await this.CBD(q.object, result, next, graphsToIgnore);
this.CBD(q.object, result, next, graphsToIgnore);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/01 - fetching a shacl shape/extraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ describe("Check whether we can successfully extract a SHACL shape", async () =>
writer.end((err, res) => {console.log(res);});*/

//TODO: Didn’t yet calculate how many actually should be returned here... Just assumed this number is correct...
assert.equal(result.length, 264); // Just testing whether there are quads being returned now
assert.equal(result.length, 273); // Just testing whether there are quads being returned now
});
});
66 changes: 66 additions & 0 deletions tests/06 - shapes and named graphs/extraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,72 @@ describe("Check whether paths trigger the right extraction process", function ()
);
// It should only have 2 quads: one outside of the named graph, and one in the named graph that is not part of the other named graphs
assert.equal(result.length, 2);

});
});

describe("regression tests", () => {
it("blank nodes break extraction 1", async () => {
const quadsString = `
<https://example.com/ns#testing> a <http://schema.org/Movie>;
<http://schema.org/actor> _:b1_n3-0, _:b1_n3-1, _:b1_n3-2, _:b1_n3-3;
<http://purl.org/dc/terms/isVersionOf> <http://yikes.dog/namespaces/movies/Alien>;
<http://www.w3.org/ns/prov#generatedAtTime> "2024-12-03T13:10:42.331Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>.
`;
const quads = new Parser().parse(quadsString);
const extractor = new CBDShapeExtractor();
const store = RdfStore.createDefault();
quads.forEach(x => store.addQuad(x));
const extracted = await extractor.extract(store, new NamedNode("https://example.com/ns#testing"));

assert.equal(extracted.length, 7);
});

it("blank nodes break extraction 2", async () => {
const quadsString = `
<https://example.com/ns#testing> a <http://schema.org/Movie>;
<http://schema.org/actor> _:b1_n3-0, _:b1_n3-1, _:b1_n3-2;
<http://purl.org/dc/terms/isVersionOf> <http://yikes.dog/namespaces/movies/Alien>;
<http://www.w3.org/ns/prov#generatedAtTime> "2024-12-03T13:10:42.331Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>.
`;
const quads = new Parser().parse(quadsString);
const extractor = new CBDShapeExtractor();
const store = RdfStore.createDefault();
quads.forEach(x => store.addQuad(x));
const extracted = await extractor.extract(store, new NamedNode("https://example.com/ns#testing"));

assert.equal(extracted.length, 6);
});

it("blank nodes break extraction 3", async () => {
const quadsString = `
<https://example.com/ns#testing> a <http://schema.org/Movie>;
<http://purl.org/dc/terms/isVersionOf> <http://yikes.dog/namespaces/movies/Alien>;
<http://www.w3.org/ns/prov#generatedAtTime> "2024-12-03T13:10:42.331Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>;
<http://schema.org/actor> _:b1_n3-0, _:b1_n3-1, _:b1_n3-2.
`;
const quads = new Parser().parse(quadsString);
const extractor = new CBDShapeExtractor();
const store = RdfStore.createDefault();
quads.forEach(x => store.addQuad(x));
const extracted = await extractor.extract(store, new NamedNode("https://example.com/ns#testing"));

assert.equal(extracted.length, 6);
});

it("blank nodes break extraction 4", async () => {
const quadsString = `
<https://example.com/ns#testing> a <http://schema.org/Movie>;
<http://purl.org/dc/terms/isVersionOf> <http://yikes.dog/namespaces/movies/Alien>;
<http://www.w3.org/ns/prov#generatedAtTime> "2024-12-03T13:10:42.331Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>;
<http://schema.org/actor> _:b1_n3-0, _:b1_n3-1, _:b1_n3-2, _:b1_n3-3.
`;
const quads = new Parser().parse(quadsString);
const extractor = new CBDShapeExtractor();
const store = RdfStore.createDefault();
quads.forEach(x => store.addQuad(x));
const extracted = await extractor.extract(store, new NamedNode("https://example.com/ns#testing"));

assert.equal(extracted.length, 7);
});
});

0 comments on commit 76a9002

Please sign in to comment.