Skip to content

Commit ed4449b

Browse files
authored
Update README.md
1 parent a3cce30 commit ed4449b

1 file changed

Lines changed: 71 additions & 27 deletions

File tree

README.md

Lines changed: 71 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# PySPARQL Anything
22
###### The SPARQL Anything Python Library
33

4-
## User Guide
4+
## USER GUIDE
55

66
###### INSTALLATION
77

88
To install PySPARQL Anything on your machine type the following in your command prompt:
9-
```
10-
pip install pysparql-anything
9+
```powershell
10+
$ pip install pysparql-anything
1111
```
1212

1313
To remove PySPARQL Anything from your machine, do the following.
1414

1515
In your command prompt execute
16-
```
16+
```python
1717
$ python
18-
>>> import pysparql_anything as cli
19-
>>> cli.config.remove_jar()
18+
>>> import pysparql_anything as sa
19+
>>> sa.utilities.remove_sparql_anything()
2020
>>> exit()
2121
$ pip uninstall pysparql-anything
2222
```
2323

24-
###### USAGE
24+
###### BASIC USAGE
2525

2626
1) Open the command prompt with the current working directory set to the main folder of a SPARQL Anything project.
2727

@@ -31,44 +31,42 @@ $ python
3131
```
3232

3333
3) Import PySPARQL Anything:
34-
```
35-
>>> import pysparql_anything as cli
34+
```python
35+
>>> import pysparql_anything as sa
3636
```
3737

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

4040
4) Initialise a ```pysparql_anything.sparql_anything.SparqlAnything``` object:
41-
```
42-
>>> engine = cli.SparqlAnything()
41+
```python
42+
>>> engine = sa.SparqlAnything()
4343
```
4444

4545
5) Run the query:
46-
```
46+
```python
4747
>>> engine.run(**kwargs)
4848
```
4949

50-
###### QUERY PARAMETERS
51-
52-
The keyword arguments to be set are the same as those of the regular Sparql Anything CLI, minus ```i```.
50+
###### KEYWORD ARGUMENTS
5351

54-
As the use of the latter flag has been deprecated, it has not been implemented.
52+
The keyword arguments to be passed to any of the PySPARQL Anything methods are the same as those of the regular SPARQL Anything CLI [1]
5553

5654
For example:
57-
```
55+
```python
5856
>>> engine.run(q='queries/getFacade.sparql', f='TTL', o='C:/Users/Marco/Desktop/facade.ttl')
5957
```
6058

61-
All of the keyword arguments except for ```v``` want to be assigned a string literal.
59+
All of the keyword arguments except for ```v``` must be assigned a string literal.
6260

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

6563
To execute the following query from the SPARQL Anything MusicXML showcase,
66-
```
64+
```powershell
6765
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
6866
```
6967

7068
with PySPARQL Anything, do
71-
```
69+
```python
7270
>>> engine.run(
7371
q='queries/populateOntology.sparql',
7472
f='ttl',
@@ -79,28 +77,74 @@ with PySPARQL Anything, do
7977
)
8078
```
8179

82-
For further information see
80+
The currently supported arguments are as follows.
81+
82+
```
83+
q: str - The path to the file storing the query to execute or the query itself.
84+
85+
o: str - OPTIONAL - The path to the output file. [Default: STDOUT]
86+
87+
l: str - OPTIONAL - The path to one RDF file or a folder including a set of
88+
files to be loaded. When present, the data is loaded in memory and
89+
the query executed against it.
8390
84-
https://github.com/SPARQL-Anything/sparql.anything#command-line-interface-cli .
91+
f: str - OPTIONAL - Format of the output file. Supported values: JSON, XML,
92+
CSV, TEXT, TTL, NT, NQ. [Default:TEXT or TTL]
93+
94+
v: dict[str, str] - OPTIONAL - Values passed as input parameter to a query template.
95+
When by substituting variable names with the values provided.
96+
The argument can be used in two ways:
97+
(1) Providing a single SPARQL ResultSet file. In this case,
98+
the query is executed for each set of bindings in the input result set.
99+
Only 1 file is allowed.
100+
(2) Named variable bindings: the argument value must follow the syntax:
101+
var_name=var_value. The argument can be passed multiple times and
102+
the query repeated for each set of values.
103+
```
104+
105+
[1] See https://github.com/SPARQL-Anything/sparql.anything#command-line-interface-cli for more information.
85106

86107
## API
87108

88109
All of PySPARQL Anything functionalities can be accessed via the following four methods of the class
89-
```pysparql_anything.sparql_anything.SparqlAnything```.
110+
``` pysparql_anything.sparql_anything.SparqlAnything ```.
90111

91-
``` run(**kwargs) -> None ```
112+
The constructor for this class is
113+
``` python
114+
pysparql_anything.SparqlAnything(*jvm_options: str) -> pysparql_anything.sparql_anything.SparqlAnything
115+
```
116+
where ```*jvm_options``` are the optional string arguments representing the user's preferred JVM options.
117+
118+
As an example, one may have
119+
```python
120+
engine = sa.SparqlAnything('-Xrs', '-Xmx6g')
121+
```
122+
NOTE: the ```*jvm_options``` are final. Once they are set they cannot be changed without starting a new process.
123+
This limitation is unfortunately due to the nature of the interaction between the JVM and the Python environment.
124+
Please see [#6](https://github.com/SPARQL-Anything/PySPARQL-Anything/issues/6) for more information on this issue.
125+
126+
###### METHODS
127+
``` python
128+
SparqlAnything.run(**kwargs) -> None
129+
```
92130

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

96-
``` ask(**kwargs) -> bool ```
134+
```python
135+
SparqlAnything.ask(**kwargs) -> bool
136+
```
97137

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

100-
``` construct(**kwargs) -> rdflib.graph.Graph ```
140+
```python
141+
SparqlAnything.construct(**kwargs) -> rdflib.graph.Graph
142+
```
101143

102144
Executes a CONSTRUCT query and returns a rdflib graph object.
103145

104-
``` select(**kwargs) -> dict ```
146+
```python
147+
SparqlAnything.select(**kwargs) -> dict
148+
```
105149

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

0 commit comments

Comments
 (0)