This repository has been archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example to test sparql endpoint; refs #46
- Loading branch information
Anthony Bargnesi
committed
Mar 19, 2014
1 parent
1c6749b
commit 4734aad
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |