An open API service indexing awesome lists of open source software.

https://github.com/vemonet/translator-sparql-service

A SPARQL endpoint to serve NCATS Translator services as SPARQL custom functions.
https://github.com/vemonet/translator-sparql-service

fastapi rdflib sparql sparql-endpoints translator

Last synced: about 2 months ago
JSON representation

A SPARQL endpoint to serve NCATS Translator services as SPARQL custom functions.

Awesome Lists containing this project

README

          

# SPARQL endpoint for Translator services

A SPARQL endpoint to serve NCATS Translator services as SPARQL custom functions. Built with [rdflib-endpoint](https://github.com/vemonet/rdflib-endpoint)

Access the SPARQL service endpoint at https://service.translator.137.120.31.102.nip.io/sparql

OpenAPI docs at https://service.translator.137.120.31.102.nip.io

Translator APIs integrated:

* https://nodenormalization-sri.renci.org/docs

## Available functions 📬

**Try the queries on YASGUI**

### Get label for entity

From a CURIE, or URI following this pattern: https://identifiers.org/NAMESPACE:ID

```SPARQL
PREFIX umtranslator:
SELECT ?entity ?label WHERE {
BIND("MONDO:0005146" AS ?entity)
BIND(umtranslator:get_label(?entity) AS ?label)
}
```

### Get preferred ID

From a CURIE, or URI following this pattern: https://identifiers.org/NAMESPACE:ID

```SPARQL
PREFIX umtranslator:
SELECT ?entity ?pref_id WHERE {
BIND("MONDO:0005146" AS ?entity)
BIND(umtranslator:pref_id(?entity) AS ?pref_id)
}
```

### Try a federated query

Use this federated query to retrieve labels from any other SPARQL endpoint supporting federated queries.

**From another SPARQL endpoint**

```SPARQL
PREFIX umtranslator:
SELECT * WHERE
{
SERVICE {
SELECT ?entity ?label WHERE {
BIND("MONDO:0005146" AS ?entity)
BIND(umtranslator:get_label(?entity) AS ?label)
}
}
}
```

**From the RDFLib SPARQL endpoint**

⚠️ RDFLib has a few limitation related to federated queries:

* Unfortunately, the `PREFIX` keyword does not work with federated queries in RDFLib, so we need to write the full URIs

* The latest version of RDFLib (`5.0.0 `) only recognize **lowercase `service`**. This will be fixed in the next versions.

Run this federated query on this RDFLib endpoint to resolve drug/disease labels retrieved from the Nanopublication network:

```SPARQL
SELECT DISTINCT ?label ?subject ?object ((str(?subject)) AS ?subjectLabel) ((str(?object)) AS ?objectLabel)
WHERE {
service {
SELECT * WHERE {
GRAPH ?np_assertion {
?association ?label ;
?subject ;
?predicate ;
?object .
optional {
?association ?relation .
}
optional {
?association ?provided_by .
}
optional {
?association ?association_type .
}
?subject ?subject_category .
?object ?object_category .
}
filter ( ?subject_category = || ?subject_category = )
filter ( ?object_category = )
GRAPH ?np_head {
?np_uri ?np_assertion .
}
?np_uri .
filter NOT EXISTS { ?creator ?np_uri }
} LIMIT 5
}
}
```

> Note: Adding this filter make the federated query crash in RDFLib (works with Fuseki functions):
>
> ```SPARQL
> GRAPH {
> ?np_uri ?pubkey .
> }
> ```

## Install and run ✨️

1. Install dependencies

```bash
pip install -r requirements.txt
```

2. Run the server on http://localhost:8000

```bash
uvicorn main:app --reload --app-dir app
```

## Or run with docker 🐳

Checkout the `Dockerfile` to see how the image is built, and run it with the `docker-compose.yml`:

```bash
docker-compose up -d --build
```

Or build and run with docker:

```bash
docker build -t rdflib-endpoint .
```

Run on http://localhost:8080

```bash
docker run -p 8080:80 rdflib-endpoint
```

## Or deploy on the DSRI

Build from the `Dockerfile` and deploy in a DSRI project with HTTPS enabled:

```bash
oc new-build --name translator-sparql --binary
oc start-build translator-sparql --from-dir=. --follow --wait
oc new-app translator-sparql
oc patch deployment/translator-sparql --patch '{"spec":{"template": {"spec":{"serviceAccountName": "anyuid"}}}}'
oc expose svc/translator-sparql
oc patch route/translator-sparql --patch '{"spec":{"tls": {"termination": "edge", "insecureEdgeTerminationPolicy": "Redirect"}}}'
```

Get the routes exposed in your project:

```bash
oc get route
```

Delete:

```bash
oc delete build translator-sparql
```