Skip to content

Instantly share code, notes, and snippets.

@gwpl
Last active December 30, 2023 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwpl/5701dabc3f6309c192643b6606d5edf8 to your computer and use it in GitHub Desktop.
Save gwpl/5701dabc3f6309c192643b6606d5edf8 to your computer and use it in GitHub Desktop.
RDF SPARQL oxigraph Rust Notes ( Link to this post: https://stackoverflow.com/a/77737438/544721 )

oxigraph ( https://github.com/oxigraph/oxigraph ) ! (also you may find related project interesting https://crates.io/crates/reasonable )

And btw. it looks like rdflib-endpoint (mentioned earlier) can via rdflib-endpoint --store Oxigraph ... be configured to use oxigraph!

cargo install oxigraph_server
mkdir -p oxigraph_data
oxigraph_server --location oxigraph_data load -f example.ttl 
oxigraph_server --location oxigraph_data serve

And you can check it in browser (probably on http://localhost:7878/ ) or form command line:

curl -G 'http://localhost:7878/query' --data-urlencode "query=PREFIX rdf:
 <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 SELECT ?sub ?pred ?obj WHERE {
   ?sub ?pred ?obj .
 } LIMIT 10" -H "Accept: application/sparql-results+json"|jq

copy from https://crates.io/crates/oxigraph_server#usage

Usage

Run oxigraph_server --location my_data_storage_directory serve to start the server where my_data_storage_directory is the directory where you want Oxigraph data to be stored. It listens by default on localhost:7878.

The server provides an HTML UI, based on YASGUI, with a form to execute SPARQL requests.


OR

Via Docker:

Copy from https://crates.io/crates/oxigraph_server#using-a-docker-image :


Using a Docker image

Display the help menu

docker run --rm ghcr.io/oxigraph/oxigraph --help

Run the Webserver

Expose the server on port 7878 of the host machine, and save data on the local ./data folder

docker run --rm -v $PWD/data:/data -p 7878:7878 ghcr.io/oxigraph/oxigraph --location /data serve --bind 0.0.0.0:7878
https://stackoverflow.com/a/77737438/544721


You can then access it from your machine on port 7878:

# Open the GUI in a browser
firefox http://localhost:7878

# Post some data
curl http://localhost:7878/store?default -H 'Content-Type: text/turtle' -T ./data.ttl

# Make a query
curl -X POST -H 'Accept: application/sparql-results+json' -H 'Content-Type: application/sparql-query' --data 'SELECT * WHERE { ?s ?p ?o } LIMIT 10' http://localhost:7878/query

# Make an UPDATE
curl -X POST -H 'Content-Type: application/sparql-update' --data 'DELETE WHERE { <http://example.com/s> ?p ?o }' http://localhost:7878/update
@gwpl
Copy link
Author

gwpl commented Dec 30, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment