Sign inSign up

aammar/data2services-sparql-operations

By aammar

•Updated almost 7 years ago

Image
0

328

aammar/data2services-sparql-operations repository overview

⁠Get started

A project to execute SPARQL⁠ queries from string, URL or multiple files using RDF4J⁠.

  • The user can execute SPARQL queries by
    • Passing a SPARQL query string in -sp param
    • Providing a URL in -f param
    • Providing the URL of a GitHub repository containing .rq files to execute in -f param
    • Providing the path to a directory where the queries are stored in .rq text files and executed in the alphabetical order of their filename.
    • A YAML file with multiple ordered queries.
  • Update, construct and select operations supported.
  • It is possible to optionally define username and password for the SPARQL endpoint.
  • data2services-transform-repository⁠: example queries to transform biomedical data to the BioLink⁠ model for the NCATS Translator program⁠.

⁠Pull

BETA: available on DockerHub⁠ the latest image is automatically built from latest branch master commit on GitHub⁠.

docker pull vemonet/data2services-sparql-operations

⁠Build

You can also clone the GitHub repository⁠ and build the docker image locally (unecessary if you do docker pull)

git clone https://github.com/MaastrichtU-IDS/data2services-sparql-operations
docker build -t vemonet/data2services-sparql-operations .

⁠Run

N.B.: you will need to remove the \ and make the docker run commands one-line for Windows PowerShell.

⁠Usage
docker run -it --rm vemonet/data2services-sparql-operations -h

⁠Select

On DBpedia⁠ using a SPARQL query string as argument.

docker run -it --rm vemonet/data2services-sparql-operations -op select \
  -sp "select distinct ?Concept where {[] a ?Concept} LIMIT 10" \
  -ep "http://dbpedia.org/sparql"

⁠Update

Multiple INSERT on graphdb.dumontierlab.com⁠, using files in a repository from the local file system.

docker run -it --rm vemonet/data2services-sparql-operations \
  -ep "http://graphdb.dumontierlab.com" -rep "test" \
  #-ep "http://graphdb.dumontierlab.com/repositories/test/statements" \
  -op update -un $USERNAME -pw $PASSWORD \
  -f "https://raw.githubusercontent.com/MaastrichtU-IDS/data2services-sparql-operations/master/src/main/resources/example-insert.rq"
  • Note that GraphDB and RDF4J Server require to add /statements at the end of the endpoint URL when doing an update.

⁠Construct

On graphdb.dumontierlab.com⁠ using GitHub URL to get the SPARQL query from a file.

docker run -it --rm vemonet/data2services-sparql-operations -op construct \
  -ep "http://graphdb.dumontierlab.com/repositories/ncats-red-kg" \
  -f "https://raw.githubusercontent.com/MaastrichtU-IDS/data2services-sparql-operations/master/src/main/resources/example-construct-pathways.rq" 

⁠GitHub repository

We crawl the example GitHub repository⁠ and execute each .rq file.

docker run -it --rm vemonet/data2services-sparql-operations \
  -op select -ep "http://dbpedia.org/sparql" \
  -f "https://github.com/MaastrichtU-IDS/data2services-sparql-operations/tree/master/src/main/resources/select-examples" 

⁠YAML

A YAML file can be used to provide multiple ordered queries. See example from GitHub⁠.

docker run -it --rm vemonet/data2services-sparql-operations \
  -op select -ep "http://dbpedia.org/sparql" \
  -f "https://raw.githubusercontent.com/MaastrichtU-IDS/data2services-sparql-operations/master/src/main/resources/example-queries.yaml"

⁠Split

Beta To split an object into multiple statements using a delimiter, and insert the statements generated by the split in the same graph.

E.g.: a statement with value "1234,345,768" would be splitted in 3 statements "1234", "345" and "768".

docker run -it \
  vemonet/data2services-sparql-operations -op split \
  --split-property "http://w3id.org/biolink/vocab/has_participant" \
  --split-class "http://w3id.org/biolink/vocab/GeneGrouping" \
  --split-delimiter "," \
  --split-delete \ # Delete the splitted statement
  --uri-expansion "https://w3id.org/data2services/" \ # Use 'infer' to do it automatically using prefixcommons
  #--trim-delimiter '"' \
  -ep "http://graphdb.dumontierlab.com" \ # RDF4J server URL
  -rep "test" \ # RDF4J server repository ID
  -un USERNAME -pw PASSWORD
  
# For SPARQLRepository
#  -ep "http://graphdb.dumontierlab.com/repositories/test" \
#  -uep "http://graphdb.dumontierlab.com/repositories/test/statements" \

⁠Set variables

3 variables can be set in the SPARQL queries using a ?_: ?_inputGraph, ?_outputGraph and ?_serviceUrl. See example:

INSERT {
  GRAPH <?_outputGraph> {
    ?Concept a <https://w3id.org/data2services/Concept> .
  }
} WHERE {
  SERVICE <?_serviceUrl> {
    GRAPH <?_inputGraph> {
      SELECT * {
        [] a ?Concept .
      } LIMIT 10 
} } }

Execute:

docker run -it --rm vemonet/data2services-sparql-operations \
  -op update -ep "http://graphdb.dumontierlab.com/repositories/test/statements" \
  -un $USERNAME -pw $PASSWORD \
  -f "https://raw.githubusercontent.com/MaastrichtU-IDS/data2services-sparql-operations/master/src/main/resources/example-insert-variables.rq" \
  --var-inputGraph http://www.ontotext.com/explicit \
  --var-outputGraph https://w3id.org/data2services/output \
  --var-serviceUrl http://localhost:7200/repositories/test

⁠Examples

From data2services-transform-repository⁠, use a federated query⁠ to transform generic RDF generated by AutoR2RML⁠ and xml2rdf⁠ to the BioLink⁠ model, and load it to a different repository.

# DrugBank
docker run -it --rm -v "$PWD/sparql/insert-biolink/drugbank":/data \
  vemonet/data2services-sparql-operations \
  -f "/data" -un USERNAME -pw PASSWORD \
  -ep "http://graphdb.dumontierlab.com/repositories/ncats-test/statements" \
  -varServiceUrl http://localhost:7200/repositories/test \ 
  -varInputGraph http://data2services/graph/xml2rdf \ 
  -varOutputGraph https://w3id.org/data2services/graph/biolink/drugbank

# HGNC
docker run -it --rm -v "$PWD/sparql/insert-biolink/hgnc":/data \
  vemonet/data2services-sparql-operations \
  -f "/data" -un USERNAME -pw PASSWORD \
  -ep "http://graphdb.dumontierlab.com/repositories/ncats-test/statements" \
  --var-serviceUrl http://localhost:7200/repositories/test \
  --var-inputGraph http://data2services/graph/autor2rml \
  --var-outputGraph https://w3id.org/data2services/graph/biolink/hgnc

Tag summary

Content type

Image

Digest

Size

83.7 MB

Last updated

almost 7 years ago

docker pull aammar/data2services-sparql-operations