Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Wright committed Nov 20, 2020
1 parent 409cb62 commit cdb7f52
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/actor-init-sparql/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ index-browser.js
index-browser.js.map
*.sparql
dist
test/system/assets/
7 changes: 7 additions & 0 deletions packages/actor-init-sparql/test/ActorInitSparql-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,13 @@ describe('ActorInitSparql', () => {
});
});

it('should correctly convert skolemized blank nodes in SPARQL queries', () => {
return expect(actor.query(`
SELECT ?label WHERE {
<urn:comunica_skolem:source_0:nodeID://b12796> <http://www.w3.org/2000/01/rdf-schema#label> ?label.
}`)).resolves.toBeTruthy();
});

it('bindings() should collect all bindings until "end" event occurs on triples', async() => {
const ctx = { sources: []};
const result = await actor.query('SELECT * WHERE { ?s ?p ?o }', ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ export class FederatedQuadSource implements IQuadSource {
* @return If the given term was a blank node, this will return a skolemized named node, otherwise the original term.
*/
public static skolemizeTerm(term: RDF.Term, sourceId: string): RDF.Term | BlankNodeScoped {
const value = /[\da-z]+$/ui.exec(term.value)?.[0];
if (term.termType === 'BlankNode') {
return new BlankNodeScoped(`bc_${sourceId}_${term.value}`,
DF.namedNode(`${FederatedQuadSource.SKOLEM_PREFIX}${sourceId}:${term.value}`));
return new BlankNodeScoped(`bc_${sourceId}_${value}`,
DF.namedNode(`${FederatedQuadSource.SKOLEM_PREFIX}${sourceId}:${value}`));
}
return term;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ describe('FederatedQuadSource', () => {
expect((<BlankNodeScoped> FederatedQuadSource.skolemizeTerm(DF.blankNode('abc'), '0')).skolemized)
.toEqualRdfTerm(DF.namedNode('urn:comunica_skolem:source_0:abc'));
});

it('should change a blank node of form nodeID://b12796', () => {
expect(FederatedQuadSource.skolemizeTerm(DF.blankNode('nodeID://b12796'), '0'))
.toEqualRdfTerm(DF.blankNode('urn:comunica_skolem:source_0:b12796'));
expect((<BlankNodeScoped> FederatedQuadSource.skolemizeTerm(DF.blankNode('nodeID://b12796'), '0')).skolemized)
.toEqualRdfTerm(DF.namedNode('urn:comunica_skolem:source_0:b12796'));
});
});

describe('#skolemizeQuad', () => {
Expand Down

0 comments on commit cdb7f52

Please sign in to comment.