Skip to content

Commit

Permalink
Update readme. Fix where target/sparql-examples-util-0.0.1 was still …
Browse files Browse the repository at this point in the history
…used, now uses target/sparql-examples-utils-*-uber.jar, so this works with any version that have been retrieved. Make sure all CLI calls are working properly (e.g. replace tester subcommand by test). Add a note explaining for these calls we expect the sparql-examples repo to be cloned in the same folder alongside sparql-examples-utils (which is kind of a logical place for it to be)
  • Loading branch information
vemonet authored and JervenBolleman committed Sep 18, 2024
1 parent 102db2d commit 1c3a4f4
Showing 1 changed file with 44 additions and 37 deletions.
81 changes: 44 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,96 +37,103 @@ WHERE
schema:keywords "taxa".
```

If you want to add a label to a query please use the [schema.org keywords](https://schema.org/keywords).

# Running the code

If using a release
```
If using a release:
```bash
mkdir target
wget "https://github.com/sib-swiss/sparql-examples-utils/releases/download/v1.0.0/sparql-examples-util-1.0.0-uber.jar"
mv sparql-examples-util-1.0.0-uber.jar target
wget "https://github.com/sib-swiss/sparql-examples-utils/releases/download/v2.0.0/sparql-examples-utils-2.0.0-uber.jar"
mv sparql-examples-utils-2.0.0-uber.jar target

# This target directory is only so that the commands in the examples match as if the code was build locally.
# basically target/ can be remove from all examples below
```
if building locally in this git repository
```
If building locally in this git repository:
```bash
mvn package
```


# Quality Assurance (QA).

To test your examples pass the folder/directory containing your exampes as an argument ('--input-directory' to the Tester command.
e.g
To test your examples pass the folder/directory containing your examples as an argument (`--input-directory` to the `test` subcommand, e.g.:

```bash
java -jar target/sparql-examples-utils-*-uber.jar test --input-directory=../sparql-examples/examples
```
java -jar target/sparql-examples-util-1.0.0-uber.jar tester --input-directory=$HOME/git/sparql-examples/examples

The queries can be executed automatically on all endpoints they apply to using an extra argument for the test `--also-run-slow-tests`. This does change the queries to add a `LIMIT 1` if no limit was set in the query.

```bash
java -jar target/sparql-examples-utils-*-uber.jar test --input-directory=../sparql-examples/examples -p MetaNetX --also-run-slow-tests
```

> [!NOTE]
>
> All CLI commands provided in this readme expects you have the [`sparql-examples`](https://github.com/sib-swiss/sparql-examples) folder cloned in the same directory alongside this `sparql-examples-utils` project folder. Feel free to change them for your own example folder and path.
# Conversion for upload in SPARQL endpoint

To load the examples into a SPARQL endpoint they should be concatenated into one example file. Use the script `convertIntoOneTurtle.sh` provide the project name with a `-p` parameter
Before loading the examples into a SPARQL endpoint they should be concatenated into one file, including the prefixes/namespaces definitions.

Compile all query files for a specific example subfolder, into a local turtle file:

```bash
java -jar target/sparql-examples-util-1.0.0-uber.jar convert -i examples/ -p all -f jsonld
# Or for a specific example folder, as turtle, to a file:
java -jar target/sparql-examples-util-1.0.0-uber.jar convert -i examples/ -p Bgee -f ttl > examples_Bgee.ttl
java -jar target/sparql-examples-utils-*-uber.jar convert -i ../sparql-examples/examples -p Bgee -f ttl > examples_Bgee.ttl
```

Or compile all subfolders as JSON-LD to the standard output:

```bash
java -jar target/sparql-examples-utils-*-uber.jar convert -i ../sparql-examples/examples -p all -f jsonld
```

## Conversion to RQ files

For easier use by other tools we can also generate [rq](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#mediaType) files. Following the syntax of [grlc](https://grlc.io/) allowing to use these queries as APIs.
For easier use by other tools we can also generate [`.rq`](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#mediaType) files. Following the syntax of [grlc.io](https://grlc.io/) allowing to use these queries as HTTP APIs.
```bash
java -jar target/sparql-examples-util-1.0.0-uber.jar convert -i examples/ -p all -r
java -jar target/sparql-examples-utils-*-uber.jar convert -i ../sparql-examples/examples -p all -r
```

## Generate markdown file

Generate markdown files with the query and a mermaid diagram of the queries, to be used to deploy a static website for the query examples.

```bash
java -jar target/sparql-examples-util-*-uber.jar convert -i examples/ -m
java -jar target/sparql-examples-utils-*-uber.jar convert -i ../sparql-examples/examples -m
```

# Querying for queries

As the SPARQL examples are themselves RDF, they can be queried for as soon as they are loaded in a SPARQL endpoint.
```sparql
PREFIX sh: <http://www.w3.org/ns/shacl#>
SELECT *
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?sq ?comment ?query
WHERE {
?ex sh:select|sh:ask|sh:construct|sh:describe ?query .
}
?sq a sh:SPARQLExecutable ;
rdfs:comment ?comment ;
sh:select|sh:ask|sh:construct|sh:describe ?query .
} ORDER BY ?sq
```

# Labeling queries

If you want to add a label to a query please use [schema.org keyword](https://schema.org/keywords)

# Testing the queries actually work

The queries can be executed automatically on all endpoints they apply to using ane extra argument for the Tester `--also-run-slow-tests`.

```
java -cp target/sparql-examples-util-1.0.0-uber.jar test --input-directory=$HOME/git/sparql-examples/examples
```

This does change the queries to add a LIMIT 1 if no limit was set in the query. Then if there is a result it is fetched.

## Finding queries that run on more than one endpoint

```bash
java -jar target/sparql-examples-util-1.0.0-uber.jar convert --input-directory $HOME/git/sparql-examples/examples -f examples_all.ttl
java -jar target/sparql-examples-utils-*-uber.jar convert --input-directory ../sparql-examples/examples > examples_all.ttl

sparql --data examples_all.ttl "SELECT ?query (GROUP_CONCAT(?target ; separator=', ') AS ?targets) WHERE { ?query <https://schema.org/target> ?target } GROUP BY ?query HAVING (COUNT(DISTINCT ?target) > 1) "
```

# Native executable

The project is ready to be compiled by the native-image tool of the [GraalVM](https://www.graalvm.org/) project.
The project is ready to be compiled by the native-image tool of the [GraalVM](https://www.graalvm.org/) project.

To do so set your `JAVA_HOME` to the graalvm location and user maven package -Pnative

e.g. on linux with graalvm installed in your `$HOME/bin` directory
e.g. on linux with graalvm installed in your `$HOME/bin` directory:
```bash
export JAVA_HOME=$HOME/bin/graalvm-jdk-${GRAALVM_VERSION}
mvn package -Pnative
Expand Down

0 comments on commit 1c3a4f4

Please sign in to comment.