Skip to content
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

Add a standardized extension of SPARQL 1.1 Query Results JSON format #13

Closed
abrokenjester opened this issue Oct 13, 2020 · 7 comments
Closed
Labels
sparql-star About SPARQL-star

Comments

@abrokenjester
Copy link
Contributor

abrokenjester commented Oct 13, 2020

(related issue: #12)

The result of a SPARQL SELECT query is serialized in JSON using the SPARQL 1.1 Query Results JSON format. This format will need to be extended to deal with the RDF* triple being a new possible value type for a binding. For example, the result of a query where variable ?a is bound to an RDF* triple:

?a ?b ?c
<<<http://example.org/bob> <http://xmlns.com/foaf/0.1/age> 23>> <http://example.org/certainty> 0.9

Currently, different implementations all have their own, slightly diverging, extensions. For example, in Eclipse RDF4J, the extension looks as follows:

{
  "head" : {
    "vars" : [
      "a",
      "b",
      "c"
    ]
  },
  "results" : {
    "bindings": [
      { "a" : {
          "type" : "triple",
          "value" : {
            "s" : {
              "type" : "uri",
              "value" : "http://example.org/bob"
            },
            "p" : {
              "type" : "uri",
              "value" : "http://xmlns.com/foaf/0.1/age"
            },
            "o" : {
              "datatype" : "http://www.w3.org/2001/XMLSchema#integer",
              "type" : "literal",
              "value" : "23"
            }
          }
        },
        "b": {
          "type": "uri",
          "value": "http://example.org/certainty"
        },
        "c" : {
          "datatype" : "http://www.w3.org/2001/XMLSchema#decimal",
          "type" : "literal",
          "value" : "0.9"
        }
      }
    ]
  }
}

In Apache Jena, the extension looks as follows:

{
  "head" : {
    "vars" : [
      "a",
      "b",
      "c"
    ]
  },
  "results" : {
    "bindings": [
      { "a" : {
          "type" : "triple",
          "value" : {
            "subject" : {
              "type" : "uri",
              "value" : "http://example.org/bob"
            },
            "property" : {
              "type" : "uri",
              "value" : "http://xmlns.com/foaf/0.1/age"
            },
            "object" : {
              "datatype" : "http://www.w3.org/2001/XMLSchema#integer",
              "type" : "literal",
              "value" : "23"
            }
          }
        },
        "b": { 
          "type": "uri",
          "value": "http://example.org/certainty"
        },
        "c" : {
          "datatype" : "http://www.w3.org/2001/XMLSchema#decimal",
          "type" : "literal",
          "value" : "0.9"
        }
      }
    ]
  }
}

In Stardog, the format extension as currently implemented is as follows:

{
  "head" : {
    "vars" : [
      "a",
      "b",
      "c"
    ]
  },
  "results" : {
    "bindings": [
      { "a" : {
          "type" : "statement",
          "s" : {
            "type" : "uri",
            "value" : "http://example.org/bob"
          },
          "p" : {
            "type" : "uri",
            "value" : "http://xmlns.com/foaf/0.1/age"
          },
          "o" : {
            "datatype" : "http://www.w3.org/2001/XMLSchema#integer",
            "type" : "literal",
            "value" : "23"
          }
        },
        "b": { 
          "type": "uri",
          "value": "http://example.org/certainty"
        },
        "c" : {
          "datatype" : "http://www.w3.org/2001/XMLSchema#decimal",
          "type" : "literal",
          "value" : "0.9"
        }
      }
    ]
  }
}

In summary, Jena and RDF4J differ only by the names of the keys inside the new RDF* triple type (s vs subject, p vs property, etc). Stardog deviates slightly more in that it does not wrap the individual components of the RDF* triple into a value.

Other implementations may have yet other, slightly deviant variants. This makes it difficult to process query results from different endpoint implementations. A single recommended extension would be a benefit for parser implementors and users alike.

@akuckartz
Copy link
Contributor

Can the result be JSON-LD please ? :-)

