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

[YASR] Support SPARQL-star results #190

Open
pchampin opened this issue Nov 16, 2021 · 10 comments · May be fixed by #215
Open

[YASR] Support SPARQL-star results #190

pchampin opened this issue Nov 16, 2021 · 10 comments · May be fixed by #215
Labels

Comments

@pchampin
Copy link

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.

@pchampin
Copy link
Author

pchampin commented Feb 7, 2022

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.

@VladimirAlexiev
Copy link

VladimirAlexiev commented Feb 7, 2022

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

@kinow
Copy link

kinow commented Dec 7, 2022

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

image

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

@afs
Copy link

afs commented Dec 9, 2022

(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

@kinow
Copy link

kinow commented Jan 8, 2023

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.

image

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?).

image

I will try a few things to see if I can re-generate the JavaScript file correctly.

@kinow
Copy link

kinow commented Jan 8, 2023

(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:

  • Use Jena's JavaCC grammar to generate JavaScript (maybe it's not impossible? https://github.com/javacc/javacc-8-js)
  • Use a different solution than Yasgui's grammar/parser to generate the tokens in SPARQL with RDF-Star support (I think that's what CodeMirror needs), and replace the tokens in YASR in jena-fuseki-ui

But first will have a little more fun trying to remember how Prolog works 🤓

@kinow
Copy link

kinow commented Jan 22, 2023

Fixed it by using an older version of swipl 👍 now back to reading the RDF-Star docs & grammars 🙂

@kinow
Copy link

kinow commented Jan 23, 2023

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... 😥

@VladimirAlexiev
Copy link

@kinow
Copy link

kinow commented Jan 23, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants