-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove forked code from processor, monkey patch instead
- Loading branch information
1 parent
76f798b
commit 1a251d9
Showing
1 changed file
with
7 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,13 @@ | ||
from rdflib.query import Processor, Result, UpdateProcessor | ||
from rdflib.plugins.sparql.sparql import Query | ||
from rdflib.plugins.sparql.parser import parseQuery, parseUpdate | ||
|
||
from quit.tools.algebra import translateQuery, translateUpdate | ||
from quit.tools.evaluate import evalQuery | ||
from quit.tools.update import evalUpdate | ||
|
||
class SPARQLUpdateProcessor(UpdateProcessor): | ||
def __init__(self, graph): | ||
self.graph = graph | ||
|
||
def update(self, strOrQuery, initBindings={}, initNs={}): | ||
if isinstance(strOrQuery, str): | ||
strOrQuery=translateUpdate(parseUpdate(strOrQuery), initNs=initNs) | ||
|
||
return evalUpdate(self.graph, strOrQuery, initBindings) | ||
|
||
|
||
class SPARQLProcessor(Processor): | ||
|
||
def __init__(self, graph): | ||
self.graph = graph | ||
|
||
def query( | ||
self, strOrQuery, initBindings={}, | ||
initNs={}, base=None, DEBUG=False): | ||
""" | ||
Evaluate a query with the given initial bindings, and initial | ||
namespaces. The given base is used to resolve relative URIs in | ||
the query and will be overridden by any BASE given in the query. | ||
""" | ||
import rdflib.plugins.sparql.processor | ||
|
||
if not isinstance(strOrQuery, Query): | ||
parsetree = parseQuery(strOrQuery) | ||
query = translateQuery(parsetree, base, initNs) | ||
else: | ||
query = strOrQuery | ||
rdflib.plugins.sparql.processor.evalQuery = evalQuery | ||
rdflib.plugins.sparql.processor.evalUpdate = evalUpdate | ||
rdflib.plugins.sparql.processor.translateQuery = translateQuery | ||
rdflib.plugins.sparql.processor.translateUpdate = translateUpdate | ||
|
||
return evalQuery(self.graph, query, initBindings, base) | ||
SPARQLUpdateProcessor = rdflib.plugins.sparql.processor.SPARQLUpdateProcessor | ||
SPARQLProcessor = rdflib.plugins.sparql.processor.SPARQLProcessor |