Skip to content

Instantly share code, notes, and snippets.

@cristianvasquez
Created May 31, 2024 08:42
Show Gist options
  • Save cristianvasquez/9b8b138814076557c24f33660c6cd831 to your computer and use it in GitHub Desktop.
Save cristianvasquez/9b8b138814076557c24f33660c6cd831 to your computer and use it in GitHub Desktop.
Walkaround Model2Owl
import { n3reasoner } from 'eyereasoner'
import { readFileSync, writeFileSync } from 'fs'
export const queryString = `
@prefix sh: <http://www.w3.org/ns/shacl#> .
{ ?shape sh:property ?property } => { ?shape sh:property ?property }.
`
const shaclFile = readFileSync('reasoning/shapes.ttl', 'utf-8')
// If a child subclasses from parent
// Then it's shape inherits it's properties
export const dataString = `
${shaclFile}
{
?child rdfs:subClassOf ?parent .
?parentShape a sh:NodeShape ;
sh:targetClass ?parent ;
sh:property ?parentProperty .
?childShape a sh:NodeShape ;
sh:targetClass ?child .
} => {
?childShape sh:property ?parentProperty .
}.
`
const result = await n3reasoner(dataString, queryString)
writeFileSync(
'reasoning/shapes-inf.ttl', result)
/**
Note this is equivalent to:
PREFIX shacl: <http://www.w3.org/ns/shacl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?childShape shacl:property ?parentProperty .
}
WHERE {
GRAPH ?g {
?child rdfs:subClassOf* ?parent .
?parentShape a shacl:NodeShape ;
shacl:targetClass ?parent ;
shacl:property ?parentProperty .
?childShape a shacl:NodeShape ;
shacl:targetClass ?child .
}
}
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment