buda-base / lds-pdi

http://purl.bdrc.io BDRC Linked Data Server
Apache License 2.0
2 stars 0 forks source link

change json results #28

Closed eroux closed 6 years ago

eroux commented 6 years ago

The current json output looks like:

  "headers" : [ "s", "lit" ],
  "rows" : [ {
    "dataRow" : {
      "s" : "<a href=/resource/P3393> P3393</a>",
      "lit" : "'od zer/@bo-x-ewts"
    }
  }, {

but what an API consumer wants is the URI of the resource, not an html link. So we have several solutions.

Solution 1

A small change:

  "headers" : [ "s", "lit" ],
  "rows" : [ {
    "dataRow" : {
      "s" : "<http://purl.bdrc.io/resource/P3393>",
      "lit" : "'od zer/@bo-x-ewts"
    }
  ...

(not sure about the <...>)

Solution 2

add prefixes, as in:

  "headers" : [ "s", "lit" ],
  "prefixes": {"bdr": "http://purl.bdrc.io/resource/"}
  "rows" : [ {
    "dataRow" : {
      "s" : "bdr:P3393",
      "lit" : "'od zer/@bo-x-ewts"
    }
  ...

Solution 3

just transmit the SPARQL result, which looks just fine:

  "headers" : [ "s", "lit" ],
  "prefixes": {"bdr": "http://purl.bdrc.io/resource/"}
  "results": {
    "bindings": [
      {
        "s": { "type": "uri" , "value": "http://purl.bdrc.io/resource/P3393" } ,
        "lit": {  "type": "literal" , "xml:lang": "bo-x-ewts" , "value": "'od zer/" } ,
      } ,
   ...

I think Solution 3 is the most solid one.

MarcAgate commented 6 years ago

Implemented solution 3 in commit df35a6a - prefixes still need to be added

eroux commented 6 years ago

Thanks, not sure we really need to add prefixes, but the datatypes are missing from the literal fields, they appear in some SPARQL results like the following:

{
  "head": {
    "vars": [ "p" ]
  } ,
  "results": {
    "bindings": [
      {
        "p": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
      } ,
MarcAgate commented 6 years ago

Ok. added Literal datatypes URI in json Results

eroux commented 6 years ago

Looking at the code I think it will output

      {
        "p": { "type": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
      } ,

instead of:

      {
        "p": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
      } ,

? If so, I think it shouldn't, I see some virtue in using the exact same format as the SPARQL query...

MarcAgate commented 6 years ago

Ok ! Implemented in commit f41a720