--- a/web/hdalab/management/commands/geojson_transform.py Fri Mar 02 23:25:56 2012 +0100
+++ b/web/hdalab/management/commands/geojson_transform.py Sun Mar 11 03:27:09 2012 +0100
@@ -7,6 +7,10 @@
import django.utils.simplejson as json
from SPARQLWrapper import SPARQLWrapper, JSON
+#import pydevd #@UnresolvedImport
+#pydevd.settrace(suspend=False)
+
+
class Command(BaseCommand):
'''
Command to export tags
@@ -59,6 +63,7 @@
base_uri_list = [base_uris[uri] for uri in base_uris]
french_labels = {}
+ labels = {}
start = 0
while start < len(base_uri_list):
@@ -67,18 +72,23 @@
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?country ?label WHERE {
?country rdfs:label ?label .
- FILTER (?country in (<%s>)) .
- FILTER langMatches( lang(?label), "fr" )
+ FILTER (?country in (<%s>))
}
""" % '>, <'.join(base_uri_list[start:start + grp])
endpoint.setQuery(sparql)
results = endpoint.query().convert()
+ print repr(results)
+
for r in results["results"]["bindings"]:
country = r["country"]["value"]
label = r["label"]["value"]
- french_labels[country] = label
+ if country not in labels:
+ labels[country] = {}
+ labels[country][r["label"]["xml:lang"]] = label
+ if r["label"]["xml:lang"] == 'fr':
+ french_labels[country] = label
print "%s label: %s"%(country, label)
start += grp
@@ -86,6 +96,9 @@
for feature in geojson['features']:
base_uri = base_uris[uris[feature['properties']['name']]]
feature['properties']['dbpedia_uri'] = base_uri
+
+ if labels.has_key(base_uri):
+ feature['properties']['labels'] = labels[base_uri]
if french_labels.has_key(base_uri):
feature['properties']['label_fr'] = french_labels[base_uri]
else: