The surf.plugin.query_reader Module

class surf.plugin.query_reader.RDFQueryReader(*args, **kwargs)[source]

Bases: surf.plugin.reader.RDFReader

Super class for SuRF Reader plugins that wrap queryable stores.

close()

Close the plugin and free any resources it may hold

concept(resource)

Return the concept URI of the following resource.

resource can be a string or a URIRef. :param resource: the given resource :type resource: surf.resource.Resource

convert(query_result, *keys)[source]

Convert the results from the query to a multilevel dictionary.

This method is used by the surf.resource.Resource class.

execute(query)[source]

Execute a query of type surf.query.Query.

get(resource, attribute, direct)

Return the value(s) of the corresponding attribute.

Parameters:
  • resource (surf.resource.Resource) – the given resource
  • attribute (str) – the given attribute
  • direct (bool) – whether the attribute is a direct or inverse edge / property. If False then the subject of the resource is considered the object of the query.
Returns:

the value(s) of the corresponding attribute

Return type:

list

inference

Toggle logical inference on / off. The property has any effect only if such functionality is supported by the underlying surf.store.Store store

instances_by_attribute(resource, attributes, direct, context)

Return all URIs that are instances of resource and have the specified attributes.

If direct is False, than the subject of the resource is considered the object of the query.

is_present(resource)

Check whether the resource is present in the underlying surf.store.Store store

Parameters:resource (surf.resource.Resource) – the given resource
load(resource, direct)

Fully load the resource from the underlying surf.store.Store store. This method returns all statements about the resource.

If direct is False, then the subject of the resource is considered the object of the query

Parameters:
  • resource (surf.resource.Resource) – the given resource
  • direct (bool) – whether the attribute is a direct or inverse edge / property. If False then the subject of the resource is considered the object of the query.
Returns:

all statements about resource

Return type:

dict

surf.plugin.query_reader.query_ask(s, context)[source]

Construct surf.query.Query of type ASK.

Parameters:
  • s – the subject
  • context – the context
Returns:

the query

Return type:

surf.query.Query

surf.plugin.query_reader.query_concept(s)[source]

Construct surf.query.Query with ?c as the unknown.

Parameters:s – the subject
Returns:the query
Return type:surf.query.Query
surf.plugin.query_reader.query_p_s(c, p, direct, context)[source]

Construct surf.query.Query with ?s and ?c as unknowns.

Parameters:
  • c – the class
  • p – the predicate
  • direct (bool) – whether the predicate is direct or inverse
  • context – the context
Returns:

the query

Return type:

surf.query.Query

surf.plugin.query_reader.query_s(s, direct, context)[source]

Construct surf.query.Query with ?p, ?v and ?c as unknowns.

Parameters:
  • s – the subject
  • direct (bool) – whether the predicate is direct or inverse
  • context – the context
Returns:

the query

Return type:

surf.query.Query

surf.plugin.query_reader.query_sp(s, p, direct, context)[source]

Construct surf.query.Query with ?v and ?c as unknowns.

Parameters:
  • s – the subject
  • p – the predicate
  • direct (bool) – whether the predicate is direct or inverse
  • context – the context
Returns:

the query

Return type:

surf.query.Query