pyneql.query package

Submodules

pyneql.query.querybuilder module

querybuilder.py is part of the project PyNeQL Author: Valérie Hanoka

class pyneql.query.querybuilder.GenericSPARQLQuery

Bases: object

A generic SPARQL ‘select’ query builder. It is used to build SPARQL queries iteratively.

add_endpoint(endpoint)

Add an Endpoint to the current query. This query will be send to evey listed endpoint. The result will be aggregated. For list of supported endpoints, see enum.Endpoints

Parameters:endpoint – the endpoint to add
add_endpoints(endpoints)

Add a list of Endpoints to the query.

Parameters:endpoints – the list of Endpoints to add
add_filter(arguments_names)

Not Implemented Yet: Add a filter clause to the SPARQL query. TODO

add_prefix(prefix)

Convert a string abbr: <url> into a NameSpace, and add this NameSpace to the query parameters.

Parameters:prefix – a string representing a RDF prefix
add_prefixes(prefixes)

Add a list of prefixes of the form [‘abbr: <url>’] to the query parameters.

Parameters:prefix – a list of strings representing RDF prefixes
add_query_alternative_triples(triples_set)

Add a set of RDFtriples to the query using SPARQL ‘UNION’ in order to express alternatives. { x } UNION { y } will match either x or y, or both. .. seealso:: https://www.w3.org/TR/rdf-sparql-query/ for more details.

Parameters:triples_set – A set of RDFtriple
add_query_triple(triple)

Add an RDF triple to the body of the select query.

Parameters:triple – A RDFtriple
add_query_triples(triples)

Add a list of RDF triples to the body of the select query.

Parameters:triples – A list of RDFtriple
add_result_argument(argument)

Add an argument (SPARQL variable) to the SELECT query. For instance, adding argument “?name” will result in a SPARQL query having “?name” as part of its variables:

SELECT ... ?name ... WHERE {...}

Parameters:argument – A string representing a SPARQL variable
add_result_arguments(arguments)

Add a list of arguments (SPARQL variables) to the SELECT query.

Parameters:arguments – A list of string representing SPARQL variables
commit()

Send the current query to the specified SPARQL endpoints and stores the query results in the results attribute.

reset_queries()

Resets the queries already constructed.

set_limit(limit)

Limits the number of results the query returns.

Parameters:limit – int (the limit of query results)
template_query = u'%(prefix)s SELECT DISTINCT %(result_arguments)s WHERE { %(triples)s } %(limit)s'

pyneql.query.rdftriple module

rdftriplebuilder is part of the project PyNeQL Author: Valérie Hanoka

class pyneql.query.rdftriple.RDFTriple(subject=u'', predicate=u'', object=u'', prefixes=None, excluded_endpoints=None, keep_only_endpoints=None, language=<LanguagesIso6391.English: 'en'>)

Bases: object

A generic RDF triple representation which can be used for querying in a select statement.

add_prefix(prefix)

A prefix can be added if it is of the type vocabulary.NameSpace or if it is a legal SPARQL query prefix declaration. >>> my_triple = RDFTriple(object=”foo”) >>> my_triple.add_prefix(NameSpace.dawgt) >>> my_triple.add_prefix(“barbarbar: <http://bar.org/bar/bar/> .”)

add_prefixes(prefixes)

Add every prefix in the prefixes iterable

class_counter = 1
get_variables()

Given a well-formed SPARQL query, returns its variables. :return: the elements of the RDF triple which are variables.

manage_endpoints_information(excluded_endpoints, keep_only_endpoints)

A triplet can be used to generate many SPARQL queries which will be send to different endpoints. It is thus desirable to tell, for the given triplet, if it is not usable in an endpoint. For instance, wikidata may need specific triplets whereas other endpoints wont.

Example:
  • ?x wdt:P31 wd:Q5 (wikidata specific) may have keep_only_endpoints=[Endpoint.wikidata]
  • ?Person a foaf:Person may have excluded_endpoints=[Endpoint.wikidata]
Parameters:
  • excluded_endpoints – List of endpoints to which the RDF triple is not to be sent
  • keep_only_endpoints – List of the only endpoints to which the RDF triple is to be sent

Module contents