Extension of SPARQL syntax - sparql

I am trying to extend SPARQL by introducing new clauses in the syntax. Is there a way to do this using graphdb?
I need a headstart for this

GraphDB uses the Eclipse RDF4J SPARQL parser, which is open-source, so you can extend that easily enough. The parser is defined as a JavaCC grammar file (see sparql.jjt in rdf4j github), so the easiest way to exend is to add your extensions to that grammar file and then recompile the parser using JavaCC.
However, given that, once you've parsed something, you need to transform it into an algebra model that then the underlying triplestore can actually do something with, extending the parser is the easy part.

Related

Can SHACL be implemented using SPARQL?

I'm trying to find a way to implement SHACL validations using SPARQL in my AWS Neptune Graph database. Is there a way to do so?
Well, it depends on what you mean by "implement". ;-)
You cannot implement all of SHACL with SPARQL alone, but you could implement some subset; not with a single query, though. You could, for example, write a query that collects the constraints of your shapes, and then use those results to generate a query that gets the relevant parts of your data; you could then examine those results and produce a validation report. And if you are doing stuff programmatically, you could of course implement also those parts with cannot be expressed through SPARQL (e.g., literal string patterns).
All that is somewhat "academic". There are open source SHACL implementations that you could use as a Neptune client (e.g., pySHACL if you are using Python and RDFLib). That would be a better and certainly a far more practical way.

Does RDF4J's AST allow for SPARQL Query Rewriting?

According to a couple answers here and here, it seems that it might be possible to use the AST produced by RDF4J's SyntaxTreeBuilder to modify a parsed SPARQL query in memory and then serialize it back to a SPARQL string. However, I have not found any implementations that handle this serialization given the AST. The closest thing of course is the SparqlQueryRenderer but my use case demands working with the AST, not the SPARQL algebra model.
Naturally, I could imagine implementing a class that rebuilds the SPARQL query string as an AST visitor, but I would rather use a different library if it is not already supported or implemented for RDF4J.

Export a project in RDF

Is it possible to export a project in RDF (XML/RDF, N3 or other serialisation)?
Use case :
I imported RDF/XML data in Openrefine, made changes to some values, and wanted to export the result in RDF/XML, in order to replace the original file.
Yes, you can use the RDF extension for that.
I am not sure how easy it is to match the format of the RDF file you started from though. OpenRefine is primarily designed to work on tabular data so there might be better tools for this workflow.
I agree with #pintoch that OpenRefine is not necessarily the right tool for that. Was there a specific reason that you used OpenRefine and did not edit the RDF directly? Turtle is the best serialization in case you simply want to do some basic changes. For more complex things you could use Apache Jena tooling and for example write some SPARQL queries that bulk-edit content in the RDF.
If you describe in more details what you were doing we might give some other tips. But if it had to be OpenRefine, the RDF extension he linked is what you want.
Thank you
I have no specific use case, but I will train some people to use Openrefine, and I wanted to know if it was the right tool to batch edit RDF files. Well, it seems it is not the case.

Using dotnetRDF library to query Large RDF file by SPARQL

i want to query an Ontology which is defined in an RDF file using SPARQL and dotnetRDF library. The problem is that the file is large, so it's not very practical to load the entire file in memory. What should i do ?
Thanks in advance
As AKSW says in the comment, the best approach would be to load your RDF file into a triple store and then run your SPARQL queries against that. dotNetRDF ships with support for several triple stores as listed at https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Storage-Providers. However, all you really need is a triple store that supports the SPARQL protocol and then you will be able to run your queries from dotNetRDF code using the SparqlRemoteEndpointclass as described at https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Querying-With-SPARQL#remote-query.
As for which triple store to use, Jena with Fuseki is probably a good open-source choice.

Is there an ANTLR grammar for just the where clause of an ANSI SQL query?

Is there an ANTLR grammar for just the where clause of an ANSI SQL query?
i am trying to parse the conditions in where clause and change the column in that condition to something relevant to the indexes i have, so that my performance can be improved.
i want to automate this feature, so want to parse the dynamic sql and change the where clause dynamically.
Probably not.
I assume you've found an ANTLR grammar for all of ANSI SQL.
Picking out the subset that is just the where clause shouldn't really be hard.
What you'll have a harder time with is modifying the AST and regenerating source text, which I presume you want. ANTLR parsers provide no specific help in modifying the AST other than a library for hacking at the nodes as you visit them. Regeneration of source is completely on you; it can be implemented by spitting strings as you walk the tree or better, using String templates. But what has happened now is that your interest in modifying the statement has turned into a big(?) engineering job before you can do it.
See my essay on "Life After Parsing" (from bio or by googling).
I think what you want is a program transformation system. These are tools that given a grammar, can parse source code to ASTs, and carry out transformations on the AST to achieve the effect you want. PrettyPrinters to regenerate source text are usually provided.