SHACL SPARQLTarget not validating the SPARQL query output nodes - sparql

I have a NodeShape with a sh:SPARQLTarget . I tried to run the Target SPARQL query in an ontology editor and it delivered results, but when I'm executing the same query in my custom target node shape in sh:select, it won't validate the target nodes returned by the SPARQL query. I am using pySHACL. Did I do something wrong? I'm out of ideas. Here is my Nodeshape and data graph:
I have used “” for sh:select instead of “”” “””, since I am defining the shapes_graph as a variable in my python code and it is already encoded in """ """. I have also enabled meta_shacl=True in pyShacl to ensure that my shapes_graph is valid. Also the nodeShape (snomed:dob363698007Shape) works well when provided with a normal TargetClass or TargetNode. What am I missing?
I have already referred SPARQLRule not constructing
**NodeShape**
snomed:
sh:declare [
sh:prefix "snomed" ;
sh:namespace <http://localhost:8890/snomed/> ;
] .
snomed:dob363698007Shape
a sh:NodeShape ;
sh:target [
a sh:SPARQLTarget ;
sh:prefixes snomed: ;
sh:select "SELECT ?this WHERE { ?node a snomed:24078009.?node a snomed:dob .?node snomed:609096000 ?this.?this a snomed:dob363698007 .bind(?node as ?conceptName).bind(?this as ?RGName) .FILTER(REGEX(strafter(xsd:string(?RGName),'snomed/'),strafter(xsd:string(?conceptName),'snomed/')) ).}";
] ;
sh:property [
sh:path snomed:363698007;
sh:minCount 1;
].```
**Data Graph**
```snomed:dob a rdfs:Class,snomed:dob ;
rdfs:label "Semantic Pattern dob"^^xsd:string ;
snomed:609096000 snomed:dob363698007 .
snomed:dob363698007 a rdfs:Class,snomed:dob363698007;
snomed:363698007 snomed:123037004 .
snomed:24078009 a rdfs:Class, snomed:24078009, snomed:dob;
rdfs:label "Gangosa of yaws (disorder)"^^xsd:string ;
snomed:609096000 snomed:24078009_3,snomed:24078009_5,snomed:24078009_6;
rdfs:subClassOf snomed:128349005,
snomed:140004,
snomed:177010002,
snomed:312118003,
snomed:312129004,
snomed:312422001,
snomed:363166002,
snomed:47841006,
snomed:88037009 .
snomed:24078009_3 a rdfs:Class, snomed:24078009_3, snomed:dob363698007 ;
snomed:263502005 snomed:90734009 .
snomed:24078009_5 a rdfs:Class, snomed:24078009_5,snomed:dob363698007;
snomed:116676008 snomed:110435003 ;
snomed:246075003 snomed:6246005 ;
snomed:363698007 snomed:71836000 ;
snomed:370135005 snomed:441862004 .
snomed:24078009_6 a rdfs:Class, snomed:24078009_6,snomed:dob363698007 ;
snomed:116676008 snomed:110435003 ;
snomed:246075003 snomed:6246005 ;
snomed:363698007 snomed:72914001 ;
snomed:370135005 snomed:441862004 .

I've put your shacl shapes file and data graph into PySHACL to isolate the issue you are seeing.
There are two problems with your given setup that I have found.
Firstly, SPARQL-Based Targets is a feature from the SHACL Advanced Specification. PySHACL does not enable the Advanced-Spec features by default. You can enable "advanced mode" by passing advanced=True to the validation module, or -a or --advanced on the commandline tool.
That is the main reason your SPARQL target was not selecting the nodes you expected.
Next, after enabling advanced mode, you will see that PySHACL fails when loading your SHACL Shape Graph. That is because your prefix namespace is not declared correctly.
See the examples in the SPARQL-Prefixes section of the Spec document. The specification states
"The values of sh:namespace are literals of datatype xsd:anyURI."
Your sh:namespace is a URIRef, not a Literal. Changing the namespace declaration to the following, fixes the error.
sh:namespace "http://localhost:8890/snomed/"^^xsd:anyURI ;
I've run PySHACL with the corrected Shapes Graph, and it works as expected.
See this code for a complete working example: https://gist.github.com/ashleysommer/a319beeef33973906b76711675b2635c

Related

Does graphdb support rdf-star syntax?

Consider example2 from the W3C's RDF* specification:
https://w3c.github.io/rdf-star/cg-spec/editors_draft.html
#prefix : <http://www.example.org/> .
:employee38
:familyName "Smith" ;
:jobTitle "Assistant Designer" {| :accordingTo :employee22 |} .
# this is equivalent to:
#
# :employee38
# :familyName "Smith" ;
# :jobTitle "Assistant Designer" .
# << :employee38 :jobTitle "Assistant Designer" >> :accordingTo :employee22 .
But when I tried in GraphDB, it didn't support the former syntax, and the latter did.
Whether graphdb does not support syntax like {|... |} ?
Currently GraphDB currently doesn't support syntax like {|..|}. We've adopted the embedded triples approach, but it's something we think should think of for the future release.

How do I refer to a SHACL rule file in a Fuseki configuration?

I want Fuseki sparql endpoint to infer new triples using SHACL rules in a file "rules.ttl".
From documentation in https://jena.apache.org/documentation/shacl/index.html
<#serviceInMemoryShacl> rdf:type fuseki:Service ;
rdfs:label "Dataset with SHACL validation" ;
fuseki:name "ds" ;
fuseki:serviceReadWriteGraphStore "" ;
fuseki:endpoint [ fuseki:operation fuseki:shacl ; fuseki:name "shacl" ] ;
fuseki:dataset <#dataset> ;
Is there some place in the syntax above to refer to the rules.ttl file?

OWL Inference problems using max cardinality in restriction class

I have created an ontology in protege. I am using the Pellet reasoner (it is enabled) and the snap sparql plugin.
I am trying to declare a small enterprise as an enterprise that has at most 20 employees.
Here are my triples. I am not able to see the inference that cs:SmithBrothers is a cs:SmallEnterprise (by the way of SPARQL query). Can someone please help me? I have been at this literally all day.
# employs
cs:employs a owl:ObjectProperty ;
rdfs:range cs:employee ;
rdfs:domain cs:enterprise .
# is-employed-by (the inverse of employs)
cs:isEmployedBy a owl:ObjectProperty ;
owl:inverseOf cs:employs .
# j. A small enterprise is an enterprise which employs at most 20 employees.
cs:smallEnterprise a owl:class ;
owl:equivalentClass [
owl:intersectionOf (
[ a owl:Restriction ;
owl:onProperty cs:employs ;
owl:maxCardinality 20 ]
cs:enterprise
)] .
# x. SmithBrothers is a family-based enterprise.
cs:SmithBrothers a cs:enterprise .
# y. Frank, Lea, Dave, Kate, Dino are employed by SmithBrothers.
cs:Frank cs:isEmployedBy cs:SmithBrothers .
cs:Lea cs:isEmployedBy cs:SmithBrothers .
cs:Dave cs:isEmployedBy cs:SmithBrothers .
cs:Kate cs:isEmployedBy cs:SmithBrothers .
cs:Dino cs:isEmployedBy cs:SmithBrothers .
#########################################
Thanks in advance.

When I running gh-rdf3x engine's commend rdf3xquery It prompt:parse error: unknown prefix 'http'

I try to use gh-rdf3x engine to do some SPARQL search, so I use LUBM-100 dataset and then I use RDF2RDF tool to make all .owl file into a test.nt file.
then I use gh-rdf3x command
./rdf3xload dataDB test.nt
to build a dataDB file. At last, I want to do some search so I use LUBM SPARQL#1 as test.sparql.
Then I do the command
./rdf3xquery dataDB test.sparql
It prompts
parse error: unknown prefix 'http'
I do all the thing as described in the GH-RDF3X Wiki, so I don't know why it prompt that.
And the message may be from file gh-rdf3x/cts/parser/TurtleParser.cpp
Thank you for your help.
I guess you're using the LUBM query from this file which unfortunately contains several syntax errors.
The first query is missing the angle brackets < and > which must be put around full URIs:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#>
SELECT ?X WHERE {
?X rdf:type ub:GraduateStudent .
?X ub:takesCourse <http://www.Department0.University0.edu/GraduateCourse0>
}

Is it possible to query inferred Einstein Riddle knowledge from OWLIM?

I have OWLIM repository populated with Einstein Riddle owl.
Link1 - Link2. Is it possible to query inferred knowledge from OWLIM using sparql ? To get same results as on individual tab in Protege ?
SPARQL:
PREFIX riddle: <http://www.iis.nsk.su/persons/ponom/ontologies/einsteins_riddle_en.owl#>
SELECT DISTINCT ?kto ?co
WHERE {
?kto riddle:drinks ?co .
?kto a owl:Thing .
?co a owl:Thing .
Protege and OWLIM have same result, only explicit knowledge.
co kto
---------------------------------------------
http://www.iis.nsk.su/persons/ponom/ontologies/einsteins_riddle_en.owl#tea http://www.iis.nsk.su/persons/ponom/ontologies/einsteins_riddle_en.owl#Ukrainian
But (according to my information) in Protege, SPARQL query works only on existing knowledge and OWLIM build up repository with existing and inferred triples. So I expected inferred triples too.
P.S.:
Query to get count of inferred triples (OWLIM):
SELECT (COUNT(*) as ?count)
FROM <http://www.ontotext.com/implicit>
WHERE {
?s ?p ?o .
}
returns 0.
** ** ** EDIT: ** ** **
My configuration:
#
# Sesame configuration template for a owlim repository
#
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
#prefix rep: <http://www.openrdf.org/config/repository#>.
#prefix sr: <http://www.openrdf.org/config/repository/sail#>.
#prefix sail: <http://www.openrdf.org/config/sail#>.
#prefix owlim: <http://www.ontotext.com/trree/owlim#>.
[] a rep:Repository ;
rep:repositoryID "Riddle" ;
rdfs:label "Einstein Riddle Getting Started" ;
rep:repositoryImpl [
rep:repositoryType "openrdf:SailRepository" ;
sr:sailImpl [
sail:sailType "owlim:Sail" ;
owlim:base-URL "http://www.iis.nsk.su/persons/ponom/ontologies/einsteins_riddle_en.owl#" ;
# There must be exactly the same number of semicolon separated entries in
# the defaulNS and imports fields
owlim:defaultNS "http://www.iis.nsk.su/persons/ponom/ontologies/einsteins_riddle_en.owl#" ;
owlim:imports "./ontology/zebra.owl" ;
owlim:entity-index-size "5000000" ;
owlim:repository-type "file-repository" ;
owlim:ruleset "owl-max" ;
owlim:storage-folder "storage" ;
# OWLIM-SE parameters
owlim:cache-memory "180m" ;
# OWLIM-Lite parameters
owlim:noPersist "false" ;
# Other OWLIM-SE parameters
# owlim:enable-context-index "false" ;
owlim:check-for-inconsistencies "true" ;
# owlim:disable-sameAs "false" ;
owlim:enable-optimization "true" ;
owlim:enablePredicateList "true" ;
# owlim:entity-id-size "32" ; # 32/40
# owlim:fts-memory "20m" ;
# owlim:ftsIndexPolicy "never" ; # never/onStartup/onShutdown/onCommit
# owlim:ftsLiteralsOnly "false" ;
# owlim:in-memory-literal-properties "false" ;
# owlim:enable-literal-index "true" ;
# owlim:index-compression-ratio "-1" ; # -1/10-50
# owlim:owlim-license "" ;
# owlim:predicate-memory "80m" ;
# owlim:query-timeout "-1" ;
# owlim:tokenization-regex "[\p{L}\d_]+" ;
# owlim:tuple-index-memory "80m" ;
# owlim:useShutdownHooks "true" ;
# owlim:transaction-mode "safe" ;
# owlim:read-only "false" ;
# Other OWLIM-Lite parameters
# owlim:jobsize "1000}" ;
# owlim:new-triples-file ""
]
].
And it doesn't matter if I use owl2-rl or owl2-ql or w/e else. Always same result. Only number of inferred triples changes to positive.
08:51:40 Executing query 'Who drinks What'
co kto
---------------------------------------------
einsteins_riddle_en:tea einsteins_riddle_en:Ukrainian
08:51:40 1 result(s) in 63ms.
08:51:40 Executing query 'Number of inferred triples'
count
---------------------------------------------
"770"^^<http://www.w3.org/2001/XMLSchema#integer>
Inferred triples are useless for me, sample of them:
p s o
---------------------------------------------
rdf:type rdf:type rdf:Property
rdf:type rdfs:subPropertyOf rdf:Property
rdf:type rdfs:subClassOf rdf:Property
rdf:type rdfs:domain rdf:Property
rdf:type rdfs:range rdf:Property
rdf:type owl:equivalentClass rdf:Property
rdf:type psys:transitiveOver rdf:Property
...
Yes, this is possible, but it depends on how your OWLIM repository is configured.
The inference ruleset that OWLIM uses is set as a configuration parameter when you first create your repository - see the configuration documentation for details. Obviously, if you have set it to use an empty ruleset, it will do no inference at all. Depending on which ruleset you pick (there are several levels of expressivity), it will be able to infer more or less entailed triples (the more expressive the ruleset, the more entailed information).
If your OWLIM repository is configured correctly, queries will automatically retrieved inferred information along with the explicit statements.
Of course, it also depends on whether there actually is anything that can be inferred. The fact that your query gives the same result in Protege and OWLIM might simply mean that OWLIM does do inferencing, but didn't find any inferred information that matches your query.