diff options
author | Pjotr Prins | 2020-11-06 12:48:00 +0000 |
---|---|---|
committer | Pjotr Prins | 2020-11-06 12:48:00 +0000 |
commit | 7c74a20b90ca647ca387eff2ed830c22f5ba1282 (patch) | |
tree | 8583e915b945901a04907db4c9f924ee24be5bad /scripts/db_enrichment/country_enrichment.py | |
parent | 5fdfece97fb2d50a10eab5004a6467ec0097ece8 (diff) | |
download | bh20-seq-resource-7c74a20b90ca647ca387eff2ed830c22f5ba1282.tar.gz bh20-seq-resource-7c74a20b90ca647ca387eff2ed830c22f5ba1282.tar.lz bh20-seq-resource-7c74a20b90ca647ca387eff2ed830c22f5ba1282.zip |
Country trouble shooting
Diffstat (limited to 'scripts/db_enrichment/country_enrichment.py')
-rw-r--r-- | scripts/db_enrichment/country_enrichment.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/scripts/db_enrichment/country_enrichment.py b/scripts/db_enrichment/country_enrichment.py index 1f99d42..f62a64e 100644 --- a/scripts/db_enrichment/country_enrichment.py +++ b/scripts/db_enrichment/country_enrichment.py @@ -39,14 +39,36 @@ def callSPARQL(query): g = Graph() +test_query=""" +# Use with https://query.wikidata.org/ +SELECT DISTINCT ?a ?label ?country ?continent ?coor WHERE { + BIND (XXX as ?a) . + OPTIONAL { + ?a wdt:P625 ?coor. + } + ?a rdfs:label ?label . + ?a wdt:P17 ?country. + ?country rdfs:label ?country_label . + OPTIONAL { + ?country wdt:P30 ?continent. + ?continent rdfs:label ?continent_label + FILTER (lang(?continent_label)='en') + } + FILTER (lang(?country_label)='en') + FILTER (lang(?label)='en') +} +""" + +# wdt:P625 are GEO coordinates + query = """ construct { ?a wdt:P625 ?c. ?a rdfs:label ?label . ?a wdt:P17 ?country. ?country rdfs:label ?country_label . - ?country wdt:P30 ?continent. - ?continent rdfs:label ?continent_label + ?country wdt:P30 ?continent . + ?continent rdfs:label ?continent_label . } WHERE { BIND (XXX as ?a) . @@ -59,7 +81,6 @@ construct { FILTER (lang(?continent_label)='en') FILTER (lang(?country_label)='en') FILTER (lang(?label)='en') - } """"" @@ -72,6 +93,8 @@ with open(outputFile, 'r') as csvfile: counter=counter+1 try: + testq = test_query.replace("XXX", "<"+row[0]+">") + print(testq) tmpquery=query.replace("XXX", "<"+row[0]+">") print(tmpquery) |