sttl.datashape.path.sparqlvalidp.rq Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of corese-core Show documentation
Show all versions of corese-core Show documentation
Corese is a Semantic Web Factory (triple store and SPARQL endpoint) implementing RDF, RDFS, SPARQL 1.1
Query and Update.
#
# SPARQL Based Constraint
# Evaluate SPARQL query with pre-bind of variable $this with focus nodes
# SPARQL query returns solutions that fail the Constraint
#
prefix sh:
template sh:sparqlvalidp (?shape, ?sh, ?vis, ?s, ?p, ?oper, ?obj, ?o) {
sh:safe(?shape, ?sh, ?suc)
}
where {
graph ?shape {
?cst sh:parameter [ sh:path ?oper ] ;
sh:propertyValidator ?valid
?valid sh:select ?q
filter not exists { ?cst sh:deactivated true }
# collect prefix definitions
# TBD: do it once and record it
{
select ?valid
(group_concat(concat("prefix ", ?pr, ": <", str(?ns), ">") ; separator="\n")
as ?define)
where {
?valid sh:prefixes ?ns
[] sh:declare [ sh:prefix ?pr ; sh:namespace ?ns ]
}
group by ?valid
}
}
bind (
concat(?define, replace(?q, "\\$PATH", sh:display(?shape, ?p)), sh:values(sh:variable(?oper)))
as ?qq)
#filter xt:display(?qq)
values ($this ?value) {
unnest(kg:sparql(?qq, "$this", ?s, sh:variable(?oper), ?obj))
}
# SPARQL query returns solutions that fail
bind (false as ?suc)
bind (st:report(sh:sparql, ?cst, ?shape, ?s, ?p, ?value, ?suc, ?vis) as ?b)
}
function sh:display(?shape, ?p) {
if (isURI(?p), st:turtle(?p), st:apply-templates-with-graph(st:dspprint, ?shape, ?p))
}
function sh:variable(?uri) {
concat("?", st:strip(?uri))
}
# pseudo declare variables in case they are not in a triple of query ?q
function sh:values(?oper){
concat("values (?this ", ?oper, ") { (UNDEF UNDEF) }")
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy