简体   繁体   中英

Literals as subject in SPARQL triples

As far as I read from the grammar of SPARQL https://www.w3.org/TR/sparql11-query/#sparqlGrammar it is allowed to have literals as the subject in a triple:

[75]    TriplesSameSubject    ::=   VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList
[106]   VarOrTerm     ::=   Var | GraphTerm
[109]   GraphTerm     ::=   iri | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL

So it would be possible to have a triple such as:

 (3, rdfs:label, 'three')

I can handle such triples in Python's rdflib, but when I try to make a federated SPARQL query with SERVICE in Virtuoso version 06.01.3127, Virtuoso complains. Here is an error message from my execution at a local install at http://localhost:8890/sparql

Virtuoso 37000 Error SP031: SPARQL compiler: No one quad map pattern is suitable for GRAPH _:_::default_8_4 { 3 <http://www.w3.org/2000/01/rdf-schema#label> ?s } triple at line 8

SPARQL query:
define sql:big-data-const 0 
#output-format:text/html
define sql:signal-void-variables 1 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?s WHERE {
  SERVICE <http://127.0.0.1:5000/sparql> {
    SELECT ?s WHERE {
      3 rdfs:label ?s .
    }
  }
}

Is this a Virtuoso issue or is this a more general SPARQL/RDF issue, - or a programming error that I make?

Very few (I believe the current count is zero) enterprise-grade triple- or quad-stores handle "Generalized RDF", which is RDF that permits literals in the Subject position. As yet, this is generally understood not to scale well, though it can be useful or interesting at small scale, such as in CWM , TimBL's Python-based Closed World Machine.

Virtuoso is an enterprise-grade DBMS, handling tabular SQL data, graphical RDF data, and more. At present, and for the planned future, Virtuoso will not handle Generalized RDF.

All that said, it should be noted that you're running a rather old Virtuoso, from circa July 2012. Whether you're running Commercial or Open Source , updating to a more recent build (at least 7.2.4.2 as of April 2016) is strongly recommended for a wide variety of performance and functionality reasons.

ObDisclaimer: OpenLink Software produces Virtuoso , and employs me.

SPARQL has always include literals as subject in the grammar even at SPARQL 1.0 - variables from one position can used in another so via variables matching literals-as-subject happens anyway.

SPARQL 1.0:
https://www.w3.org/TR/rdf-sparql-query/#sparqlTriplePatterns
SPARQL 1.1:
https://www.w3.org/TR/sparql11-query/#sparqlTriplePatterns

Of course, they will not match RDF as stored.

The rules for CONSTRUCT say "reject such triples".

https://www.w3.org/TR/sparql11-query/#construct

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM