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

Fix/35 #36

Merged
merged 2 commits into from
Dec 3, 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
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);
});
});
Loading