-
Notifications
You must be signed in to change notification settings - Fork 823
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
Closed-world approach to SHACL shape for schema.org #3408
Comments
I do not think we should add any constraints using OWL axioms (e.g. disjointness axioms etc.), for the following reasons:
As for SHACL: IMO, what would be a good approach was if one set of authoritative SHACL shapes for classes and properties was automatically produced for each release and added to a release as a separate resource. There are some tools (not tested them myself) that might help with that task (this will require adding support for the schema-specific domain and range properties): Hope you find this long ;-) comment useful! |
For future readers who require citation, here is one:
|
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 |
This issue is being nudged due to inactivity. |
I encountered this problem:
RDFLib/pySHACL#215
In summary, I purposefully generated an erroneous markup where
nutrition
is part ofProduct
and used pySHACL to validate it. Because of the lack of constraint, pySHACL could not infer that. The issue arises from the open-world nature of RDF, and SHACL rules can be used to constrain the usage ofschema:nutrition
to specific classes if a more closed-world approach is desired.Is there a possibility to further refine the OWL ontology for schema.org?
The text was updated successfully, but these errors were encountered: