Package: pysparql-anything
PySPARQL AnythingThe SPARQL Anything Python LibraryTable of ContentsUser GuideInstallationBasic UsageKeyword ArgumentsAPIMethodsDevelopment and MaintananceBuilding PySPARQL AnythingSPARQL Anything Updates1. USER GUIDE1.1. INSTALLATIONTo install PySPARQL Anything on your machine type the following in your command prompt:$pipinstallpysparql-anythingTo remove PySPARQL Anything from your machine, do the following.In your command prompt execute$python>>>importpysparql_anythingassa>>>sa.utilities.remove_sparql_anything()>>>exit()$pipuninstallpysparql-anything1.2. BASIC USAGEOpen the command prompt with the current working directory set to the main folder of a SPARQL Anything project.Launch Python:$ pythonImport PySPARQL Anything:>>>importpysparql_anythingassaIf the SPARQL Anything jar isn't installed in the API's folder it will now be downloaded there automatically.Initialise apysparql_anything.sparql_anything.SparqlAnythingobject:>>>engine=sa.SparqlAnything()Run the query:>>>engine.run(**kwargs)1.3. KEYWORD ARGUMENTSThe keyword arguments to be passed to any of the PySPARQL Anything methods are the same as those of the regular SPARQL Anything CLI (Seeherefor more info).For example:>>>engine.run(q='queries/getFacade.sparql',f='TTL',o='C:/Users/Marco/Desktop/facade.ttl')All of the keyword arguments except forvmust be assigned a string literal.vrequires to be assigned a Python dictionary, as in the following example.To execute the following query from the SPARQL Anything MusicXML showcase,java-jarsparql-anything-0.8.0-SNAPSHOT.jar-qqueries/populateOntology.sparql-vfilePath="./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml"-vfileName="AltDeu10-017"-fTTLwith PySPARQL Anything, do>>>engine.run(q='queries/populateOntology.sparql',f='ttl',v={'filePath':'./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml','fileName':'AltDeu10-017'})The currently supported arguments are as follows.q: str - The path to the file storing the query to execute or the query itself.

 o: str - OPTIONAL - The path to the output file. [Default: STDOUT]

 l: str - OPTIONAL - The path to one RDF file or a folder including a set of
          files to be loaded. When present, the data is loaded in memory and
          the query executed against it.

 f: str - OPTIONAL -  Format of the output file. Supported values: JSON, XML,
          CSV, TEXT, TTL, NT, NQ. [Default:TEXT or TTL]

 v: dict[str, str] - OPTIONAL - Values passed as input parameter to a query template.
                     When by substituting variable names with the values provided.
                     The argument can be used in two ways:
                     (1) Providing a single SPARQL ResultSet file. In this case,
                     the query is executed for each set of bindings in the input result set.
                     Only 1 file is allowed.
                     (2) Named variable bindings: the argument value must follow the syntax:
                     var_name=var_value. The argument can be passed multiple times and
                     the query repeated for each set of values.2. APIAll of PySPARQL Anything functionalities can be accessed via the following four methods of the classpysparql_anything.sparql_anything.SparqlAnything.The constructor for this class ispysparql_anything.SparqlAnything(*jvm_options:str)->pysparql_anything.sparql_anything.SparqlAnythingwhere*jvm_optionsare the optional string arguments representing the user's preferred JVM options.As an example, one may haveengine=sa.SparqlAnything('-Xrs','-Xmx6g')NOTE: the*jvm_optionsare final. Once they are set they cannot be changed without starting a new process.
This limitation is unfortunately due to the nature of the interaction between the JVM and the Python environment.
Please see#6for more information on this issue.2.1. METHODSSparqlAnything.run(**kwargs)->NoneReflects 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)SparqlAnything.ask(**kwargs)->boolExecutes an ASK query and returns a Python boolean True or False.SparqlAnything.construct(**kwargs)->rdflib.graph.GraphExecutes a CONSTRUCT query and returns a rdflib graph object.SparqlAnything.select(**kwargs)->dictExecutes a SELECT query and returns the result as a Python dictionary.3. DEVELOPMENT AND MAINTAINANCE3.1. Building PySPARQL AnythingTo build the source distribution and binary distribution we proceed as follows.First, the tools we require arebuildas the build frontend,hatchas the build backend andtwineto upload the distribution files to PyPI.All of these can be installed viapip install xif required.Once the tools are ready, the build metadata can be configured in thepyproject.tomlfile.NOTE: it is not needed to amend anything in this file for versioning the software, as this is set dynamically (see below for how to perform this).After the build metadata has been defined, one can proceed to build the distribution archives.To do this, open the command prompt on the directory containing thepyproject.tomlfile and runpy-mbuildThis command should output a lot of text and once completed should generate adistdirectory containing two files:dist/
├── pysparql_anything-0.8.1.2-py3-none-any.whl
└── pysparql_anything-0.8.1.2.tar.gzfor example. Here thetar.gzfile is a source distribution whereas the.whlfile is a binary distribution.To upload the distributions one doestwineuploaddist/*and enter the relevant PyPI credentials for this project.3.2. SPARQL Anything UpdatesEach version of PySPARQL Anything is tied to a released version of SPARQL Anything. Therefore, when a new version of the latter is released a new release of PySPARQL Anything should follow.Assuming that there are no changes in the entry point of SPARQL Anyhing, this process simply involves updating the__about__.pymodule of the source code. To do this, set the__version__and__SparqlAnything__variables to the new values following the given structure.As an example, to update fromv0.8.1tov0.8.2of SPARQL Anything, we would have# PySPARQL Anything version variable__version__='0.8.1.2'# --> '0.8.2.1'  # PySPARQL version for the build process.# SPARQL Anything metadata__SparqlAnything__='v0.8.1'# --> 'v0.8.2'  # Downloads v0.8.2 of SPARQL Anything.__uri__='SPARQL-Anything/sparql.anything'# Software's GitHub URI.After this build the new distribution files and upload them to PyPI.