Skip to main content

A Python based CLI for SPARQL Anything

Project description

PySPARQL Anything

A Python CLI and API for SPARQL Anything

User Guide

INSTALLATION

To install PySPARQL Anything on your machine type the following in your command prompt:

pip install pysparql-anything 

To remove PySPARQL Anything from your machine, do the following:

In your command prompt execute

$ python
>>> import pysparql_anything as cli
>>> cli.config.remove_jar()
>>> exit()
$ pip uninstall pysparql-anything
USAGE
  1. Open the command prompt with the current working directory set to the main folder of a SPARQL Anything project.

  2. Launch Python:

$ python 
  1. Import PySPARQL Anything:
>>> import pysparql_anything as cli

If the SPARQL Anything jar isn't installed in the API's folder it will now be downloaded there automatically.

  1. Initialise a pysparql_anything.sparql_anything.SparqlAnything object:
>>> engine = cli.SparqlAnything()
  1. Run the query:
>>> engine.run(**kwargs)

The keyword arguments to be set are the same as those of the regular Sparql Anything CLI, minus the hyphen.

For example:

>>> engine.run(q='queries/getFacade.sparql', f='TTL', o='C:/Users/Marco/Desktop/facade.ttl')

All of the keyword arguments except for v want to be assigned a string literal.

v requires to be assigned a Python dictionary, as in the following example.

To execute the following query from the SPARQL Anything MusicXML showcase,

java -jar sparql-anything-0.8.0-SNAPSHOT.jar -q queries/populateOntology.sparql -v filePath="./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml" -v fileName="AltDeu10-017" -f TTL

with PySPARQL Anything, do

>>> engine.run(
    	q='queries/populateOntology.sparql',
    	f='ttl',
    	v={
            'filePath' : './musicXMLFiles/AltDeu10/AltDeu10-017.musicxml',
            'fileName' : 'AltDeu10-017'
    	}
    )

API

All of PySPARQL Anything functionalities can be accessed via the following four methods of the class pysparql_anything.sparql_anything.SparqlAnything.

All keyword arguments to be set are the same as those of the regular Sparql Anything CLI, minus the hyphen.

See https://github.com/SPARQL-Anything/sparql.anything#command-line-interface-cli and above for some particular examples.

run(**kwargs) -> None

Reflects the functionalities of the original SPARQL Anything CLI. This can be used to run a query the output of which is to be printed on the command line or saved to a file. (See example above)

ask(**kwargs) -> bool

Executes an ASK query and returns a Python boolean True or False.

construct(**kwargs) -> rdflib.Graph

Executes a CONSTRUCT query and returns a rdflib graph object.

select(**kwargs) -> dict

Executes a SELECT query and returns the result as a Python dictionary.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysparql_anything-0.8.1.1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysparql_anything-0.8.1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file pysparql_anything-0.8.1.1.tar.gz.

File metadata

  • Download URL: pysparql_anything-0.8.1.1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for pysparql_anything-0.8.1.1.tar.gz
Algorithm Hash digest
SHA256 ebb3f2844c911a8d5a575af08c274471c362c9bcea7d8562a95e914d64ee5c70
MD5 06837ecfc99b3fd023fd7ee2e480e5df
BLAKE2b-256 0f0f97fef3ea762c8597abc0a7998848f33764a3704b910daa7b870562b7fa18

See more details on using hashes here.

File details

Details for the file pysparql_anything-0.8.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pysparql_anything-0.8.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e77dc44902837c197b2468f0dcd61c552390810c8da112b75d19d0020bf1789
MD5 15bd21f3fcf74f5fae79b3239084ef29
BLAKE2b-256 878ed6d22c0cf7b34100ccf40c5acb31cb0099cdb67de9dad83d9b0a6fa91d29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page