CLARIAH / grlc

grlc builds Web APIs using shared SPARQL queries
http://grlc.io
MIT License
137 stars 32 forks source link

Improving SPARQL transform #215

Closed c-martinez closed 5 years ago

c-martinez commented 5 years ago

The proposal is merge the functionality of SPARQLtransform and projections (pyql files). We would prefer for queries to always be expressed as SPARQL, in order not to loose any of the SPARQL expressiveness, but to keep the transform result representation capability -- results from queries expressed as json. The transform syntax could be included using the transform keyword.

The .rq file would look like this:

#+ summary: Brief description of this query
#+ endpoint_in_url: False
#+ endpoint: "http://endpoint/sparql/"
#+ transform: {
#+     "id": "?id",
#+     "class": "$rdf:type$required$var:?class",
#+     "label": "$rdfs:label$required",
#+     "o": "?o"
#+   }

prefix dcterms: <http://purl.org/dc/terms/>

SELECT ?p ?o WHERE
{
  ?_s ?p ?o
}

@pasqLisena -- I discussed this with @albertmeronyo and we agreed this might be the best way forward. Do you have any comments / suggestions?

pasqLisena commented 5 years ago

Hello @c-martinez, I agree that the next step is extracting the transforming capabilities of the module. I received different suggestions on this topic and I will soon study the problem and produce the best solution.

c-martinez commented 5 years ago

Hi @pasqLisena -- great! Let us know if you have any suggestions or other recommendations for the grlc implementation.

c-martinez commented 5 years ago

Hey @pasqLisena, I'm implementing the new functionality as discussed above, with some simplifications. More specifically, I was trying to project results from this query:

SELECT ?p ?o WHERE
{
  ?_s ?p ?o
} LIMIT 5

into something like this:

{
  "p1":"o1",
  "p2":"o2",
  "p3":"o3",
  "p4":"o4",
  "p5":"o5"
}

However, it looks like SPARQLTransformer always returns a list? It also looks like it must always have an id -- is that correct? What is the reasoning behind it?

pasqLisena commented 5 years ago

However, it looks like SPARQLTransformer always returns a list?

Normally yes.

It also looks like it must always have an id -- is that correct? What is the reasoning behind it?

Yes, the id is an anchor for merging. For now, it is hardcoded, planning to make it selectable.


Back to your template, I am surprised that you don't want something like :

[
  {"p1" : "o1"},
  {"p2" : "o2"},
  {"p3" : "o3"},
  {"p4" : "o4"},
  {"p5" : "o5"}
]

Anyway, for now, SPARQL Transformer is capable to output something like:

[
  {"p" : "p1",
  "o" : "o1" },
  {"p" : "p2",
  "o" : "o2" },
  ...
]

in other words, only the attribute values are replaced, while attribute names are not touched.

c-martinez commented 5 years ago

Ok, that kind of makes sense. And what would be the correct syntax for such a projection? I imagine I should use something like this (given that the id is required at the moment):

{
  "id": "?p",
  "value": "?o"
}

Would give me something like:

[
  { "id" : "p1",  "value" : "o1" },
  { "id" : "p2",  "value" : "o2" },
  ...
]

Is that correct?

pasqLisena commented 5 years ago

Exactly

pasqLisena commented 5 years ago

Hi @c-martinez, I just released a version of ST in which you can replace that hard-coded id with any other property with a $anchor modifier. See documentation

c-martinez commented 5 years ago

Hi @pasqLisena. Nice! So this means I should be able to write something like this:

{
  "key": "?p$anchor",
  "value": "?o"
}

and get the desired result. Correct?