Description
During discussions on Framing and Query some use cases were shown where a greater amount of query capability would be useful than that available through the (current) framing algorithm. Dave Longley pointed to GraphQL as being a useful paradigm, which is in realy use in APIs. I (@gkellogg) pointed out that, as the JSON-LD data model is RDF, SPARQL is a natural query language, perhaps with a JSON syntax.
Ultimately, the discussion converged on completing the existing framing model, and possibly looking into more powerful query at a later date in a separate specificaiton.
One consideration from this is that the framing syntax could, perhaps, be better described using structures that could be more congruent with query models. For example, consider the framing keywords:
@embed
– determines how/if nodes are embedded as property values, or referenced.@explicit
– determines if only those properties contained in the frame are used in output, or if all properties are used.@omitDefault
– Causes default values to be ignored.@requireAll
– Requires all properties in frame to be present in node for match.
Embedding can be inferred by the frame using an embedded node syntax, in which case the framed result would be included. For examples:
{
"@context": {},
"@type": "Library",
"contains": {
"@id": {}
}
}
Would determine both that values of "contains" must be a node, and that those values be embedded.
For explicit output, adding a wildcard property values would be consistent with a SPARQL pattern such as the following:
?subj ?pred ?obj
Which would match on any property. A frame such as the following would include properties not specified within the frame explicitly:
{
"@context": {},
"@type": "Library",
"contains": {"@id": {}},
"@any": {}
}
Omit default does not seem too useful, since the frame author can simply not include default values.
The @requireAll
flag might be better used with explicit optional output, which would be more consistent with the SPARQL OPTIONAL
mechanism (left join). For example:
{
"@context": {},
"@type": "Library",
"dc:title": {"@optional": {}},
"contains": {"@id": {}}
}
Might indiciate that dc:title
is not necessary for frame matching, but included in output if it exists; this could also include other sub-patterns, which may prevent things matching (for instance, if the @language
doesn't match). This roughly would be equivalent to the following SPARQL:
WHERE {
?lib a :Library;
:contains a ?book .
OPTIONAL {
?lib dc:title ?title
}
}
Groups of properties could be included together in an @optional
block at the node level:
{
"@context": {},
"@type": "Library",
"contains": {"@id": {}},
"@optional": {
"dc:title": {},
"dc:description": {}
}
}
This would match on Libraries without dc:title
or dc:description
, or on Libraries having both dc:title
and dc:description
. Of course, @optional
might be multi-valued, to allow mutliple OPTIONAL
blocks.
These changes in frame syntax remove the use of framing flags in favor of constructs that more closely relate to potential query structures, which might, for example, include the use of explicit variables.