-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to catch violations with properties that are not defined #215
Comments
It looks to me like you've stumbled into an undesired extension of First, on trying to flag this as an error from inferencing: The ontology you linked is not an OWL ontology, and the nearby OWL transcoding does not include any Neither OWL nor RDFS inferencing using the schema.org ontology (i.e. the RDF Schema or OWL Ontology) would cause new In a purposefully-unimaginative and closed-world style, I could declare that the set of concerts and set of cooking recipes are disjoint. But, that's not encoded in schema.org, so I'd need to write a SHACL rule for my own data. And, respecting imagination and open-world modeling, someone could probably link a video to a counterexample, with a rock band playing while someone's baking a cake. Depending on any other ontology foundations your graph is built on, that concert could rightly get a nutrition value. If you wanted to be really careful with your usage of <urn:example:schema-nutrition-subjects-shape>
a sh:NodeShape ;
sh:or (
[
a sh:NodeShape ;
sh:class schema:MenuItem ;
]
[
a sh:NodeShape ;
sh:class schema:Recipe ;
]
) ;
sh:targetSubjectsOf schema:nutrition ;
. |
Thank you for the prompt reply! If I understand it right, in a few words, schema.org defines what a class is but does not define what a class is not. The use case is this:
In the shape graph, schema:Recipe
a rdfs:Class ;
a sh:NodeShape ;
rdfs:comment "A recipe. For dietary restrictions covered by the recipe, a few common restrictions are enumerated via [[suitableForDiet]]. The [[keywords]] property can also be used to add more detail."^^rdf:HTML ;
rdfs:label "Recipe" ;
rdfs:subClassOf schema:HowTo ;
sh:property schema:Recipe-cookTime ;
sh:property schema:Recipe-cookingMethod ;
sh:property schema:Recipe-ingredients ;
sh:property schema:Recipe-nutrition ;
sh:property schema:Recipe-recipeCategory ;
sh:property schema:Recipe-recipeCuisine ;
sh:property schema:Recipe-recipeIngredient ;
sh:property schema:Recipe-recipeInstructions ;
sh:property schema:Recipe-recipeYield ;
sh:property schema:Recipe-suitableForDiet ;
schema:Recipe-nutrition
a sh:PropertyShape ;
sh:path schema:nutrition ;
sh:class schema:NutritionInformation ;
sh:description "Nutrition information about the recipe or menu item."^^rdf:HTML ;
sh:name "nutrition" ; |
Thanks, it was fun to write and think through.
Yes.
This will likely be very difficult when you start considering subclasses. When I mentioned "Other ontology foundations," I was alluding to how some other ontologies rely on some foundational ontology that divides "Everything" into subsets, and sometimes those subsets are disjoint, sometimes they aren't. For instance, one division drawn from the philosophical literature is endurants vs. perdurants, which behave differently with how they relate to time. (Take thing X. Freeze time. Is X wholly contained in that time slice---an endurant---or must you look outside that time slice to have the full definition of X---a perdurant? My body is an endurant. My life is a perdurant.) Endurants and perdurants are disjoint. If you had those in your ontology near the top (near Placing disjointedness statements in an ontology is unlikely to be, or remain once tried, quick.
The shape I sketched would satisfy this use case.
These shapes prescribe how |
Since I never know what the end user might type, I can't anticipate every misadventure with a shape. |
Unfortunately, IRI typo detection is another hard problem in RDF because of the open-world nature. Think of it from the future-proofing perspective. Also, syntax-check - the way you wrote FWIW, with an ontology community I work with, we introduced a "Concept typo checker" as part of an extension to It might also be possible to do such a concept set with SKOS Concept Schemes if you want a SHACL-oriented solution. But, again, this set of |
FYI: Some more background from a schema.org perspective of the problem is in schemaorg/schemaorg#3408 (comment). |
Quick and practical advice for this and similar data validation tasks: You need to produce your custom SHACL shapes definitions, either manually or derived from the RDFS or OWL vocabulary or vocabularies and maybe manually augmented. Neither OWL nor RDFS are particularly suited for defining constraints regarding the domain or range of properties. After all, that is the entire motivation for the notion of data shapes and shape languages like SHACL; worthwhile reading is e.g. Tim Berners-Lee's piece Linked Data Shapes, Forms and Footprints. |
After a while, I figured out a quick and dirty way to perform the type checking under CWA:
def close_ontology(graph: ConjunctiveGraph):
"""Load an input SHACL shape graph and close each shape
by bringing all property from parent class to currend class shape
then add sh:closed at the end
"""
query = f"""
SELECT DISTINCT ?shape ?parentShape ?parentProp WHERE {{
?shape a <http://www.w3.org/ns/shacl#NodeShape> ;
a <http://www.w3.org/2000/01/rdf-schema#Class> ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>* ?parentShape .
?parentShape <http://www.w3.org/ns/shacl#property> ?parentProp .
FILTER(?parentShape != ?shape)
}}
"""
results = graph.query(query)
visited_shapes = set()
for result in results:
shape = result.get("shape")
parent_prop = result.get("parentProp")
graph.add((shape, URIRef("http://www.w3.org/ns/shacl#property"), parent_prop))
graph.add((shape, URIRef("http://www.w3.org/ns/shacl#closed"), Literal(True)))
# subj sh:ignoredProperties ( rdf:type owl:sameAs )
# https://www.w3.org/TR/turtle/#collections
if shape not in visited_shapes:
ignored_props = graph.collection(BNode())
ignored_props += [URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), URIRef("http://www.w3.org/2002/07/owl#sameAs")]
graph.add((shape, URIRef("http://www.w3.org/ns/shacl#ignoredProperties"), ignored_props.uri))
visited_shapes.add(shape)
# Replace xsd:float with xsd:double
for prop in graph.subjects(URIRef("http://www.w3.org/ns/shacl#datatype"), URIRef("http://www.w3.org/2001/XMLSchema#float")):
graph.set((prop, URIRef("http://www.w3.org/ns/shacl#datatype"), URIRef("http://www.w3.org/2001/XMLSchema#double")))
return graph |
Given the datashape below, which is a json-ld markup:
Given the shape graph, and the ontology,
nutrition
not being a property ofProduct
orThing
, I expect a violation but there wasn't any.I ran using:
I added
sh:closed true
toThing
but I encounter inheritance issues as discussed #167, #141.I tried to follow the recommendation here but then pySHACL reports error:
The text was updated successfully, but these errors were encountered: