def evalQuery(graph, query, initBindings, base=None): ctx = QueryContext(graph) ctx.prologue = query.prologue if initBindings: for k, v in initBindings.iteritems(): if not isinstance(k, Variable): k = Variable(k) ctx[k] = v ctx.push() # nescessary? main = query.algebra # import pdb; pdb.set_trace() if main.datasetClause: if ctx.dataset is None: raise Exception( "Non-conjunctive-graph doesn't know about " + "graphs! Try a query without FROM (NAMED).") ctx = ctx.clone() # or push/pop? firstDefault = False for d in main.datasetClause: if d.default: if firstDefault: # replace current default graph dg = ctx.dataset.get_context(BNode()) ctx.pushGraph(dg) firstDefault = True ctx.load(d.default, default=True) elif d.named: g = d.named ctx.load(g, default=False) return evalPart(ctx, main)
def evalQuery(graph, query, initBindings, base=None): ctx = QueryContext(graph) ctx.prologue = query.prologue if initBindings: for k, v in initBindings.iteritems(): if not isinstance(k, Variable): k = Variable(k) ctx[k] = v ctx.push() # nescessary? main = query.algebra # import pdb; pdb.set_trace() if main.datasetClause: if ctx.dataset is None: raise Exception("Non-conjunctive-graph doesn't know about " + "graphs! Try a query without FROM (NAMED).") ctx = ctx.clone() # or push/pop? firstDefault = False for d in main.datasetClause: if d.default: if firstDefault: # replace current default graph dg = ctx.dataset.get_context(BNode()) ctx.pushGraph(dg) firstDefault = True ctx.load(d.default, default=True) elif d.named: g = d.named ctx.load(g, default=False) return evalPart(ctx, main)
def evalUpdate(graph, update, initBindings=None): """ http://www.w3.org/TR/sparql11-update/#updateLanguage 'A request is a sequence of operations [...] Implementations MUST ensure that operations of a single request are executed in a fashion that guarantees the same effects as executing them in lexical order. Operations all result either in success or failure. If multiple operations are present in a single request, then a result of failure from any operation MUST abort the sequence of operations, causing the subsequent operations to be ignored.' This will return None on success and raise Exceptions on error """ for u in update: ctx = QueryContext(graph) ctx.prologue = u.prologue if initBindings: for k, v in initBindings.iteritems(): if not isinstance(k, Variable): k = Variable(k) ctx[k] = v ctx.push() # nescessary? try: if u.name == 'Load': evalLoad(ctx, u) elif u.name == 'Clear': evalClear(ctx, u) elif u.name == 'Drop': # rdflib does not record empty graphs, so clear == drop evalClear(ctx, u) elif u.name == 'Create': evalCreate(ctx, u) elif u.name == 'Add': evalAdd(ctx, u) elif u.name == 'Move': evalMove(ctx, u) elif u.name == 'Copy': evalCopy(ctx, u) elif u.name == 'InsertData': evalInsertData(ctx, u) elif u.name == 'DeleteData': evalDeleteData(ctx, u) elif u.name == 'DeleteWhere': evalDeleteWhere(ctx, u) elif u.name == 'Modify': evalModify(ctx, u) else: raise Exception('Unknown update operation: %s' % (u, )) except: if not u.silent: raise
def evalUpdate(graph, update, initBindings=None): """ http://www.w3.org/TR/sparql11-update/#updateLanguage 'A request is a sequence of operations [...] Implementations MUST ensure that operations of a single request are executed in a fashion that guarantees the same effects as executing them in lexical order. Operations all result either in success or failure. If multiple operations are present in a single request, then a result of failure from any operation MUST abort the sequence of operations, causing the subsequent operations to be ignored.' This will return None on success and raise Exceptions on error """ for u in update: ctx = QueryContext(graph) ctx.prologue = u.prologue if initBindings: for k, v in initBindings.iteritems(): if not isinstance(k, Variable): k = Variable(k) ctx[k] = v ctx.push() # nescessary? try: if u.name == 'Load': evalLoad(ctx, u) elif u.name == 'Clear': evalClear(ctx, u) elif u.name == 'Drop': # rdflib does not record empty graphs, so clear == drop evalClear(ctx, u) elif u.name == 'Create': evalCreate(ctx, u) elif u.name == 'Add': evalAdd(ctx, u) elif u.name == 'Move': evalMove(ctx, u) elif u.name == 'Copy': evalCopy(ctx, u) elif u.name == 'InsertData': evalInsertData(ctx, u) elif u.name == 'DeleteData': evalDeleteData(ctx, u) elif u.name == 'DeleteWhere': evalDeleteWhere(ctx, u) elif u.name == 'Modify': evalModify(ctx, u) else: raise Exception('Unknown update operation: %s' % (u,)) except: if not u.silent: raise