@abrokenjester
Copy link
Contributor Author

Can the result be JSON-LD please ? :-)

It would certainly be interesting to look at extending JSON-LD to cover RDF* triples as well, but note that what we are talking about here is a JSON format for a tabular query result, not for RDF data. As such, I don't immediately see how we could make this particular format a JSON-LD format.

@hartig
Copy link
Collaborator

hartig commented Oct 14, 2020

I agree with @jeenbroekstra.

As a side note, work on JSON-LD for RDF* has already started: https://json-ld.github.io/json-ld-star/

@akuckartz
Copy link
Contributor

@jeenbroekstra wrote:

... what we are talking about here is a JSON format for a tabular query result, not for RDF data. As such, I don't immediately see how we could make this particular format a JSON-LD format.

Half a decade ago quite a bit of effort went into creating a set of W3C Recommendations enabling conversions from tabular data to RDF:
https://www.w3.org/2013/csvw/wiki/Main_Page

I think this work can and should be used to enable the new SPARQL version to output JSON-LD (or JSON-LD*) and not just JSON. This first of all requires a JSON-LD context - which could become part of the new SPARQL specification.

@abrokenjester
Copy link
Contributor Author

abrokenjester commented Oct 14, 2020

Half a decade ago quite a bit of effort went into creating a set of W3C Recommendations enabling conversions from tabular data to RDF:
https://www.w3.org/2013/csvw/wiki/Main_Page
I think this work can and should be used to enable the new SPARQL version to output JSON-LD (or JSON-LD*) and not just JSON. This first of all requires a JSON-LD context - which could become part of the new SPARQL specification.

There may well be a use case for what you propose, a more comprehensibly enriched JSON-LD format for SPARQL tabular query results, and I'be interested to see a proposal to that effect. I do note, however, that having such a format is not contingent on the availability of RDF* in the data. As such, it is out of scope for the issue proposed here, which is purely about a minimal syntactical extension of a specific standard JSON format to enable carrying query results involving RDF* data.

We need this to be minimal to allow low-effort uptake by various implementors (i.e. a simple adjustment of the currently existing parser/writer code in various software packages). Adding JSON-LD into the mix makes the effort of supporting the proposed format that much harder (it effectively will require a completely new parser/writer implementation for most software packages), and will hamper uptake.

I suggest that you open a separate github issue (either here or perhaps more appropriately over at the SPARQL 1.2 community group, since this idea does not seem specific to RDF* to me) about formulating a JSON-LD format for tabular SPARQL query results.

@akuckartz
Copy link
Contributor

Adding JSON-LD into the mix makes the effort of supporting the proposed format that much harder (it effectively will require a completely new parser/writer implementation for most software packages), and will hamper uptake.

Not necessarily. Ideally only a JSON-LD context needs to be added. But that would need to be looked at closer.

I suggest that you open a separate github issue (either here or perhaps more appropriately over at the SPARQL 1.2 community group, since this idea does not seem specific to RDF* to me) about formulating a JSON-LD format for tabular SPARQL query results.

Done: w3c/sparql-dev#125

@pchampin pchampin added sparql-star About SPARQL-star help wanted Extra attention is needed labels Nov 10, 2020
abrokenjester added a commit to metaphacts/rdf-star that referenced this issue Nov 19, 2020
abrokenjester added a commit to metaphacts/rdf-star that referenced this issue Nov 20, 2020
abrokenjester added a commit to metaphacts/rdf-star that referenced this issue Nov 20, 2020
abrokenjester added a commit to metaphacts/rdf-star that referenced this issue Nov 21, 2020
pchampin pushed a commit that referenced this issue Dec 11, 2020
@pchampin
Copy link
Collaborator

This was solved a while ago by #39

@pchampin pchampin removed the help wanted Extra attention is needed label Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sparql-star About SPARQL-star
Projects
None yet
Development

No branches or pull requests

4 participants