-
Notifications
You must be signed in to change notification settings - Fork 54
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
How to Document Properties and Cardinalities Defined in SHACL Shapes? #104
Comments
@lambdamusic Hi, I realised that I could solve my problem partially by extracting some information from the SHACL shapes and using this for the docs generation: ...,
{
"@id": "schema:email",
"@type": "rdf:Property",
"schema:domainIncludes": {
"@id": "schema:Person"
},
"schema:rangeIncludes": {
"@id": "xsd:string"
},
"rdfs:comment": "Email address.",
"rdfs:label": "email"
},
... However, I am still wondering how to display the cardinalities or additional info like sh:pattern etc. Could you guide me how to adjust the template or just point out an example? That'd be a great help! Thanks a lot for this cool tool. |
Would it possible to customise https://github.com/lambdamusic/Ontospy/blob/d23a17544c9c20039b9ce4ab051f8aebfc5a45b6/ontospy/ontodocs/media/templates/html-multi/browser/browser_classinfo.html? If yes, how would I get more information from the internal representation of the ontology? |
Ontospy doesn't really process SHACL shapes at the moment (apart from highlighting their links to classes). At the very leart, I suppose you'd have to add a shapes extractor in Do you have a sample file you can share for testing? |
Hi there
Yes, this is what I noticed. For now, I generate the ontology from the shapes and then use this for Ontospy to generate the docs. Example:SHACL shape for schema:Thing {
"@context": {
"owl": "http://www.w3.org/2002/07/owl#",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"skos": "http://www.w3.org/2004/02/skos/core#",
"prov": "http://www.w3.org/ns/prov#",
"dcat": "http://www.w3.org/ns/dcat#",
"sh": "http://www.w3.org/ns/shacl#",
"shsh": "http://www.w3.org/ns/shacl-shacl#",
"dcterms": "http://purl.org/dc/terms/",
"schema": "http://schema.org/",
"rescs": "http://rescs.org/"
},
"@graph": [
{
"@id": "rescs:dash/thing/ThingShape",
"@type": "sh:NodeShape",
"rdfs:comment": {
"@type": "xsd:string",
"@value": "The most generic type of item."
},
"rdfs:label": {
"@type": "xsd:string",
"@value": "Thing"
},
"sh:property": [
{
"sh:datatype": {
"@id": "xsd:string"
},
"sh:description": "An alias for the item.",
"sh:maxCount": {
"@type": "xsd:integer",
"@value": 1
},
"sh:name": "alternateName",
"sh:path": {
"@id": "schema:alternateName"
}
},
{
"sh:datatype": {
"@id": "xsd:string"
},
"sh:description": "A description of the item.",
"sh:maxCount": {
"@type": "xsd:integer",
"@value": 1
},
"sh:name": "description",
"sh:path": {
"@id": "schema:description"
}
},
{
"sh:description": "The identifier property represents any kind of identifier for any kind of [[Thing]], such as ISBNs, GTIN codes, UUIDs etc. Schema.org provides dedicated properties for representing many of these, either as textual strings or as URL (URI) links. See [background notes](/docs/datamodel.html#identifierBg) for more details.",
"sh:maxCount": {
"@type": "xsd:integer",
"@value": 1
},
"sh:name": "identifier",
"sh:or": {
"@list": [
{
"sh:datatype": {
"@id": "xsd:string"
}
},
{
"sh:nodeKind": {
"@id": "sh:IRI"
}
}
]
},
"sh:path": {
"@id": "schema:identifier"
}
},
{
"sh:description": "An image of the item.",
"sh:maxCount": {
"@type": "xsd:integer",
"@value": 1
},
"sh:name": "image",
"sh:nodeKind": {
"@id": "sh:IRI"
},
"sh:path": {
"@id": "schema:image"
}
},
{
"sh:datatype": {
"@id": "xsd:string"
},
"sh:description": "The name of the item.",
"sh:maxCount": {
"@type": "xsd:integer",
"@value": 1
},
"sh:minCount": {
"@type": "xsd:integer",
"@value": 1
},
"sh:name": "name",
"sh:path": {
"@id": "schema:name"
}
},
{
"sh:description": "URL of a reference Web page that unambiguously indicates the item's identity. E.g. the URL of the item's Wikipedia page, Wikidata entry, or official website.",
"sh:name": "sameAs",
"sh:nodeKind": {
"@id": "sh:IRI"
},
"sh:path": {
"@id": "schema:sameAs"
}
},
{
"sh:description": "URL of the item.",
"sh:maxCount": {
"@type": "xsd:integer",
"@value": 1
},
"sh:name": "url",
"sh:nodeKind": {
"@id": "sh:IRI"
},
"sh:path": {
"@id": "schema:url"
}
}
],
"sh:targetClass": {
"@id": "schema:Thing"
}
}
]
} I added a manually coded definition for {
"@id": "schema:Thing",
"@type": "rdfs:Class"
} and then from the shapes I extracted this information (here an example for the property {
"@id": "schema:name",
"@type": "rdf:Property",
"schema:domainIncludes": {
"@id": "schema:Thing"
},
"schema:rangeIncludes": {
"@id": "xsd:string"
},
"rdfs:comment": "The name of the item.",
"rdfs:label": "name"
} This is rather a workaround so I can generate the docs in the "traditional" way from the ontology. |
Is there a way to also include the cardinalities in the "traditional" way? I guess the SHACL cardinalities would have to be converted to OWL cards. However, I am not sure if SHACL cards can be converted to OWL cards and vice-versa without loss of information. Do you have an example of OWL cards being documented? |
Yes, I can have a look if I understand how this could work. Unfortunately at the moment I don't have the time to come up with a PR implementing support for SHACL. But I think I could assist you in specifying this feature and then help with smaller specific tasks. Maybe you could explain me how modular this design could be. Is there a way to decouple some things from the Ontospy package so users could use their own config without having to change the source (e.g., templating, custom Python classes for the internal repr.)? |
@lambdamusic Would it be possible to discuss this feature request sometime early next year? I'd propose the following priorities:
I am happy to help and provide some code. However, I need some guidance to make this efficient. |
Hi Tobias, thanks for contributing. I'm happy to discuss more, in the new year. FYI right now there is already an active PR that is intended to add various functionalities for SHACL processing. That might address some of your requirements - so feel free to take a look and comment if you like. In general, I'd rather finish up integrating that code, before adding more SHACL support. |
@lambdamusic That sounds great. I'll have look at the PR this week. I wish you a great 2022 :-) |
I installed ontospy-2.0.0a0 and tried with my shapes graph. I can now see a new category "Property Shapes" or "Shape Properties" along with their cardinalities: @lambdamusic @ajnelson-nist Overall, this looks great! Thanks a lot for your effort! I have a few questions:
Please let me know in case I can help with something. |
sidenote: |
@tobiasschweizer - thank you for the kind words. I have a short answer about If If I think what the SHACL display testing really needs next is a test suite of many small ontologies specific to certain SHACL features. It's not immediately obvious to me what the right presentation is for some cases, e.g. @lambdamusic - if many small SHACL feature-test files would be helpful, in what directory under |
It is in fact an asterisk as I can see now :-) If I was 20 years younger I'd have seen it right away ;-) |
Querying lists in RDF seemed quite cumbersome to me. Especially when their length is not known. Let me know if you come up with a good way. Not sure if this may help: http://www.snee.com/bobdc.blog/2014/04/rdf-lists-and-sparql.html (Retrieving all the members). The example applies property path syntax. (I got the author's book many years ago) |
I can't think offhand of a better way than what was done in that snee post. For the needs of this repository, a general list function could be added to take a list's head identifier and turn it into a Python list of Meanwhile, in your screenshot about a grants shape, it's a non-trivial tree of |
Thanks for asking! We are using a system which supports SHACL but not RDF(S) inference. This is why we make use of To build the docs, however, there is an additional ontology file which just hardcodes those class relations. And there is a build process which collects the single SHACL shape definitions and puts them in a graph along with the ontology file. Properties are dynamically filled into the ontology definitions to avoid too much redundancy. See https://github.com/Connectome-Consortium/rescs_shacl_shapes#use-with-standard-tools for more details. (There is even a script which gets rid of In short: Because of the ontology file stating the class relations the I am not sure how generic that support for |
I think How do you think I suggest a small ontology be used as an initial exemplar. Hopefully the citation pattern inlined here shows the source sufficiently well: @prefix ex: <http://example.com/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
ex:PersonAddressShape
a sh:NodeShape ;
rdfs:seeAlso <https://www.w3.org/TR/shacl/#OrConstraintComponent> ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:address ;
sh:or (
[
sh:datatype xsd:string ;
]
[
sh:class ex:Address ;
]
)
] . |
That's right.
I have no particular requirements regarding HTML. I think the example above could be rendered like "schema:rangeIncludes": [
{
"@id": "schema:Person"
},
{
"@id": "schema:Organization"
}
] However, I am not sure how |
I have just noticed that you referred to https://www.w3.org/TR/shacl/#OrConstraintComponent as well ;-) I meant this one: ex:OrConstraintExampleShape
a sh:NodeShape ;
sh:targetNode ex:Bob ;
sh:or (
[
sh:path ex:firstName ;
sh:minCount 1 ;
]
[
sh:path ex:givenName ;
sh:minCount 1 ;
]
) . |
@ajnelson-nist Let me know if I can help with anything. |
I will be on vacation in August and I am looking forward to doing some work here in September :-) |
@tobiasschweizer Given scattered summer availabilities, we're probably still at the strategy-level thinking on this. I think the right strategy is to start systematically exercising SHACL capabilities as they are demonstrated in the SHACL specification document. I borrowed a snippet and included a So, the snippet I excerpted could go into: And then the test framework could loop through that folder ( The design work can then be isolated to handle each the SHACL informative examples. If we're lucky, the designs for each of the samples we need would compose when we start combining features like your chain of How does that sound as a way forward? |
@ajnelson-nist Thanks for your message. Yes, that sounds very systematical and allows us to do one step at a time, not getting wound up in SHACL's complexity from the beginning. In September, we could try working on this and split the tasks a bit once we are sure about the basic setup. Have a good summer! |
Hi there
First of all: nice tool!
I have the following use case: I define SHACL Shapes to define a subset of schema.org types (classes) and properties (following https://datashapes.org/schema).
What I get looks like this:
In the addition to the SHACL shapes, I added a few RDF(S) definitions to the graph:
Then I do:
ontospy gendocs graph.json
, then option 2 (Html multi page)Question: Is there a way to display the properties, their ranges and cardinalities that are defined in the SHACL shapes along with the class?
So far, the properties only show up if they are defined along with
schema:domainIncludes
(which is somehow redundant because this is also stated in the shapes).Ontospy already recognises the relation between the shape and its target class so I wonder if it could include more information from the shape.
Thanks a lot!
The text was updated successfully, but these errors were encountered: