Skip to content

Commit

Permalink
RDF 1.2 and SPARQL 1.2; SEMIJOIN and ANTIJOIN
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Dec 11, 2024
1 parent 3d34ac9 commit 2f1818c
Show file tree
Hide file tree
Showing 595 changed files with 15,748 additions and 13,978 deletions.
4 changes: 3 additions & 1 deletion jena-arq/Grammar/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ Y12.html
sparql-grammar.html
# Grammar in BNF text
sparql.bnf
# Grammar in HTML as a standalone web page.
## BNF
sparql.bnf
## Grammar in HTML as a standalone web page.
sparql-html.html
3 changes: 2 additions & 1 deletion jena-arq/Grammar/RDF-Protobuf/binary-rdf.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ message RDF_Literal {
string lex = 1 ;
oneof literalKind {
bool simple = 9 ;
string langtag = 2 ;
string langtag = 2 ; // Language tag only literal
string langdir = 5 ; // Language tag and base direction separated by "--"
string datatype = 3 ;
RDF_PrefixName dtPrefix = 4 ;
}
Expand Down
2 changes: 2 additions & 0 deletions jena-arq/Grammar/RDF-Thrift/BinaryRDF.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ struct RDF_BNode {
// union with additional values.

struct RDF_Literal {
// Keep this numbering.
1: required string lex ;
2: optional string langtag ;
5: optional string baseDirection ;
3: optional string datatype ; // Either 3 or 4 but UNION is heavy.
4: optional RDF_PrefixName dtPrefix ; // datatype as prefix name
}
Expand Down
14 changes: 8 additions & 6 deletions jena-arq/Grammar/RDF-Thrift/gen-thrift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash
## Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0

if [ "$#" != 1 ]
then
echo "Usage: $(basename $0) FILE" 2>&1
exit 1
fi
## if [ "$#" != 1 ]
## then
## echo "Usage: $(basename $0) FILE" 2>&1
## exit 1
## fi

# Find the namespace
PKG=../../src/main/java/org/apache/jena/riot/thrift/wire
Expand All @@ -16,7 +16,9 @@ rm -f "$PKG"/*.java
## undated: suppress the date at @Generated annotations
## suppress: suppress @Generated annotations entirely

thrift -r -out ../../src/main/java -gen 'java:generated_annotations=suppress' "$@"
THRIFT="${1:-BinaryRDF.thrift}"

thrift -r -out ../../src/main/java -gen 'java:generated_annotations=suppress' "$THRIFT"

for f in "$PKG"/*.java
do
Expand Down
31 changes: 31 additions & 0 deletions jena-arq/Grammar/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
==== SPARQL Parser

Run

grammar

This produces the code for the current version SPARQL
and the ARQ (SPARQL with extensions) parsers.

==

To produce the HTML for the SPARQL Grammar for the W3C spec:
produce the SPARQL 1.2 specific file

grammar

which also generates Java code and can be used for checking.

Then run

sparql2html

The output is in sparql-grammar.html.

This replaces the table between "<!-- GRAMMAR -->" in the specific HTML.

Running

sparql2bnf

produces a text BNF form.
181 changes: 119 additions & 62 deletions jena-arq/Grammar/Turtle/turtle.jj
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void Statement() : {}
{
Directive()
| DirectiveOld()
// | (TriplesSameSubject() (<DOT> | <EOF> ) )
// | (Triples() (<DOT> | <EOF> ) )
// Strict
| (TriplesSameSubject() <DOT> )
| (Triples() <DOT> )
}

// Turtle [3] directive
Expand All @@ -106,25 +106,22 @@ void DirectiveOld() : { Token t ; String iri ; }
{ setBase(iri, t.beginLine, t.beginColumn) ; }
}

// Turtle [6] triples
void TriplesSameSubject() : { Node s ; }
void Triples() : { Node n; }
{
s = Subject()
PredicateObjectList(s)
n = Subject() PredicateObjectList(n)
|
s = BlankNodePropertyList()
( PredicateObjectList(s) )?
n = BlankNodePropertyList() ( PredicateObjectList(n) )?
|
n = ReifiedTriple() ( PredicateObjectList(n) )?
}

// Turtle [7] predicateObjectList
void PredicateObjectList(Node s) : { Node p = null ; }
{
p = Verb()
ObjectList(s, p)
(<SEMICOLON> (p = Verb() ObjectList(s, p))? )*
}

// Turtle [8] objectList
void ObjectList(Node s, Node p): { Node o ; }
{
o = Object()
Expand All @@ -137,17 +134,6 @@ void ObjectList(Node s, Node p): { Node o ; }
)*
}

// RDF-star Annotation Syntax
void Annotation(Node s, Node p, Node o) : {}
{
(
<L_ANN>
{ Node x = createQuotedTriple(s, p, o, token.beginLine, token.beginColumn); }
PredicateObjectList(x)
<R_ANN>
)?
}

// Turtle [9] verb
Node Verb() : { Node p ; }
{
Expand All @@ -163,13 +149,10 @@ Node Subject() : { Node s; String iri ; }
s = BlankNode()
|
s = Collection()
|
s = QuotedTriple()
)
{ return s ; }
}


// Turtle [11] predicate
Node Predicate() : { String iri;}
{
Expand All @@ -185,43 +168,12 @@ Node Object(): { Node o ; String iri; }
| o = Collection()
| o = BlankNodePropertyList()
| o = Literal()
| o = QuotedTriple()
| o = TripleTerm()
| o = ReifiedTriple()
)
{ return o; }
}

Node QuotedTripleSubject(): { Node o ; String iri; }
{
( iri = iri() { o = createURI(iri, token.beginLine, token.beginColumn) ; }
| o = BlankNode()
| o = QuotedTriple()
)
{ return o; }
}

Node QuotedTripleObject(): { Node o ; String iri; }
{
( iri = iri() { o = createURI(iri, token.beginLine, token.beginColumn) ; }
| o = BlankNode()
| o = Literal()
| o = QuotedTriple()
)
{ return o ; }
}

// The syntax for RDF-star <<>>
Node QuotedTriple() : { Node s , p , o ; Token t ; }
{
t = <LT2>
s = QuotedTripleSubject()
p = Verb()
o = QuotedTripleObject()
<GT2>
{ Node n = createQuotedTriple(s, p, o, t.beginLine, t.beginColumn);
return n;
}
}

// Turtle [13] literal
Node Literal() : { Node n ;}
{
Expand Down Expand Up @@ -302,7 +254,7 @@ Node RDFLiteral() : { Token t ; String lex = null ; }
String LangTag() : { Token t ; }
{
// Enumerate the directives here because they look like language tags.
( t = <LANGTAG> | t = AnyDirective() )
( t = <LANG_DIR> | t = AnyDirective() )
{ String lang = stripChars(t.image, 1) ; return lang ; }
}

Expand Down Expand Up @@ -369,6 +321,106 @@ String IRIREF() : { Token t ; }
{ return resolveQuotedIRI(t.image, t.beginLine, t.beginColumn) ; }
}

Node Reifier() : { Node n = null; String iriStr; Token t; }
{
t = <TILDE>
(
iriStr = iri() { n = createURI(iriStr, token.beginLine, token.beginColumn) ; }
| n = BlankNode()
)?
{ if ( n == null ) n = createBNode(t.beginLine, t.beginColumn) ; }
{ return n ; }
}

Node ReifiedTriple() : { Node reifId = null ; Token tok ; Node s; Node p ; Node o ; }
{
tok = <LT2>
s = ReifiedTripleSubject()
p = Verb()
o = ReifiedTripleObject()
( reifId = Reifier())?
{ reifId = emitTripleReifier(tok.beginLine, tok.beginColumn, reifId, s, p, o); }
<GT2>
{ return reifId ; }
}

// rtSubject
Node ReifiedTripleSubject() : { Node s; String iri; } {
( iri = iri() { s = createURI(iri, token.beginLine, token.beginColumn) ; }
| s = BlankNode()
| s = ReifiedTriple()
)
{ return s; }
}

// rtObject
Node ReifiedTripleObject() : { Node o; String iri; } {
( iri = iri() { o = createURI(iri, token.beginLine, token.beginColumn) ; }
| o = BlankNode()
| o = Literal()
| o = TripleTerm()
| o = ReifiedTriple()
)
{ return o; }
}

Node TripleTerm() : { Node n = null ; Token openToken ; String iri ; Node s , p , o ; }
{
<L_TRIPLE>
s = TripleTermSubject()
p = Verb()
o = TripleTermObject()
<R_TRIPLE>
{ return createTripleTerm(s, p, o, token.beginLine, token.beginColumn) ; }
}

// ttSubject
Node TripleTermSubject(): { Node o ; String iri; }
{
( iri = iri() { o = createURI(iri, token.beginLine, token.beginColumn) ; }
| o = BlankNode()
)
{ return o; }
}

// ttObject
Node TripleTermObject(): { Node o ; String iri; }
{
( iri = iri() { o = createURI(iri, token.beginLine, token.beginColumn) ; }
| o = BlankNode()
| o = Literal()
| o = TripleTerm()
)
{ return o ; }
}

// RDF-star Annotation Syntax
void Annotation(Node s, Node p, Node o) : { Node reifId = null; }
{
(
reifId = Reifier()
{ reifId = emitTripleReifier(token.beginLine, token.beginColumn, reifId, s, p, o) ; }
{ setReifierId(reifId); }
|
{ reifId = getOrAllocReifierId(s, p, o, token.beginLine, token.beginColumn); }
{ clearReifierId(); }
AnnotationBlock(reifId)
) *
}

void AnnotationBlock( Node reifId ) : {}
{
<L_ANN>
PredicateObjectList(reifId)
<R_ANN>
// (
// <L_ANN>
// { Node x = createQuotedTriple(s, p, o, token.beginLine, token.beginColumn); }
// PredicateObjectList(x)
// <R_ANN>
// )?
}

// ------------------------------------------
// Tokens

Expand Down Expand Up @@ -457,18 +509,23 @@ TOKEN :
| < SEMICOLON: ";" >
| < COMMA: "," >
| < DOT: "." >

| < DATATYPE: "^^">
| < AT: "@">

| < L_TRIPLE: "<<(" >
| < R_TRIPLE: ")>>" >
| < LT2: "<<" >
| < GT2: ">>" >
| < L_ANN: "{|" >
| < R_ANN: "|}" >

| < DATATYPE: "^^">
| < AT: "@">
| < TILDE: "~" >
| < VBAR: "|" >

| <PNAME_NS: (<PN_PREFIX>)? ":" >
| <PNAME_LN: <PNAME_NS> <PN_LOCAL> >
| <BLANK_NODE_LABEL: "_:" (<PN_CHARS_U> | ["0"-"9"]) ((<PN_CHARS>|".")* <PN_CHARS>)? >
| <LANGTAG: <AT> (<A2Z>)+("-" (<A2ZN>)+)* >
| <LANG_DIR: <AT> (<A2Z>)+("-" (<A2ZN>)+)* ( "--" (<A2Z>)* )? >
| <#A2Z: ["a"-"z","A"-"Z"]>
| <#A2ZN: ["a"-"z","A"-"Z","0"-"9"]>

Expand Down
Loading

0 comments on commit 2f1818c

Please sign in to comment.