pyrdf2vec.connectors module

class pyrdf2vec.connectors.Connector(endpoint, *, cache=NOTHING)

Bases: abc.ABC

Base class of the connectors.

_asession

The aiohttp session to use for asynchrone requests. Defaults to None.

_headers

The HTTP headers to use. Defaults to {“Accept”: “application/sparql-results+json”}.

cache

The policy and size cache to use. Defaults to TTLCache(maxsize=1024, ttl=1200).

endpoint

The endpoint to execute the queries.

async close()

Closes the aiohttp session.

Return type

None

abstract fetch(query)

Fetchs the result of a query.

Parameters

query (str) – The query to fetch the result

Returns

The JSON response.

Raises

NotImplementedError – If this method is called, without having provided an implementation.

class pyrdf2vec.connectors.SPARQLConnector(endpoint, *, cache=NOTHING)

Bases: pyrdf2vec.connectors.Connector

Represents a SPARQL connector.

_asession

The aiohttp session to use for asynchrone requests. Defaults to None.

_headers

The HTTP headers to use. Defaults to {“Accept”: “application/sparql-results+json”}.

cache

The policy and size cache to use. Defaults to connectors.TTLCache(maxsize=1024, ttl=1200).

endpoint

The endpoint to execute the queries.

async afetch(queries)

Fetchs the result of SPARQL queries asynchronously.

Parameters

queries (List[str]) – The queries.

Return type

List[List[List[Dict[str, Dict[str, str]]]]]

Returns

The response of the queries.

fetch(query)

Fetchs the result of a SPARQL query.

Parameters

query (str) – The query to fetch the result.

Return type

List[Dict[str, Dict[str, str]]]

Returns

The response of the query in a JSON format.

get_query(entity, preds=None)

Gets the SPARQL query for an entity.

Parameters
  • entity (str) – The entity to get the SPARQL query.

  • preds (Optional[List[str]]) – The predicate chain to fetch a literal Defaults to None.

Return type

str

Returns

The SPARQL query for the given entity.

res2literals(res)

Converts a JSON response server to literal(s).

Parameters

res – The JSON response.

Return type

Union[float, str, Tuple[Union[float, str], ...]]

Returns

The literal(s).