Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
example to test sparql endpoint; refs #46
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Bargnesi committed Mar 19, 2014
1 parent 1c6749b commit 4734aad
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions sparql_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
# -*- coding: utf8 -*-
# vim: ts=4 sw=4:
from json import dumps
from urllib.error import HTTPError
from SPARQLWrapper import SPARQLWrapper, GET, JSON


def query(query, endpoint):
sparql = SPARQLWrapper(endpoint)
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
sparql.setMethod(GET)

try:
result = sparql.query()
return result.convert()
except HTTPError as e:
print(str(e))

if __name__ == '__main__':
import sys

if len(sys.argv) != 2:
sys.stderr.write('usage: sparql_test.py [SPARQL_ENDPOINT_URL]\n')
sys.exit(1)

endpoint_url = sys.argv[1]
EXACT_MATCH_ORPHANS = """
prefix skos: <http://www.w3.org/2004/02/skos/core#>
select (count(distinct ?uri2) as ?count)
where {
?uri1 skos:exactMatch ?uri2 .
minus { ?uri2 skos:inScheme ?scheme .}
}
"""
ORTHOLOGOUS_MATCH_ORPHANS = """
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix belv: <http://www.openbel.org/vocabulary/>
select (count(distinct ?uri2) as ?count)
where {
?uri1 belv:orthologousMatch ?uri2 .
minus { ?uri2 skos:inScheme ?scheme .}
}
"""

print("Orphans for exactMatch:")
print(dumps(query(EXACT_MATCH_ORPHANS, endpoint_url), indent=4))

print("Orphans for orthologousMatch:")
print(dumps(query(ORTHOLOGOUS_MATCH_ORPHANS, endpoint_url), indent=4))

0 comments on commit 4734aad

Please sign in to comment.