1
1
# -*- coding: utf-8 -*-
2
2
3
3
"""
4
- @see: U{SPARQL Specification<http://www.w3.org/TR/rdf-sparql-query/>}
5
- @authors: U{Ivan Herman<http://www.ivan-herman.net>}, U{Sergio Fernández<http://www.wikier.org>}, U{Carlos Tejo Alonso<http://www.dayures.net>}
6
- @organization: U{World Wide Web Consortium<http://www.w3.org>} and U{Foundation CTIC<http://www.fundacionctic.org/>}.
7
- @license: U{W3C® SOFTWARE NOTICE AND LICENSE<href="http://www.w3.org/Consortium/Legal/copyright-software">}
8
- @requires: U{RDFLib<http://rdflib.net>} package.
4
+ .. seealso:: `SPARQL Specification <http://www.w3.org/TR/rdf-sparql-query/>`_
5
+
6
+ :author: Ivan Herman <http://www.ivan-herman.net>
7
+ :author: Sergio Fernández <http://www.wikier.org>
8
+ :author: Carlos Tejo Alonso <http://www.dayures.net>
9
+ :author: Alexey Zakhlestin <https://indeyets.ru/>
10
+ :organization: `World Wide Web Consortium <http://www.w3.org>`_ and `Foundation CTIC <http://www.fundacionctic.org/>`_.
11
+ :license: `W3C® Software notice and license <http://www.w3.org/Consortium/Legal/copyright-software>`_
12
+ :requires: `RDFLib <https://rdflib.readthedocs.io>`_ package.
9
13
"""
10
14
11
15
import urllib2
@@ -74,19 +78,19 @@ class Bindings(object):
74
78
return value and instantiates a number of attributes that can be consulted directly. See
75
79
the list of variables.
76
80
77
- The U{ Serializing SPARQL Query Results in JSON<http://www.w3.org/TR/rdf-sparql-json-res/>} explains the details of the
78
- JSON return structures. Very succintly : the return data has "bindings", which means a list of dictionaries. Each
81
+ The ` Serializing SPARQL Query Results in JSON <http://www.w3.org/TR/rdf-sparql-json-res/>`_ explains the details of the
82
+ JSON return structures. Very succinctly : the return data has "bindings", which means a list of dictionaries. Each
79
83
dictionary is a possible binding of the SELECT variables to :class:`Value` instances. This structure is made a bit
80
84
more usable by this class.
81
85
82
86
:ivar fullResult: The original dictionary of the results, stored for an easier reference
83
87
:ivar head: Header part of the return, see the JSON return format document for details
84
88
:ivar variables: List of unbounds (variables) of the original query. It is an array of strings. None in the case of an ASK query
85
- :ivar bindings: The final bindings: array of dictionaries, mapping variables to :class:`Value` instances.
86
- (If unbound, then no value is set in the dictionary; that can be easily checked with
87
- C{ var in res.bindings[..]} , for example.)
89
+ :ivar bindings: The final bindings: array of dictionaries, mapping variables to :class:`Value` instances. \
90
+ (If unbound, then no value is set in the dictionary; that can be easily checked with \
91
+ `` var in res.bindings[..]`` , for example.)
88
92
:ivar askResult: by default, set to False; in case of an ASK query, the result of the query
89
- :type askResult: Boolean
93
+ :type askResult: bool
90
94
"""
91
95
def __init__ (self , retval ):
92
96
"""
@@ -122,7 +126,7 @@ def __init__(self, retval):
122
126
123
127
def getValues (self , key ):
124
128
"""A shorthand for the retrieval of all bindings for a single key. It is
125
- equivalent to "C{ [b[key] for b in self[key]]} "
129
+ equivalent to "`` [b[key] for b in self[key]]`` "
126
130
127
131
:param key: possible variable
128
132
:return: list of :class:`Value` instances
@@ -133,12 +137,12 @@ def getValues(self, key):
133
137
return []
134
138
135
139
def __contains__ (self , key ):
136
- """Emulation of the "C{ key in obj} " operator. Key can be a string for a variable or an array/tuple
140
+ """Emulation of the "`` key in obj`` " operator. Key can be a string for a variable or an array/tuple
137
141
of strings.
138
142
139
- If C{ key} is a variable, the return value is C{ True} if there is at least one binding where C{ key} is
140
- bound. If C{ key} is an array or tuple, the return value is C{ True} if there is at least one binding
141
- where I{ all} variables in C{ key} are bound.
143
+ If `` key`` is a variable, the return value is `` True`` if there is at least one binding where `` key`` is
144
+ bound. If `` key`` is an array or tuple, the return value is `` True`` if there is at least one binding
145
+ where * all* variables in `` key`` are bound.
142
146
143
147
:param key: possible variable, or array/tuple of variables
144
148
:return: whether there is a binding of the variable in the return
@@ -168,16 +172,16 @@ def __contains__(self, key):
168
172
return False
169
173
170
174
def __getitem__ (self , key ):
171
- """Emulation of the C{ obj[key]} operator. Slice notation is also available.
175
+ """Emulation of the `` obj[key]`` operator. Slice notation is also available.
172
176
The goal is to choose the right bindings among the available ones. The return values are always
173
177
arrays of bindings, ie, arrays of dictionaries mapping variable keys to :class:`Value` instances.
174
178
The different value settings mean the followings:
175
179
176
- - C{ obj[key]} returns the bindings where C{ key} has a valid value
177
- - C{ obj[key1,key2,...]} returns the bindings where I{ all} C{ key1,key2,...} have valid values
178
- - C{ obj[(key1,key2,...):(nkey1,nkey2,...)]} returns the bindings where all C{ key1,key2,...} have
179
- valid values and I{ none} of the C{ nkey1,nkey2,...} have valid values
180
- - C{ obj[:(nkey1,nkey2,...)]} returns the bindings where I{ none} of the C{ nkey1,nkey2,...} have valid values
180
+ - `` obj[key]`` returns the bindings where `` key`` has a valid value
181
+ - `` obj[key1,key2,...]`` returns the bindings where * all* `` key1,key2,...`` have valid values
182
+ - `` obj[(key1,key2,...):(nkey1,nkey2,...)]`` returns the bindings where all `` key1,key2,...`` have
183
+ valid values and * none* of the `` nkey1,nkey2,...`` have valid values
184
+ - `` obj[:(nkey1,nkey2,...)]`` returns the bindings where * none* of the `` nkey1,nkey2,...`` have valid values
181
185
182
186
In all cases complete bindings are returned, ie, the values for other variables, not present among
183
187
the keys in the call, may or may not be present depending on the query results.
@@ -235,12 +239,12 @@ def _nonSliceCase(key):
235
239
return retval
236
240
237
241
def convert (self ):
238
- """This is just a convenience method, returns C{ self} .
242
+ """This is just a convenience method, returns `` self`` .
239
243
240
- Although C{ Binding} is not a subclass of :class:`QueryResult<SPARQLWrapper.Wrapper.QueryResult>`, it is returned as a result by
244
+ Although `` Binding`` is not a subclass of :class:`QueryResult<SPARQLWrapper.Wrapper.QueryResult>`, it is returned as a result by
241
245
:class:`SPARQLWrapper2.query`, just like :class:`QueryResult<SPARQLWrapper.Wrapper.QueryResult>` is returned by
242
246
:class:`SPARQLWrapper.SPARQLWrapper.query`. Consequently,
243
- having an empty C{ convert} method to imitate :class:`QueryResult's convert method<SPARQLWrapper.Wrapper.QueryResult.convert>` may avoid unnecessary problems.
247
+ having an empty `` convert`` method to imitate :class:`QueryResult's convert method<SPARQLWrapper.Wrapper.QueryResult.convert>` may avoid unnecessary problems.
244
248
"""
245
249
return self
246
250
@@ -279,7 +283,7 @@ def query(self):
279
283
Exceptions can be raised if either the URI is wrong or the HTTP sends back an error.
280
284
The usual urllib2 exceptions are raised, which cover possible SPARQL errors, too.
281
285
282
- If the query type is I{ not} SELECT, the method falls back to the
286
+ If the query type is * not* SELECT, the method falls back to the
283
287
:class:`corresponding method in the superclass<SPARQLWrapper.query>`.
284
288
285
289
:return: query result
@@ -295,7 +299,7 @@ def query(self):
295
299
def queryAndConvert (self ):
296
300
"""This is here to override the inherited method; it is equivalent to :class:`query`.
297
301
298
- If the query type is I{ not} SELECT, the method falls back to the
302
+ If the query type is * not* SELECT, the method falls back to the
299
303
:class:`corresponding method in the superclass<SPARQLWrapper.queryAndConvert>`.
300
304
301
305
:return: the converted query result.
0 commit comments