diff options
Diffstat (limited to 'rdflib/plugins/sparql')
-rw-r--r-- | rdflib/plugins/sparql/algebra.py | 20 | ||||
-rw-r--r-- | rdflib/plugins/sparql/evaluate.py | 1 | ||||
-rw-r--r-- | rdflib/plugins/sparql/evalutils.py | 2 | ||||
-rw-r--r-- | rdflib/plugins/sparql/operators.py | 52 | ||||
-rw-r--r-- | rdflib/plugins/sparql/parser.py | 8 | ||||
-rw-r--r-- | rdflib/plugins/sparql/parserutils.py | 4 | ||||
-rw-r--r-- | rdflib/plugins/sparql/results/graph.py | 2 | ||||
-rw-r--r-- | rdflib/plugins/sparql/results/tsvresults.py | 2 | ||||
-rw-r--r-- | rdflib/plugins/sparql/results/xmlresults.py | 3 | ||||
-rw-r--r-- | rdflib/plugins/sparql/sparql.py | 2 |
10 files changed, 47 insertions, 49 deletions
diff --git a/rdflib/plugins/sparql/algebra.py b/rdflib/plugins/sparql/algebra.py index f84e51c9..cfd4f410 100644 --- a/rdflib/plugins/sparql/algebra.py +++ b/rdflib/plugins/sparql/algebra.py @@ -95,7 +95,7 @@ def _knownTerms(triple, varsknown, varscount): ) -def reorderTriples(l): +def reorderTriples(l_): """ Reorder triple patterns so that we execute the ones with most bindings first @@ -105,10 +105,10 @@ def reorderTriples(l): if isinstance(term, (Variable, BNode)): varsknown.add(term) - l = [(None, x) for x in l] + l_ = [(None, x) for x in l_] varsknown = set() varscount = collections.defaultdict(int) - for t in l: + for t in l_: for c in t[1]: if isinstance(c, (Variable, BNode)): varscount[c] += 1 @@ -121,17 +121,17 @@ def reorderTriples(l): # we sort by decorate/undecorate, since we need the value of the sort keys - while i < len(l): - l[i:] = sorted((_knownTerms(x[1], varsknown, varscount), x[1]) for x in l[i:]) - t = l[i][0][0] # top block has this many terms bound + while i < len(l_): + l_[i:] = sorted((_knownTerms(x[1], varsknown, varscount), x[1]) for x in l_[i:]) + t = l_[i][0][0] # top block has this many terms bound j = 0 - while i + j < len(l) and l[i + j][0][0] == t: - for c in l[i + j][1]: + while i + j < len(l_) and l_[i + j][0][0] == t: + for c in l_[i + j][1]: _addvar(c, varsknown) j += 1 i += 1 - return [x[1] for x in l] + return [x[1] for x in l_] def triples(l): @@ -826,7 +826,7 @@ if __name__ == "__main__": import os.path if os.path.exists(sys.argv[1]): - q = file(sys.argv[1]) + q = open(sys.argv[1]).read() else: q = sys.argv[1] diff --git a/rdflib/plugins/sparql/evaluate.py b/rdflib/plugins/sparql/evaluate.py index 43b3d0b0..6c47eec3 100644 --- a/rdflib/plugins/sparql/evaluate.py +++ b/rdflib/plugins/sparql/evaluate.py @@ -42,7 +42,6 @@ from rdflib.plugins.sparql.evalutils import ( ) from rdflib.plugins.sparql.aggregates import Aggregator -from rdflib.plugins.sparql.algebra import Join, ToMultiSet, Values from rdflib.plugins.sparql import parser diff --git a/rdflib/plugins/sparql/evalutils.py b/rdflib/plugins/sparql/evalutils.py index 8bf1981d..72b767a1 100644 --- a/rdflib/plugins/sparql/evalutils.py +++ b/rdflib/plugins/sparql/evalutils.py @@ -3,7 +3,7 @@ import collections from rdflib.term import Variable, Literal, BNode, URIRef from rdflib.plugins.sparql.operators import EBV -from rdflib.plugins.sparql.parserutils import Expr, CompValue, value +from rdflib.plugins.sparql.parserutils import Expr, CompValue from rdflib.plugins.sparql.sparql import SPARQLError, NotBoundError diff --git a/rdflib/plugins/sparql/operators.py b/rdflib/plugins/sparql/operators.py index 8f644a1f..ef995ce0 100644 --- a/rdflib/plugins/sparql/operators.py +++ b/rdflib/plugins/sparql/operators.py @@ -168,16 +168,16 @@ def Builtin_CEIL(expr, ctx): http://www.w3.org/TR/sparql11-query/#func-ceil """ - l = expr.arg - return Literal(int(math.ceil(numeric(l))), datatype=l.datatype) + l_ = expr.arg + return Literal(int(math.ceil(numeric(l_))), datatype=l_.datatype) def Builtin_FLOOR(expr, ctx): """ http://www.w3.org/TR/sparql11-query/#func-floor """ - l = expr.arg - return Literal(int(math.floor(numeric(l))), datatype=l.datatype) + l_ = expr.arg + return Literal(int(math.floor(numeric(l_))), datatype=l_.datatype) def Builtin_ROUND(expr, ctx): @@ -189,10 +189,10 @@ def Builtin_ROUND(expr, ctx): # but in py3k bound was changed to # "round-to-even" behaviour # this is an ugly work-around - l = expr.arg - v = numeric(l) + l_ = expr.arg + v = numeric(l_) v = int(Decimal(v).quantize(1, ROUND_HALF_UP)) - return Literal(v, datatype=l.datatype) + return Literal(v, datatype=l_.datatype) def Builtin_REGEX(expr, ctx): @@ -371,7 +371,7 @@ def Builtin_STRAFTER(expr, ctx): if i == -1: return Literal("") else: - return Literal(a[i + len(b) :], lang=a.language, datatype=a.datatype) + return Literal(a[i + len(b):], lang=a.language, datatype=a.datatype) def Builtin_CONTAINS(expr, ctx): @@ -407,9 +407,9 @@ def Builtin_SUBSTR(expr, ctx): def Builtin_STRLEN(e, ctx): - l = string(e.arg) + l_ = string(e.arg) - return Literal(len(l)) + return Literal(len(l_)) def Builtin_STR(e, ctx): @@ -420,9 +420,9 @@ def Builtin_STR(e, ctx): def Builtin_LCASE(e, ctx): - l = string(e.arg) + l_ = string(e.arg) - return Literal(l.lower(), datatype=l.datatype, lang=l.language) + return Literal(l_.lower(), datatype=l_.datatype, lang=l_.language) def Builtin_LANGMATCHES(e, ctx): @@ -528,9 +528,9 @@ def Builtin_TZ(e, ctx): def Builtin_UCASE(e, ctx): - l = string(e.arg) + l_ = string(e.arg) - return Literal(l.upper(), datatype=l.datatype, lang=l.language) + return Literal(l_.upper(), datatype=l_.datatype, lang=l_.language) def Builtin_LANG(e, ctx): @@ -542,19 +542,19 @@ def Builtin_LANG(e, ctx): with an empty language tag. """ - l = literal(e.arg) - return Literal(l.language or "") + l_ = literal(e.arg) + return Literal(l_.language or "") def Builtin_DATATYPE(e, ctx): - l = e.arg - if not isinstance(l, Literal): - raise SPARQLError("Can only get datatype of literal: %r" % l) - if l.language: + l_ = e.arg + if not isinstance(l_, Literal): + raise SPARQLError("Can only get datatype of literal: %r" % l_) + if l_.language: return RDF_langString - if not l.datatype and not l.language: + if not l_.datatype and not l_.language: return XSD.string - return l.datatype + return l_.datatype def Builtin_sameTerm(e, ctx): @@ -825,7 +825,7 @@ def RelationalExpression(e, ctx): else: raise error - if not op in ("=", "!=", "IN", "NOT IN"): + if op not in ("=", "!=", "IN", "NOT IN"): if not isinstance(expr, Literal): raise SPARQLError( "Compare other than =, != of non-literals is an error: %r" % expr @@ -1062,15 +1062,15 @@ def _lang_range_check(range, lang): """ - def _match(r, l): + def _match(r, l_): """ Matching of a range and language item: either range is a wildcard or the two are equal @param r: language range item - @param l: language tag item + @param l_: language tag item @rtype: boolean """ - return r == "*" or r == l + return r == "*" or r == l_ rangeList = range.strip().lower().split("-") langList = lang.strip().lower().split("-") diff --git a/rdflib/plugins/sparql/parser.py b/rdflib/plugins/sparql/parser.py index e8c37a2e..2124aad2 100644 --- a/rdflib/plugins/sparql/parser.py +++ b/rdflib/plugins/sparql/parser.py @@ -61,7 +61,7 @@ def expandTriples(terms): res = [] if DEBUG: print("Terms", terms) - l = len(terms) + l_ = len(terms) for i, t in enumerate(terms): if t == ",": res.extend([res[-3], res[-2]]) @@ -78,7 +78,7 @@ def expandTriples(terms): if len(t) > 1: res += t # is this bnode the subject of more triples? - if i + 1 < l and terms[i + 1] not in ".,;": + if i + 1 < l_ and terms[i + 1] not in ".,;": res.append(t[0]) elif isinstance(t, ParseResults): res += t.asList() @@ -1058,9 +1058,9 @@ MultiplicativeExpression = Comp( # [116] AdditiveExpression ::= MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | ( NumericLiteralPositive | NumericLiteralNegative ) ( ( '*' UnaryExpression ) | ( '/' UnaryExpression ) )* )* # NOTE: The second part of this production is there because: -### "In signed numbers, no white space is allowed between the sign and the number. The AdditiveExpression grammar rule allows for this by covering the two cases of an expression followed by a signed number. These produce an addition or subtraction of the unsigned number as appropriate." +# "In signed numbers, no white space is allowed between the sign and the number. The AdditiveExpression grammar rule allows for this by covering the two cases of an expression followed by a signed number. These produce an addition or subtraction of the unsigned number as appropriate." -# Here (I think) this is not nescessary since pyparsing doesn't separate +# Here (I think) this is not necessary since pyparsing doesn't separate # tokenizing and parsing diff --git a/rdflib/plugins/sparql/parserutils.py b/rdflib/plugins/sparql/parserutils.py index e67b754b..c30e10d6 100644 --- a/rdflib/plugins/sparql/parserutils.py +++ b/rdflib/plugins/sparql/parserutils.py @@ -4,7 +4,7 @@ from collections import OrderedDict from pyparsing import TokenConverter, ParseResults, originalTextFor -from rdflib import BNode, Variable, URIRef +from rdflib import BNode, Variable DEBUG = True DEBUG = False @@ -235,7 +235,7 @@ class Comp(TokenConverter): for t in tokenList: if isinstance(t, ParamValue): if t.isList: - if not t.name in res: + if t.name not in res: res[t.name] = plist() res[t.name].append(t.tokenList) else: diff --git a/rdflib/plugins/sparql/results/graph.py b/rdflib/plugins/sparql/results/graph.py index 13e256bb..77715d07 100644 --- a/rdflib/plugins/sparql/results/graph.py +++ b/rdflib/plugins/sparql/results/graph.py @@ -1,6 +1,6 @@ from rdflib import Graph -from rdflib.query import Result, ResultParser, ResultSerializer, ResultException +from rdflib.query import Result, ResultParser class GraphResultParser(ResultParser): diff --git a/rdflib/plugins/sparql/results/tsvresults.py b/rdflib/plugins/sparql/results/tsvresults.py index bdfa2d4a..2406cf4e 100644 --- a/rdflib/plugins/sparql/results/tsvresults.py +++ b/rdflib/plugins/sparql/results/tsvresults.py @@ -108,7 +108,7 @@ class TSVResultParser(ResultParser): if __name__ == "__main__": import sys - r = Result.parse(file(sys.argv[1]), format="tsv") + r = Result.parse(source=sys.argv[1], format="tsv") print(r.vars) print(r.bindings) # print r.serialize(format='json') diff --git a/rdflib/plugins/sparql/results/xmlresults.py b/rdflib/plugins/sparql/results/xmlresults.py index aa4f796f..1511783f 100644 --- a/rdflib/plugins/sparql/results/xmlresults.py +++ b/rdflib/plugins/sparql/results/xmlresults.py @@ -1,5 +1,4 @@ import logging -from io import BytesIO from xml.sax.saxutils import XMLGenerator from xml.dom import XML_NAMESPACE @@ -7,7 +6,7 @@ from xml.sax.xmlreader import AttributesNSImpl from rdflib.compat import etree -from rdflib import Literal, URIRef, BNode, Graph, Variable +from rdflib import Literal, URIRef, BNode, Variable from rdflib.query import Result, ResultParser, ResultSerializer, ResultException diff --git a/rdflib/plugins/sparql/sparql.py b/rdflib/plugins/sparql/sparql.py index 5b6eab2e..417edc03 100644 --- a/rdflib/plugins/sparql/sparql.py +++ b/rdflib/plugins/sparql/sparql.py @@ -287,7 +287,7 @@ class QueryContext(object): return graph.load(source, format="nt", **kwargs) except: raise Exception( - "Could not load %s as either RDF/XML, N3 or NTriples" % (source) + "Could not load %s as either RDF/XML, N3 or NTriples" % source ) if not rdflib.plugins.sparql.SPARQL_LOAD_GRAPHS: |