Skip to content

semantifyit/sparql-property-paths

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPARQL Property Path Engine

Minimal engine to execture SPARQL property-paths (https://www.w3.org/TR/sparql11-query/#propertypaths) agains a turtle/jsonld document and a given starting node.

Implemented with help of https://github.com/RDFLib/rdflib .

Example

const { SPPEvaluator } = require("sparql-property-paths");

(async () => {
  const [evalPP] = await SPPEvaluator(
    `
    prefix p: <http://ex.com/>
    p:a p:x p:b .
    p:b p:y p:c .
    p:c p:str "hello" .`,
    "turtle",
  );
  const ppathPrefixes = { p: "http://ex.com/" };

  const results = evalPP("http://ex.com/a", "p:x/p:y", ppathPrefixes);

  const str = evalPP(results[0], "p:str", ppathPrefixes);

  console.log(str);
})();

Installation

Currently not on npm-registry, install with git:

npm i git+https://github.com/semantifyit/sparql-property-paths

Then simply require with

const { SPPEvaluator } = require("sparql-property-paths");

API (Typescript signatures)

SPPEvaluator

type OutFn = (base: string, spp: string, prefix?: Record<string, string>) => string[];

const SPPEvaluator = (str: string, type: "jsonld" | "ttl"): Promise<[OutFn, Graph]>;

Known issues

  • nested * + ? selectors might produce duplicates. (e.g. test case pp37)
  • negated inverse property paths produce wrong results (e.g. !^:p)

About

SPARQL property paths evaluator engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published