Package SPARQLWrapper :: Module Wrapper :: Class QueryResult
[hide private]
[frames] | no frames]

Class QueryResult

source code

object --+
         |
        QueryResult

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.

Instance Methods [hide private]
 
__init__(self, result)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
string
geturl(self)
Return the URI of the original call.
source code
dictionary
info(self)
Return the meta-information of the HTTP result.
source code
 
__iter__(self)
Return an iterator object.
source code
 
next(self)
Method for the standard iterator.
source code
Python dictionary
_convertJSON(self)
Convert a JSON result into a Python dict.
source code
PyXlib DOM node
_convertXML(self)
Convert an XML result into a Python dom tree.
source code
RDFLib Graph
_convertRDF(self)
Convert a RDF/XML result into an RDFLib triple store.
source code
string
_convertN3(self)
Convert a RDF Turtle/N3 result into a string.
source code
RDFLib Graph
_convertJSONLD(self)
Convert a RDF JSON-LDresult into an RDFLib triple store.
source code
 
convert(self)
Encode the return value depending on the return format:
source code
 
print_results(self, minWidth=None) source code
 
__get_results_width(self, results, minWidth=2) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
setJSONModule(module)
Set the Python module for encoding JSON data.
source code
Instance Variables [hide private]
  response
the direct HTTP response; a file-like object, as return by the urllib2.urlopen library call.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, result)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • result - HTTP response stemming from a SPARQLWrapper.query call, or a tuple with the expected format: (response,format)
Overrides: object.__init__

geturl(self)

source code 

Return the URI of the original call.

Returns: string
URI

info(self)

source code 

Return the meta-information of the HTTP result.

Returns: dictionary
meta information

__iter__(self)

source code 

Return an iterator object. This method is expected for the inclusion of the object in a standard for loop.

setJSONModule(module)
Static Method

source code 
Set the Python module for encoding JSON data. If not an allowed value, the setting is ignored.
   JSON modules supported:
     - ``simplejson``: http://code.google.com/p/simplejson/
     - ``cjson``: http://pypi.python.org/pypi/python-cjson
     - ``json``: This is the version of ``simplejson`` that is bundled with the
       Python standard library since version 2.6
       (see http://docs.python.org/library/json.html)
@param module: Possible values: are L{simplejson}, L{cjson}, L{json}. All other cases raise a ValueError exception.
@type module: string

_convertJSON(self)

source code 

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

_convertXML(self)

source code 

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

_convertRDF(self)

source code 

Convert a 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

_convertN3(self)

source code 

Convert a RDF Turtle/N3 result into a string. This method can be overwritten in a subclass for a different conversion method.

Returns: string
converted result

_convertJSONLD(self)

source code 

Convert a RDF JSON-LDresult into an RDFLib triple store. This method can be overwritten in a subclass for a different conversion method.

Returns: RDFLib Graph
converted result

convert(self)

source code 

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.