Skip to content

Instantly share code, notes, and snippets.

@michaelcpuckett
Last active February 12, 2020 00:18
Show Gist options
  • Save michaelcpuckett/6ec41b45f06219978e9f0d5c55ca2cb6 to your computer and use it in GitHub Desktop.
Save michaelcpuckett/6ec41b45f06219978e9f0d5c55ca2cb6 to your computer and use it in GitHub Desktop.
{
"@context": {
"schema": "http://schema.org/",
"sh": "http://www.w3.org/ns/shacl#",
"as": "https://www.w3.org/TR/activitystreams-core/"
},
"@type": "schema:ReadAction",
"schema:object": {
"@id": "schema:Article"
},
"schema:target": "http://example.com/graph",
"schema:result": {
"@type": "sh:NodeShape",
"sh:targetClass": {
"@id": "as:OrderedCollection"
},
"sh:property": {
"@type": "sh:PropertyShape",
"sh:path": {
"@id": "as:orderedItems"
},
"sh:values": {
"sh:orderBy": {
"sh:nodes": {
"@type": "sh:NodeShape",
"sh:path": [
{
"@id": "schema:interactionStatistic"
},
{
"@id": "schema:userInteractionCount"
}
]
}
}
},
"sh:node": {
"@type": "sh:NodeShape",
"sh:class": {
"@id": "schema:Article"
},
"sh:property": [
{
"@type": "sh:PropertyShape",
"sh:path": {
"@id": "schema:author"
}
},
{
"@type": "sh:PropertyShape",
"sh:path": {
"@id": "schema:headline"
}
},
{
"@type": "sh:PropertyShape",
"sh:path": {
"@id": "schema:interactionStatistic"
},
"sh:node": {
"@type": "sh:NodeShape",
"sh:class": {
"@id": "schema:InteractionCounter"
},
"sh:property": [
{
"@type": "sh:PropertyShape",
"sh:path": {
"@id": "schema:interactionType"
},
"sh:node": {
"@type": "sh:NodeShape",
"sh:class": {
"@id": "schema:CommentAction"
}
}
},
{
"@type": "sh:PropertyShape",
"sh:path": {
"@id": "schema:userInteractionCount"
}
}
]
}
}
]
}
}
}
}
@michaelcpuckett
Copy link
Author

I'm using Schema.org's Actions as a format to make requests. (I'm also considering Hydra.)

So, this ReadAction is a query. There's also UpdateAction and DeleteAction for mutations.

It's querying for all Articles, from a /graph endpoint. The articles are wrapped in an ActivityStream ordered collection (also similar in Hydra).

The Articles are also from Schema.org. I don't want to get back everything an Article has, so I ask for the author and headline properties. I also want the comment count.

Then I want to sort all the articles by comment count. I have read in the Advanced Features section about orderBy. I can't tell if I can apply it as I have above, directly on a Shape, or if I need to include it as Triple Rule, i.e.,

{
  "@type": "sh:TripleRule",
  "sh:subject": "sh:this",
  "sh:predicate": "???",
  "sh:object": {
      "sh:orderBy": { ... }
   }
}

@HolgerKnublauch
Copy link

This goes beyond what the SHACL spec says or what SHACL has been originally designed for. RDF data is inherently unordered. So you can make up the semantics of ordering as you want. I guess you could just as well introduce your own property instead of sh:orderBy, since then you don't really need to pay attention to the whole complexity of triple rules etc.

If you want to define property shapes to "walk" down a structure, using sh:node, then you'd only really need target statements for the root level, not the nested ones like "sh:targetClass": "schema:InteractionCounter" IMHO.

FWIW we heavily use Property Value Rules https://w3c.github.io/shacl/shacl-af/#PropertyValueRule to dynamically compute values, and those support sh:orderBy too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment