Skip to content

Commit

Permalink
Add ability to specify custom parser
Browse files Browse the repository at this point in the history
This will allow for hacking in a custom SPARQL processor, that e.g., rewrites some nodes as we demonstrated in biopragmatics/curies#41
  • Loading branch information
cthoyt authored Mar 15, 2023
1 parent 4b37be0 commit 0deca37
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/rdflib_endpoint/sparql_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from rdflib.plugins.sparql.evaluate import evalPart
from rdflib.plugins.sparql.evalutils import _eval
from rdflib.plugins.sparql.parserutils import CompValue
from rdflib.plugins.sparql.query import Processor
from rdflib.plugins.sparql.sparql import QueryContext, SPARQLError


Expand All @@ -29,6 +30,7 @@ def __init__(
description: str = "A SPARQL endpoint to serve machine learning models, or any other logic implemented in Python. \n[Source code](https://github.com/vemonet/rdflib-endpoint)",
version: str = "0.1.0",
graph: Union[Graph, ConjunctiveGraph, Dataset] = ConjunctiveGraph(),
processor: Union[str, Processor] = "sparql",,
functions: Dict[str, Callable[..., Any]] = {},
custom_eval: Optional[Callable[..., Any]] = None,
enable_update: bool = False,
Expand All @@ -46,6 +48,7 @@ def __init__(
FastAPI calls are defined in this constructor
"""
self.graph = graph
self.processor = processor
self.functions = functions
self.title = title
self.description = description
Expand Down Expand Up @@ -206,7 +209,7 @@ async def sparql_endpoint(request: Request, query: Optional[str] = Query(None))

try:
# query_results = self.graph.query(query, initNs=graph_ns)
query_results = self.graph.query(query)
query_results = self.graph.query(query, processor=self.processor)
except Exception as e:
logging.error("Error executing the SPARQL query on the RDFLib Graph: " + str(e))
return JSONResponse(
Expand Down

0 comments on commit 0deca37

Please sign in to comment.