sparql-inferenced
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

sparql-inferenced

An RDF inferencer that extends the HyLAR inferencing engine to allow inferencing with SPARQL Construct queries

Usage

import inferencer from 'sparql-inferenced'
import { Store, Parser } from 'n3';
import { owl2rl } from 'hylar-core';
import constructInferences from 'construct-inferences-shacl';
import * as fs from 'fs'

const parser = new Parser();

const ontologyQuads = parser.parse(
  fs.readFileSync(/* Path to SHACL ontology */).toString()
);

const shaclConstraint = parser.parse(`
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

ex:myShape a sh:NodeShape ;
  sh:property [
    sh:path foaf:friend ;
  ] .
`)

const SHACLInferences = [...constructInferences, `
PREFIX ex: <http://example.org#>

CONSTRUCT {
	?s ex:myCustomConstraint false
} WHERE {
  ?s a sh:PropertyShape
  FILTER(NOT EXISTS { ?s ex:myCustomConstraint ?o })
}
`]

(async () => {
  // Store to hold explicitly loaded triples
  const explicit = new Store();
  // Store to hold implicitly loaded triples
  const implicit = new Store();

  await inferencer(ontologyQuads, [], explicit, implicit, owl2rl, SHACLInferences)
  await inferencer(shaclConstraint, [], explicit, implicit, owl2rl, SHACLInferences)

  /**
   * Implicit now contains inferenced triples including
   * 
   * ex:myShape sh:closed false (from Construct inferences)
   * _b:1 a sh:PropertyShape ;   (from owl2rl inferences)
   *   sh:order 0 ;             (from Construct inferences)
   *   sh:minCount 0 .          (from Construct inferences) 
   */

})

Future work

Package Sidebar

Install

npm i sparql-inferenced

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

13.6 kB

Total Files

5

Last publish

Collaborators

  • jeswr