Text we don't want to loose but which is old or badly, confusingly out of date.


Text from Sept04 spec draft for features which WG deemed out of scope for the first working draft

6 More Pattern Matching – Alternatives

Section status:  rough draft

An RDF query (for a person's name) may be satisified by any of a set of graphs. These differences may be a simple change of object or predicate:

Data:

@prefix  rss:  <http://purl.org/rss/1.0/> .
@prefix  dc0:  <http://purl.org/dc/elements/1.0/> .
@prefix  dc1:  <http://purl.org/dc/elements/1.1/> .

<http://feeds.example/alice.rss> rdf:type rss:channel .
<http://feeds.example/alice.rss> dc0:creator "Alice" .

<http://feeds.example/bob.rss> rdf:type rss:channel .
<http://feeds.example/bob.rss> dc1:creator "Bob" .

or a graph with a different topology:

@prefix  rss:  <http://purl.org/rss/1.0/> .
@prefix  dc1:  <http://purl.org/dc/elements/1.1/> .
@prefix  pim:  <http://www.w3.org/2000/10/swap/pim/contact#> .

<http://feeds.example/eve.rss> dc1:creator _1 .
			    _1   pim:given "Eve" .

BRQL graphPatterns can have alternative graph patterns within them. For instance, the query

Query:

SELECT ?channel ?creator
PREFIX  rss:  <http://purl.org/rss/1.0/>
PREFIX  dc0:  <http://purl.org/dc/elements/1.0/>
PREFIX  dc1:  <http://purl.org/dc/elements/1.1/>
PREFIX  pim:  <http://www.w3.org/2000/10/swap/pim/contact#>
WHERE { ?channel rdf:type    rss:channel
        { ?channel dc0:creator ?creator } OR 
        { ?channel dc1:creator ?x .
          ?x    pim:given   ?creator } OR 
        { ?channel dc1:creator ?creator } }

Query result:

?channel = <http://feeds.example/alice.rss> , ?creator = "Alice" 
?channel = <http://feeds.example/eve.rss> , ?creator = "Eve" 
?channel = <http://feeds.example/bob.rss> , ?creator = "Bob" 

The first triplePattern in this query extracts a set of nodes with rdf:type rss:channel. It then constrains that set to those that either have a dc 1.0 creator, or have a dc 1.1 creator which in turn has a pim:given or have a dc 1.1 creator with no pim:given arc. <http://feeds.example/bob.rss> has a dc1:creator with no pim:given, so the { ?channel dc1:creator ?creator } pattern matches and binds ?creator to "Bob". <http://feeds.example/eve.rss> has a dc1:creator which has a pim:given, so the previous pattern matches; ?creator gets bound to "Eve" and the { ?channel dc1:creator ?creator } pattern is not reached. This illustrates the shortcut nature of the BRQL disjunction.

Definition: Graph Pattern (Disjunction) A disjunction of QS, with initial binding B, the first QS to match or an empty set of no solutions exist.

7 More Pattern Matching – Unsaid

Section status: placeholder text - not integrated

Non-Existence of Triples

Form:

NOT (?s ?p ?o)

Example:

SELECT ?x
WHERE      (?x rdf:type foaf:Person)
       NOT (?x foaf:foaf:family_name "Smith")
           (?x foaf:foaf:first_name "John")

When a query processor encounters a NOT modifier, a query result is rejected if there is a RDF statement in the RDF graph that matches the pattern. No bindings are caused.

 

 



Original Text

Original Text and Structure:





  1. Introduction
  2. Description
  3. Comparison with RDQL
  4. Grammar
  5. Test Cases
  6. Correlation to DAWG UC&R
  7. References and Resources

Documents


X1. Introduction

BRQL is an extension of RDQL which has been implemented in a number of RDF systems for extracting information from RDF graphs. This extension is designed to meet the requirements and design objectives specified by the W3C RDF Data Access Working Group in their RDF Data Access Use Cases and Requirements document.

RDQL itself is an evolution from several languages and including ideas described in [6]. See [1] for the original paper about three similar query languages, together with some history and context.  See [2] for a comprehensive survey of many RDF query languages (and also rule systems) and [3] for a number of use case with examples in several languages.

X2. Description

This section is a non-normative description of BRQL with examples.  It is not a tutorial (see the [4] Jena RDQL tutorial) but a quick description of the key elements of the query language. The @@@ and grammar, given later, is normative.

An RDF [8] model is graph, often expressed as a set of triples.  An RDQL consists of a graph pattern, expressed as a list of triple patterns.  Each triple pattern is comprised of named variables and RDF values (URIs and literals).  An RDQL query can additionally have a set of constraints on the values of those variables, and a list of the variables required in the answer set.

Example 1:

SELECT ?x
WHERE (?x,  <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>,
                                   <http://xmlns.com/foaf/0.1/Person>)

This triple pattern matches all statements in the graph that have predicate http://www.w3.org/1999/02/22-rdf-syntax-ns#type and object http://example.com/someType.  The variable "?x" will be bound to the label of the subject resource.  All such "x" are returned (strictly, "x" is the variable name, "?" introduces a variable but is not part if its name).

An RDQL query treats an RDF graph purely as data. If the implementation of that graph provides inferencing to appear as "virtual triples" (i.e. triples that appear in the graph but are not in the ground facts) then an RDQL will include those triples as possible matches in triple patterns. RDQL makes no distinction between inferred triples and ground triples.

The terms quoted by "<>" are URIrefs.  Other RDF values are literals which, following N-Triples syntax [7], are a string and optional language tag (introduced with '@') and datatype URI (introduced by '^^').  URIrefs can also abbreviated with an XML QName-like form; this is syntactic assistance and is translated to the full URIref.

The example query above had just one triple pattern forming a single edge in the graph pattern. More complicated graph patterns are made by writing all the edges in the query. Like RDF, these are interpreted conjunctively – all of them must match for a result to be added to the result set of the query. This may mean that variables are used to link together triple patterns.

Example 2:

SELECT ?given, ?family
WHERE  (?vcard  vcard:FN "Alice Antwerp")
       (?vcard  vcard:N  ?name)
       (?name   vcard:Family  ?family)
       (?name   vcard:Given  ?given)
USING  vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>

This query, based on the vCard vocabulary [9], finds the family name and given name from any vcards with formatted name (FN) "John Smith".  The vCard vocabulary has a structured value for the name, using the vcard:N property to point to another node in the RDF graph.  This node, in turn, has the various name elements as further statements. This intermediate node can be a blank node (an RDF node without a URIref in this RDF graph).

We have used the prefix 'vcard' to abbreviate the URI or URIref.  Writing the full URI or writing the abbreviated form is the same query as RDF only deals with full URIrefs.

We have used a comma to separate the variables in the SELECT clause.  Commas in queries in triple patterns or in places where lists of items occur are optional and the application writer can choose to use them or not for readability and personal style.

Example 3:

SELECT ?name
WHERE (?who info:age ?age)
      (?who vcard:FN ?name)
AND ?age >= 30
USING info FOR <http://example.org/peopleInfo#>, 
      vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>

In this example, there is a constraint to restrict the object value of the matched statements.

Example 4:

SELECT ?resource
FROM   <http://example.org/someWebPage>
WHERE  (?resource info:age ?age)
AND    ?age >= 30
USING  info FOR <http://example.org/peopleInfo#>

In this example, the source of the data to be queried is supplied.

Where not supplied, it is the responsibility of the execution environment to associate the query with the RDF graph to be queried. Such mechanisms are outside the scope of this note.

X4. Grammar

Section Status: Out of Date

Note: this is a permissive grammar.  It is designed for convenience and includes liberal interpretations of terms from other systems.

X4.1. Lexical Tokens

QuotedURI  ::=  '<' URI characters (from RFC 2396) '>'
NSPrefix  ::=   NCName As defined in XML Namespace v1.1 and XML 1.1
LocalPart  ::=   NCName As defined in XML Namespace v1.1 and XML 1.1
SELECT  ::=  'SELECT' Case Insensitive match
FROM  ::=  'FROM'   Case Insensitive match
SOURCE  ::=  'SOURCE' Case Insensitive match
WHERE  ::=  'WHERE' Case Insensitive match
AND  ::=  'AND' Case Insensitive match
USING  ::=  'USING' Case Insensitive match
Identifier  ::=  ([a-z][A-Z][0-9][-_.])+  
EOF  ::=  End of file
COMMA  ::=  ','
INTEGER_LITERAL   ::=  ([0-9])+
FLOATING_POINT_LITERAL  ::=  ([0-9])*'.'([0-9])+('e'('+'|'-')?([0-9])+)?
STRING_LITERAL1  ::=  '"'UTF-8 characters'"' (with escaped \")
STRING_LITERAL2  ::=  "'"UTF-8 characters"'" (with escaped \')
LPAREN  ::=  '('
RPAREN  ::=  ')'
COMMA  ::=  ','
DOT  ::=  '.'
GT  ::=  '>'
LT  ::=  '<'
BANG  ::=  '!'
TILDE  ::=  '~'
HOOK  ::=  '?'
COLON  ::=  ':'
EQ  ::=  '=='
NEQ  ::=  '!='
LE  ::=  '<='
GE  ::=  '>='
SC_OR  ::=  '||'
SC_AND  ::=  '&&'
STR_EQ  ::= 'EQ' Case Insensitive match
STR_NE  ::= 'NE' Case Insensitive match
PLUS  ::=  '+'
MINUS  ::=  '-'
STAR  ::=  '*'
SLASH  ::=  '/'
REM  ::=  '%'
STR_MATCH  ::=  '=~' | '~~'
STR_NMATCH  ::=  '!~'
DATATYPE  ::=  '^^'
AT  ::=  '@'

X4.2. Productions

References to lexical tokens are enclosed in <>.  Whitespace is skipped.

Notes: The term "literal" refers to a constant value, and not only an RDF Literal.

The grammar starts with the doc-BRQLQuery production.

[1]    BRQLQuery    ::=    SELECT VarList ( SourceClause )? WHERE GraphPattern ( ConstraintClause )? ( PrefixesClause )?
| DESCRIBE VarList ( SourceClause )? WHERE GraphPattern ( ConstraintClause )? ( PrefixesClause )?
| DESCRIBE URI ( SourceClause )? ( PrefixesClause )?
| CONSTRUCT Graph ( SourceClause )? WHERE GraphPattern ( ConstraintClause )? ( PrefixesClause )?
A BRQL query will SELECT a set of variable bindings, CONSTRUCT a set of statements from the variable bindings, or DESCRIBE a resource with a set of statements.
SELECT ?p
WHERE (?s ?p ?o)
[2]    SourceClause    ::=    ( SOURCE | FROM ) SourceSelector ( ( <COMMA> )? SourceSelector )*
The SourceClause identifies a set of documents or virtual documents to query.
FROM <http://example.org/doc1.rdf> , <http://example.org/database-2>
[3]    SourceSelector    ::=    URI
[4]    GraphPattern    ::=    Graph ( GroundPattern )*
The GraphPattern describes a set of RDF graphs. The initial graph must be an exact match of the included TriplePatterns. Any graph following the NOT keyword much not be present in the @@@returned@@@ set. Graphs following the OPTIONAL may be preset (in their entirety) but a failure to match an OPTIONAL component does not eliminate results from the @@@returned@@@ set.
(?x rdf:type foaf:Person)
(?x foaf:mbox_sha1sum "ABCD1234")
[5]    GroundPattern    ::=    NOT Graph
| OPTIONAL Graph
NOT and OPTIONAL graphs must follow .
NOT (?x rdf:type foaf:UnPerson)
OPTIONAL (?x foaf:created ?creation)
[6]    Graph    ::=    TriplePattern ( ( <COMMA> )? TriplePattern )*
The Graph defines a set of TriplePatterns that compose a query graph. A query graph is composed of TriplePatterns and may have variables as node or arc labels where an RDF Graph is a simple conjunction of RDF Statements (with no variables).
(?x rdf:type foaf:Person)
(?x foaf:mbox_sha1sum "ABCD1234")
[7]    TriplePattern    ::=    SourceOpt LPAREN ( Var | URI ) ( <COMMA> )? ( Var | URI ) ( <COMMA> )? ( Var | Const ) RPAREN
Simple TriplePatterns are conjunctions with any that have come before in the query. NOT triples match only if the expressed pattern (with any already bound variables) is not found in the data. OPTIONAL TriplePatterns match just as simple TriplePatterns do, however, if no match is found, the solution is not eliminated. Instead, all newly introduced variables are known to be unbound.
[8]    SourceOpt    ::=   
| SOURCE '?' Identifier
The Source of a TriplePattern identifies the variable which will hold @@@ needs href @@@ the provenance of a matched TriplePattern.
[9]    Var    ::=    '?' Identifier
[10]    PrefixesClause    ::=    USING PrefixDecl ( ( <COMMA> )? PrefixDecl )*
[11]    PrefixDecl    ::=    Identifier FOR QuotedURI

Constraints

Expressions express constraints that will not match literal statements in the queried data.

[12]    ConstraintClause    ::=    AND Expression ( ( COMMA | AND ) Expression )*
[13]    Expression    ::=    ConditionalOrExpression
| QName LPAREN ( PrimaryExpression )* RPAREN
[14]    ConditionalOrExpression    ::=    ConditionalAndExpression
| ConditionalAndExpression SC_OR ConditionalOrExpression
[15]    ConditionalAndExpression    ::=    StringEqualityExpression
| StringEqualityExpression SC_AND ConditionalAndExpression
[16]    StringEqualityExpression    ::=    ArithmeticCondition
| ArithmeticCondition STR_EQ StringEqualityExpression
| ArithmeticCondition STR_NE StringEqualityExpression
| PatternLiteral STR_MATCH StringEqualityExpression
| PatternLiteral STR_NMATCH StringEqualityExpression
[17]    ArithmeticCondition    ::=    EqualityExpression
[18]    EqualityExpression    ::=    RelationalExpression
| RelationalExpression EQ RelationalExpression
| RelationalExpression NEQ RelationalExpression
[19]    RelationalExpression    ::=    AdditiveExpression
| AdditiveExpression LT AdditiveExpression
| AdditiveExpression GT AdditiveExpression
| AdditiveExpression LE AdditiveExpression
| AdditiveExpression GE AdditiveExpression
[20]    AdditiveExpression    ::=    MultiplicativeExpression
| MultiplicativeExpression PLUS MultiplicativeExpression
| MultiplicativeExpression MINUS MultiplicativeExpression
[21]    MultiplicativeExpression    ::=    UnaryExpression
| UnaryExpression STAR MultiplicativeExpression
| UnaryExpression SLASH MultiplicativeExpression
| UnaryExpression REM MultiplicativeExpression
[22]    UnaryExpression    ::=    UnaryExpressionNotPlusMinus
| PLUS UnaryExpression
| MINUS UnaryExpression
[23]    UnaryExpressionNotPlusMinus    ::=    TILDE UnaryExpression
| BANG UnaryExpression
| PrimaryExpression
[24]    PrimaryExpression    ::=    Var
| Const
| LPAREN Expression RPAREN
[25]    Const    ::=    URI
| NumericLiteral
| TextLiteral
| BooleanLiteral
| NullLiteral
[26]    NumericLiteral    ::=    INTEGER_LITERAL
| FLOATING_POINT_LITERAL
[27]    TextLiteral    ::=    ( STRING_LITERAL1 | STRING_LITERAL2 ) ( AT Identifier )? ( DATATYPE URI )?
[28]    PatternLiteral    ::=    PATTERN_LITERAL
[29]    BooleanLiteral    ::=    BOOLEAN_LITERAL
[30]    NullLiteral    ::=    NULL_LITERAL
[31]    URI    ::=    QuotedURI
| QName
[32]    QName    ::=    NSPrefix ':'
| NSPrefix ':' LocalPart
[33]    Identifier    ::=    IDENTIFIER
| SELECT
| SOURCE
| FROM
| WHERE
| PREFIXES
| FOR
| STR_EQ
| STR_NE

X7.0 References and Resources

Resources

References

[1] "Three Implementations of SquishQL, a Simple RDF Query Language", Libby Miller, Andy Seaborne, Alberto Reggiori; ISWC2002

[2] "RDF Query and Rules: A Framework and Survey", Eric Prud'hommeaux

[3] "RDF Query and Rule languages Use Cases and Example", Alberto Reggiori, Andy Seaborne

[4] RDQL Tutorial for Jena (in the Jena tutorial).

[5] RDQL BNF from Jena

[6] Enabling Inference, R.V. Guha, Ora Lassila, Eric Miller, Dan Brickley

[7] N-Triples

[8] RDF http://www.w3.org/RDF/

[9] "Representing vCard Objects in RDF/XML", Renato Iannella, W3C Note.

[10] "RDF Data Access Working Group"

[11] "RDF Data Access Use Cases and Requirements — W3C Working Draft 2 June 2004", Kendall Grant Clark.


$Log: OtherText.html,v $
Revision 1.1  2004/10/12 14:21:44  matthieu
Created

Revision 1.3  2004/09/24 13:08:26  aseaborne
Changes from the Bristol Face-to-face meeting:
+ Change examples to (triple) syntax
+ Move text for disjunction to OtherText.html
+ Move text for unsaid to OtherText.html

Revision 1.2  2004/09/01 16:27:26  aseaborne
no message

Revision 1.1  2004/08/24 13:34:36  aseaborne
Text not currently in use