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

rdflib.plugins.sparql.CUSTOM_EVALS["exampleEval"] = customEval #1

Closed
rchateauneu opened this issue Dec 16, 2021 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@rchateauneu
Copy link

I would like to know if this is possible to implement this kind of custom evaluation function, such as in this example:
Source code for examples.custom_eval

Also, do you please know if this would work in a federated query from Wikidata or Wikibase ? Thanks.

@vemonet
Copy link
Owner

vemonet commented Dec 17, 2021

Hi @rchateauneu, thanks for the feedback! I think that should be possible relatively easily, and that would be a required to enable full use of RDFLib custom evals

Currently I focused on implementing custom functions because that was my use-case, but enabling it also for BGP would be better
I am already using the custom eval, but in my case I try to make it easier for the users to define and register multiple functions without having to play too much with the RDFLib SPARQL parsing internals

cf. calling the CUSTOM_EVALS: https://github.com/vemonet/rdflib-endpoint/blob/main/rdflib_endpoint/sparql_endpoint.py#L69
And generating the CUSTOM_EVALS from the list of functions registered by the user: https://github.com/vemonet/rdflib-endpoint/blob/main/rdflib_endpoint/sparql_endpoint.py#L272

2 solutions would come to my mind here:

  1. Allowing the user to directly provide their own CUSTOM_EVALS which would overwrite the one I generate from the provided custom functions
  2. Implementing a custom_bgp argument, similar to the current custom_functions arg to make it easier for the users to register multiple custom BGP (requires more dev an testing)

Solution 1 is a must-have, that would allow to cover all use-cases I don't think of, I guess that's the solution you'll prefer? And we can also have both in the end: user-friendly "just define your functions", and flexible "rewrite everything by yourself"

I will look into it when I have some time, but feel free to send a pull requests if you want to fix it asap!

I tried the SPARQL endpoint federated queries from Virtuoso (Jena based) and Ontotext GraphDB (RDF4J based) and they were working, I don't think I tried Blazegraph (which is the triplestore used by Wikibase). I would expect it to work, but you never know...
I'll try it next time I put up a public rdflib-endpoint, let me know if you are facing a problem in the meantime

@vemonet vemonet added the enhancement New feature or request label Dec 17, 2021
@rchateauneu
Copy link
Author

Thanks for the answer.

What I wish it to create a Sparql endpoint usable from a Wikidata query such as these ones:
Wikidata:SPARQL query service/Federated queries
https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/Federated_queries

Any implementation would be OK as long as I can implement the specific feature of accessing the BGP from part.triples, add more triples to ctx.graph and finally call evalBGP(ctx, part.triples).

@vemonet
Copy link
Owner

vemonet commented Jan 10, 2022

Hi @rchateauneu, I added the option to pass directly the custom evaluation, released in 0.1.5

You can find an example to use it there: https://github.com/vemonet/rdflib-endpoint#-or-directly-define-the-custom-evaluation

Let me know if it is working as expected for you!

@vemonet vemonet closed this as completed Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants