Package SPARQLWrapper :: Module SmartWrapper :: Class Bindings
[hide private]
[frames] | no frames]

Class Bindings

source code

object --+
         |
        Bindings

Class encapsulating one query result, based on the JSON return format. It decodes the return values to make it a bit more usable for a standard usage. The class consumes the return value and instantiates a number of attributes that can be consulted directly. See the list of variables.

The Serializing SPARQL Query Results in JSON explains the details of the JSON return structures. Very succintly: the return data has "bindings", which means a list of dictionaries. Each dictionary is a possible binding of the SELECT variables to Value instances. This structure is made a bit more usable by this class.

Instance Methods [hide private]
 
__init__(self, retval)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
getValues(self, key)
A shorthand for the retrieval of all bindings for a single key.
source code
Boolean
__contains__(self, key)
Emulation of the "key in obj" operator.
source code
array of variable -> Value dictionaries
__getitem__(self, key)
Emulation of the obj[key] operator.
source code
 
convert(self)
This is just a convenience method, returns self.
source code

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

Instance Variables [hide private]
Boolean askResult
by default, set to False; in case of an ASK query, the result of the query
  bindings
The final bindings: array of dictionaries, mapping variables to Value instances.
  fullResult
The original dictionary of the results, stored for an easier reference
  head
Header part of the return, see the JSON return format document for details
  variables
List of unbounds (variables) of the original query.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, retval)
(Constructor)

source code 

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

Parameters:
Overrides: object.__init__

getValues(self, key)

source code 

A shorthand for the retrieval of all bindings for a single key. It is equivalent to "[b[key] for b in self[key]]"

Parameters:
  • key - possible variable
Returns:
list of Value instances

__contains__(self, key)
(In operator)

source code 

Emulation of the "key in obj" operator. Key can be a string for a variable or an array/tuple of strings.

If key is a variable, the return value is True if there is at least one binding where key is bound. If key is an array or tuple, the return value is True if there is at least one binding where all variables in key are bound.

Parameters:
  • key - possible variable, or array/tuple of variables
Returns: Boolean
whether there is a binding of the variable in the return

__getitem__(self, key)
(Indexing operator)

source code 

Emulation of the obj[key] operator. Slice notation is also available. The goal is to choose the right bindings among the available ones. The return values are always arrays of bindings, ie, arrays of dictionaries mapping variable keys to Value instances. The different value settings mean the followings:

  • obj[key] returns the bindings where key has a valid value
  • obj[key1,key2,...] returns the bindings where all key1,key2,... have valid values
  • obj[(key1,key2,...):(nkey1,nkey2,...)] returns the bindings where all key1,key2,... have valid values and none of the nkey1,nkey2,... have valid values
  • obj[:(nkey1,nkey2,...)] returns the bindings where none of the nkey1,nkey2,... have valid values

In all cases complete bindings are returned, ie, the values for other variables, not present among the keys in the call, may or may not be present depending on the query results.

Parameters:
  • key - possible variable or array/tuple of keys with possible slice notation
Returns: array of variable -> Value dictionaries
list of bindings

convert(self)

source code 

This is just a convenience method, returns self.

Although Binding is not a subclass of QueryResult, it is returned as a result by SPARQLWrapper2.query, just like QueryResult is returned by SPARQLWrapper.SPARQLWrapper.query. Consequently, having an empty convert method to imitate QueryResult's convert method may avoid unnecessary problems.


Instance Variable Details [hide private]

bindings

The final bindings: array of dictionaries, mapping variables to Value instances. (If unbound, then no value is set in the dictionary; that can be easily checked with var in res.bindings[..], for example.)

variables

List of unbounds (variables) of the original query. It is an array of strings. None in the case of an ASK query