From d75f1c74fbf86652b02520de6ed46c981cf27e50 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 6 Nov 2020 10:13:05 +0000 Subject: Adding Tennessee items --- scripts/db_enrichment/country_enrichment.py | 43 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'scripts/db_enrichment/country_enrichment.py') diff --git a/scripts/db_enrichment/country_enrichment.py b/scripts/db_enrichment/country_enrichment.py index 8dcf5f2..1f99d42 100644 --- a/scripts/db_enrichment/country_enrichment.py +++ b/scripts/db_enrichment/country_enrichment.py @@ -1,3 +1,12 @@ +# This script by @LLTommy queries the main SPARQL end point to find what +# collections are missing country information for GPS coordinates, such +# +# rdfs:label "Canterbury Region" ; +# ns1:P17 ; +# ns1:P625 "Point(172.0 -43.6)" . +# +# See also the ./readme.md + import requests import csv from rdflib import Graph, Literal, RDF, URIRef @@ -30,30 +39,28 @@ def callSPARQL(query): g = Graph() - - query = """ construct { - ?a wdt:P625 ?c. + ?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 -} WHERE -{ - BIND (XXX as ?a) . - ?a wdt:P625 ?c. + ?a wdt:P17 ?country. + ?country rdfs:label ?country_label . + ?country wdt:P30 ?continent. + ?continent rdfs:label ?continent_label +} WHERE +{ + BIND (XXX as ?a) . + ?a wdt:P625 ?c. ?a rdfs:label ?label . - ?a wdt:P17 ?country. - ?country rdfs:label ?country_label . - ?country wdt:P30 ?continent. + ?a wdt:P17 ?country. + ?country rdfs:label ?country_label . + ?country wdt:P30 ?continent. ?continent rdfs:label ?continent_label - FILTER (lang(?continent_label)='en') + FILTER (lang(?continent_label)='en') FILTER (lang(?country_label)='en') - FILTER (lang(?label)='en') + FILTER (lang(?label)='en') -} +} """"" outputFile = 'input_location.csv' @@ -88,4 +95,4 @@ with open(outputFile, 'r') as csvfile: raise print(g.serialize(format='n3').decode("utf-8")) -g.serialize(destination='enriched_ouput.txt', format='turtle') \ No newline at end of file +g.serialize(destination='enriched_output.txt', format='turtle') -- cgit v1.2.3 From 7c74a20b90ca647ca387eff2ed830c22f5ba1282 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 6 Nov 2020 12:48:00 +0000 Subject: Country trouble shooting --- doc/INSTALL.md | 1 + scripts/db_enrichment/country_enrichment.py | 29 ++++++++++++++++++++++++++--- scripts/db_enrichment/input_location.csv | 10 ---------- scripts/db_enrichment/readme.md | 12 +++++++----- 4 files changed, 34 insertions(+), 18 deletions(-) (limited to 'scripts/db_enrichment/country_enrichment.py') diff --git a/doc/INSTALL.md b/doc/INSTALL.md index 45aca0f..367b452 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -77,6 +77,7 @@ Note: see above on GUIX_PACKAGE_PATH. ## Run country semantic enrichment script cd bh20-seq-resource/scripts/db_enrichment + edit input_location.csv guix environment guix --ad-hoc git python nss-certs python-rdflib -- python3 country_enrichment.py ## Run the tests 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) diff --git a/scripts/db_enrichment/input_location.csv b/scripts/db_enrichment/input_location.csv index a4246cd..8c3308f 100644 --- a/scripts/db_enrichment/input_location.csv +++ b/scripts/db_enrichment/input_location.csv @@ -1,16 +1,6 @@ http://www.wikidata.org/entity/Q7960498 http://www.wikidata.org/entity/Q692895 -http://www.wikidata.org/entity/Q928 http://www.wikidata.org/entity/Q2722074 http://www.wikidata.org/entity/Q25622187 http://www.wikidata.org/entity/Q27684996 http://www.wikidata.org/entity/Q2757125 -http://www.wikidata.org/entity/Q1922283 -http://www.wikidata.org/entity/Q490 -http://www.wikidata.org/entity/Q677037 -http://www.wikidata.org/entity/Q3037 -http://www.wikidata.org/entity/Q843 -http://www.wikidata.org/entity/Q183 -http://www.wikidata.org/entity/Q29 -http://www.wikidata.org/entity/Q17 -http://www.wikidata.org/entity/Q810 diff --git a/scripts/db_enrichment/readme.md b/scripts/db_enrichment/readme.md index 88e8be5..7539104 100644 --- a/scripts/db_enrichment/readme.md +++ b/scripts/db_enrichment/readme.md @@ -11,11 +11,13 @@ File containing information about the countries in our database. Additional info This SPARQL query (http://sparql.genenetwork.org/sparql/) retrieves all countries (ids) from our database that do not have a label yet: ->SELECT DISTINCT ?geoLocation WHERE ->{ ->?fasta ?x [ <> ?geoLocation] . ->FILTER NOT EXISTS {?geoLocation <> ?geoLocation_tmp_label} ->} +```sparql +SELECT DISTINCT ?geoLocation WHERE +{ + ?fasta ?x [ ?geoLocation] . + FILTER NOT EXISTS {?geoLocation ?geoLocation_tmp_label} +} +``` [Run query](http://sparql.genenetwork.org/sparql/?default-graph-uri=&query=%0D%0ASELECT+DISTINCT+%3FgeoLocation++WHERE%0D%0A%7B%0D%0A++%3Ffasta+%3Fx+%5B+%3Chttp%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FGAZ_00000448%3E+%3FgeoLocation%5D+.%0D%0A++FILTER+NOT+EXISTS+%7B%3FgeoLocation+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23label%3E+%3FgeoLocation_tmp_label%7D%0D%0A%7D&format=text%2Fhtml&timeout=0&debug=on&run=+Run+Query+) -- cgit v1.2.3 From 6c654dd60f98d473ba94fda6143d8b8b00f99586 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 6 Nov 2020 12:58:38 +0000 Subject: Add country entries that miss coordinates --- scripts/db_enrichment/country_enrichment.py | 2 +- semantic_enrichment/countries.ttl | 30 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) (limited to 'scripts/db_enrichment/country_enrichment.py') diff --git a/scripts/db_enrichment/country_enrichment.py b/scripts/db_enrichment/country_enrichment.py index f62a64e..37329fb 100644 --- a/scripts/db_enrichment/country_enrichment.py +++ b/scripts/db_enrichment/country_enrichment.py @@ -72,7 +72,6 @@ construct { } WHERE { BIND (XXX as ?a) . - ?a wdt:P625 ?c. ?a rdfs:label ?label . ?a wdt:P17 ?country. ?country rdfs:label ?country_label . @@ -81,6 +80,7 @@ construct { FILTER (lang(?continent_label)='en') FILTER (lang(?country_label)='en') FILTER (lang(?label)='en') + OPTIONAL { ?a wdt:P625 ?c } } """"" diff --git a/semantic_enrichment/countries.ttl b/semantic_enrichment/countries.ttl index 728877f..b0651cf 100644 --- a/semantic_enrichment/countries.ttl +++ b/semantic_enrichment/countries.ttl @@ -348,11 +348,6 @@ ns1:P30 ; ns1:P625 "Point(137.0 -28.0)" . - rdfs:label "India" ; - ns1:P17 ; - ns1:P30 ; - ns1:P625 "Point(83.0 22.8)" . - rdfs:label "Colombia" ; ns1:P17 ; ns1:P30 ; @@ -1389,6 +1384,31 @@ ns1:P30 ; ns1:P625 "Point(123.0 12.0)" . + rdfs:label "Bayad" ; + ns1:P17 ; + ns1:P625 "Point(73.0 20.8)" . + + rdfs:label "Choryasi Taluka" ; + ns1:P17 ; + ns1:P625 "Point(73.0 20.8)" . + + rdfs:label "Daskroi" ; + ns1:P17 ; + ns1:P625 "Point(72.0 22.0)" . + + rdfs:label "Wairarapa" ; + ns1:P17 ; + ns1:P625 "Point(174.0 -41.2)" . + + rdfs:label "Waitemata City" ; + ns1:P17 ; + ns1:P625 "Point(174.0 -41.2)" . + + rdfs:label "India" ; + ns1:P17 ; + ns1:P30 ; + ns1:P625 "Point(83.0 22.8)" . + rdfs:label "Oceania" . rdfs:label "North America" . rdfs:label "South America" . -- cgit v1.2.3