Class QueryResult
source code
Wrapper around an a query result. Users should not create instances of
this class, it is generated by a SPARQLWrapper.query call. The results can be converted
to various formats, or used directly.
If used directly: the class gives access to the direct http request
results self.response: it is a file-like object with two
additional methods: geturl() to return the URL of the
resource retrieved and info() that returns the
meta-information of the HTTP result as a dictionary-like object (see the
urllib2 standard library module of Python).
For convenience, these methods are also available on the instance. The
__iter__ and next methods are also implemented
(by mapping them to self.response). This means that the common idiom:
for l in obj : do_something_with_line(l)
would work, too.
|
|
|
|
string
|
|
|
dictionary
|
|
|
|
|
|
|
next(self)
Method for the standard iterator. |
source code
|
|
|
Python dictionary
|
|
|
PyXlib DOM node
|
|
|
RDFLib Graph
|
|
|
string
|
|
|
|
|
|
|
response
the direct HTTP response; a file-like object, as return by the
urllib2.urlopen library call.
|
|
Return the URI of the original call.
- Returns: string
- URI
|
|
Return the meta-information of the HTTP result.
- Returns: dictionary
- meta information
|
|
Return an iterator object. This method is expected for the inclusion
of the object in a standard for loop.
|
|
Convert a JSON result into a Python dict. This method can be
overwritten in a subclass for a different conversion method.
- Returns: Python dictionary
- converted result
|
|
Convert an XML result into a Python dom tree. This method can be
overwritten in a subclass for a different conversion method.
- Returns: PyXlib DOM node
- converted result
|
|
Convert an RDF/XML result into an RDFLib triple store. This method can
be overwritten in a subclass for a different conversion method.
- Returns: RDFLib Graph
- converted result
|
|
Convert an RDF Turtle/N3 result into a string. This method can be
overwritten in a subclass for a different conversion method.
- Returns: string
- converted result
|
|
Encode the return value depending on the return format:
-
in the case of XML, a DOM top element is returned;
-
in the case of JSON, a simplejson conversion will return a
dictionary;
-
in the case of RDF/XML, the value is converted via RDFLib into a
Graph instance.
In all other cases the input simply returned.
- Returns:
- the converted query result. See the conversion methods for more
details.
|