|
@@ -4,7 +4,7 @@ import logging
|
|
|
import re
|
|
|
import arklog
|
|
|
import rdflib
|
|
|
-from typing import Any, Callable, Dict, List, Optional, Union
|
|
|
+from typing import Any, Dict, List, Optional, Union
|
|
|
from urllib import parse
|
|
|
from fastapi import FastAPI, Query, Request, Response
|
|
|
from fastapi.responses import JSONResponse
|
|
@@ -15,6 +15,8 @@ from rdflib.plugins.sparql.evalutils import _eval
|
|
|
from rdflib.plugins.sparql.parserutils import CompValue
|
|
|
from rdflib.plugins.sparql.sparql import QueryContext, SPARQLError
|
|
|
|
|
|
+from spendpoint import service
|
|
|
+
|
|
|
arklog.set_config_logging()
|
|
|
|
|
|
|
|
@@ -57,13 +59,13 @@ class SparqlEndpoint(FastAPI):
|
|
|
return "application/rdf+xml"
|
|
|
return output_mime_type
|
|
|
|
|
|
- def __init__(self, *args: Any, title: str, description: str, version: str, functions: Dict[str, Callable[..., Any]], graph: Union[Graph, ConjunctiveGraph, Dataset] = ConjunctiveGraph(), **kwargs: Any):
|
|
|
+ def __init__(self, *args: Any, title: str, description: str, version: str, configuration, graph: Union[Graph, ConjunctiveGraph, Dataset] = ConjunctiveGraph(), **kwargs: Any):
|
|
|
""""""
|
|
|
self.graph = graph
|
|
|
- self.functions = functions
|
|
|
self.title = title
|
|
|
self.description = description
|
|
|
self.version = version
|
|
|
+ self.configuration = configuration
|
|
|
super().__init__(*args, title=title, description=description, version=version, **kwargs)
|
|
|
logging.debug(self.description)
|
|
|
rdflib.plugins.sparql.CUSTOM_EVALS["evalCustomFunctions"] = self.eval_custom_functions
|
|
@@ -166,12 +168,10 @@ class SparqlEndpoint(FastAPI):
|
|
|
for eval_part in evalPart(ctx, part.p):
|
|
|
# Checks if the function is a URI (custom function)
|
|
|
if hasattr(part.expr, "iri"):
|
|
|
- # Iterate through the custom functions passed in the constructor
|
|
|
- for function_uri, custom_function in self.functions.items():
|
|
|
+ for conf_service in self.configuration.services:
|
|
|
# Check if URI correspond to a registered custom function
|
|
|
- if part.expr.iri == URIRef(function_uri):
|
|
|
- # Execute each function
|
|
|
- query_results, ctx, part, eval_part = custom_function(query_results, ctx, part, eval_part)
|
|
|
+ if part.expr.iri == URIRef(conf_service.namespace):
|
|
|
+ query_results, ctx, part, eval_part = getattr(service, conf_service.call)(query_results, ctx, part, eval_part, conf_service)
|
|
|
else:
|
|
|
# For built-in SPARQL functions (that are not URIs)
|
|
|
evaluation: List[Any] = [_eval(part.expr, eval_part.forget(ctx, _except=part._vars))]
|