Open pchampin opened 3 years ago
I notice that GraphDB 9.10.1, which seems to be using YASR and YASQE, has some support for SPARQL-star in them. @VladimirAlexiev any chance to see these changes open-sourced and submitted to the original code?
Also related to #189.
Our workbench is open source: https://github.com/Ontotext-AD/graphdb-workbench
It uses an older version of YASR . Our modified version is also open source: https://github.com/Ontotext-AD/YASR-Ontotext . But I'm not sure it has been updated for a while. I think we display rdf-star tabular results in our own widget.
@desislava-hristova-ontotext can say more.
Also: we are currently working on making GDB WB (and YASR and charts) translatable. This is coordinated by @rdstn
We are using YASGUI/YASR in Apache Jena, thanks a lot for sharing it.
I forked and had a look at the project:
I have yarn run dev
running with YASGUI, showing the errors for SPARQL-star
and I have the latest SWI Prolog for Ubuntu. I tried running the current code from GitHub to see if I could produce the tokenizer before trying to modify it. But running the build.sh
command results in this error:
kinow@ranma:~/Development/java/jena/Yasgui/packages/yasqe/grammar$ ./build.sh
Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.2)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
ERROR: assertz/1: Type error: `callable' expected, found `[]' (an empty_list)
Exception: (9) *'or([baseDecl,prefixDecl])'===>_7470 ?
My Prolog is really (but really) rusty. Any idea what could be wrong here, or if I need to install an older version?
Thank you! -Bruno
(JavaCC rather than Antlr)
The grammar changes for SPARQL are in the CG report which si BNF without the local parser actions attached: https://www.w3.org/2021/12/rdf-star.html#sparql-star-grammar
and for results formats: https://www.w3.org/2021/12/rdf-star.html#query-result-formats
Tried with trealla prolog but looks like the code uses some features that are missing in trealla's (maybe the dynamic predicates, like ==>
).
Installed PDT on Eclipse (really nostalgic, years since I last used it), and loaded the gen_sparql11.pl
module as main
, and reevaluated it.
Then calling go.
(what was described so far is exactly what the shell script does calling swipl -s $file -t go
), and now at least I have a trace/debugger of the error. Not likely to solve it so easily. Maybe it's something introduced in a recent version of SWI-Prolog that requires the grammar to be updated (e.g. declare predicates with callable
?).
I will try a few things to see if I can re-generate the JavaScript file correctly.
(JavaCC rather than Antlr)
Argh, I think I said Antlr in other issues too. Always confuse it. Thanks for correcting it.
The grammar changes for SPARQL are in the CG report which si BNF without the local parser actions attached: https://www.w3.org/2021/12/rdf-star.html#sparql-star-grammar
and for results formats: https://www.w3.org/2021/12/rdf-star.html#query-result-formats
Thanks @afs!
If I cannot get the SWI-Prolog files to work here in Yasgui, a crazy idea that just occurred me was to try a few other possibilities:
jena-fuseki-ui
But first will have a little more fun trying to remember how Prolog works :nerd_face:
Fixed it by using an older version of swipl
:+1: now back to reading the RDF-Star docs & grammars :slightly_smiling_face:
Hmmm, I've added the grammar changes for SPARQL, and prolog runs OK (also with #214).
diff --git a/packages/yasqe/grammar/sparql11-grammar.pl b/packages/yasqe/grammar/sparql11-grammar.pl
index 8f3681e..289bd9c 100644
--- a/packages/yasqe/grammar/sparql11-grammar.pl
+++ b/packages/yasqe/grammar/sparql11-grammar.pl
@@ -46,7 +46,7 @@ selectQuery ==>
[selectClause,*(datasetClause),whereClause,solutionModifier].
subSelect ==>
- [selectClause,whereClause,solutionModifier,valuesClause].
+ [selectClause,whereClause,solutionModifier,valuesClause].
% [9]
selectClause ==>
@@ -296,6 +296,7 @@ inlineDataOneVar ==> [var,'{',*(dataBlockValue),'}'].
inlineDataFull ==> [ 'NIL' or ['(',*(var),')'],
'{',*(['(',*(dataBlockValue),')'] or 'NIL'),'}'].
%[65]
+dataBlockValue ==> [quotedTriple].
dataBlockValue ==> [iriRef].
dataBlockValue ==> [rdfLiteral].
dataBlockValue ==> [numericLiteral].
@@ -337,7 +338,7 @@ constructTriples ==>
[triplesSameSubject,?(['.',?(constructTriples)])].
%[75]
triplesSameSubject ==>
- [varOrTerm,propertyListNotEmpty].
+ [varOrTermOrQuotedTP,propertyListNotEmpty].
triplesSameSubject ==>
[triplesNode,propertyList].
%[76]
@@ -356,9 +357,9 @@ objectList ==>
[object,*([',',object])].
%[80]
object ==>
- [graphNode].
+ [graphNode, ?(annotationPattern)].
%[81]
-triplesSameSubjectPath ==> [varOrTerm,propertyListPathNotEmpty].
+triplesSameSubjectPath ==> [varOrTermOrQuotedTP,propertyListPathNotEmpty].
triplesSameSubjectPath ==> [triplesNodePath,propertyListPath].
%[82]
propertyListPath ==> [propertyListNotEmpty].
@@ -376,7 +377,7 @@ verbSimple ==> [var].
objectListPath ==>
[objectPath,*([',',objectPath])].
%[87]
-objectPath ==> [graphNodePath].
+objectPath ==> [graphNodePath, ?(annotationPatternPath)].
%[88]
path ==> [pathAlternative].
%[89].
@@ -449,10 +450,10 @@ collection ==> ['(',+(graphNode),')'].
%[103]
collectionPath ==> ['(',+(graphNodePath),')'].
%[104]
-graphNode ==> [varOrTerm].
+graphNode ==> [varOrTermOrQuotedTP].
graphNode ==> [triplesNode].
%[105]
-graphNodePath ==> [varOrTerm].
+graphNodePath ==> [varOrTermOrQuotedTP].
graphNodePath ==> [triplesNodePath].
%[106]
varOrTerm ==> [var].
@@ -516,6 +517,7 @@ primaryExpression ==> [rdfLiteral].
primaryExpression ==> [numericLiteral].
primaryExpression ==> [booleanLiteral].
primaryExpression ==> [var].
+primaryExpression ==> [exprQuotedTP].
primaryExpression ==> [aggregate].
%[120]
brackettedExpression ==> ['(',expression,')'].
@@ -577,6 +579,11 @@ builtInCall ==> ['ISNUMERIC','(',expression,')'].
builtInCall ==> [regexExpression].
builtInCall ==> [existsFunc].
builtInCall ==> [notExistsFunc].
+builtInCall ==> ['TRIPLE','(',expression,expression,expression,')'].
+builtInCall ==> ['SUBJECT','(',expression,')'].
+builtInCall ==> ['PREDICATE','(',expression,')'].
+builtInCall ==> ['OBJECT','(',expression,')'].
+builtInCall ==> ['isTRIPLE','(',expression,')'].
%[122]
regexExpression ==>
['REGEX','(',expression,',',expression,?([',',expression]),')'].
@@ -642,7 +649,41 @@ prefixedName ==> ['PNAME_NS'].
%[138]
blankNode ==> ['BLANK_NODE_LABEL'].
blankNode ==> ['ANON'].
-
+%[174]
+quotedTP ==> ['<<',qtSubjectOrObject,verb,qtSubjectOrObject,'>>'].
+%[175]
+quotedTriple ==> ['<<',dataValueTerm,'(',iriRef or 'a',dataValueTerm,'>>'].
+%[176]
+qtSubjectOrObject ==> [var].
+qtSubjectOrObject ==> [blankNode].
+qtSubjectOrObject ==> [iriRef].
+qtSubjectOrObject ==> [rdfLiteral].
+qtSubjectOrObject ==> [numericLiteral].
+qtSubjectOrObject ==> [booleanLiteral].
+qtSubjectOrObject ==> [quotedTP].
+%[177]
+dataValueTerm ==> [iriRef].
+dataValueTerm ==> [rdfLiteral].
+dataValueTerm ==> [numericLiteral].
+dataValueTerm ==> [booleanLiteral].
+dataValueTerm ==> [quotedTriple].
+%[178]
+varOrTermOrQuotedTP ==> [var].
+varOrTermOrQuotedTP ==> [graphTerm].
+varOrTermOrQuotedTP ==> [quotedTP].
+%[179]
+annotationPattern ==> ['{|',propertyListNotEmpty,'|}'].
+%[180]
+annotationPatternPath ==> ['{|',propertyListPathNotEmpty,'|}'].
+%[181]
+exprQuotedTP ==> ['<<',exprVarOrTerm,verb,exprVarOrTerm,'>>'].
+%[182]
+exprVarOrTerm ==> [iriRef].
+exprVarOrTerm ==> [rdfLiteral].
+exprVarOrTerm ==> [numericLiteral].
+exprVarOrTerm ==> [booleanLiteral].
+exprVarOrTerm ==> [var].
+exprVarOrTerm ==> [exprQuotedTP].
% tokens defined by regular expressions elsewhere
tm_regex([
@@ -793,7 +834,15 @@ tm_keywords([
'SAMPLE',
'SEPARATOR',
-'STR'
+'STR',
+
+'REGEX',
+
+'TRIPLE',
+'SUBJECT',
+'PREDICATE',
+'OBJECT',
+'isTRIPLE'
]).
% Other tokens representing fixed, case sensitive, strings
@@ -830,5 +879,9 @@ tm_punct([
'^^'= '\\^\\^',
'?' = '\\?',
'|' = '\\|',
-'^'= '\\^'
+'^'= '\\^',
+'<<'='<<',
+'>>'='>>',
+'{|'='{|',
+'|}'='|}'
]).
I ran yarn install
, yarn run build
, yarn run link
, and then did a yarn add /home/kinow/.../yasq
. However, the RDF-Star syntax was still not being handled.
Running yarn run dev
, I get the same in YASQE. It appears besides updating the grammar it's needed to update the YASQE files too, to include some of the changes from RDF-Star there... :disappointed_relieved:
This issue inspired me to add
* https://github.com/VladimirAlexiev/grammar-diagrams/#sparql-star-railroad-diagram * https://rawgit2.com/VladimirAlexiev/grammar-diagrams/master/sparql-star-grammar.xhtml
These look awesome @VladimirAlexiev ! I'll refer to them while working on this PR. Thanks heaps!
It would be nice if YASR (at least the table and response tabs) supported the SPARQL-star result formats (i.e. where able to display bindings where some variables are bound to quoted triples).
Note that the RDF-star CG report is now considered pretty stable (we are considering publishing a final report soon), and SPARQL-star is already supported or partially supported by a number of triple stores, so this could already be useful (see example).
The changes to the SPARQL result formats (XML and JSON) are documented here.