utf 8 - UTF-8 encoding not working with data parsed from DBpedia using RDFLib in Python 2 -


i have following code parse data dbpedia output , add rdflib graph:

for index, value in enumerate(output['results']['bindings']):      #the encoding necessary parse non-english characters     subj_raw = '<' + value['s']['value'].encode('utf-8') + '>'     subj_refined = uriref(subj_raw)     pred_raw = '<' + value['p']['value'].encode('utf-8') + '>'     pred_refined = uriref(pred_raw)     if 'http' in value['o']['value']:         obj_raw = '<' + value['o']['value'].encode('utf-8') + '>'         obj_refined = uriref(obj_raw)     else:         obj_raw = '"' + value['o']['value'].encode('utf-8') + '"'         obj_refined = uriref(obj_raw)     datagraph.add((subj_refined,pred_refined,obj_refined)) 

despite using .encode('utf-8'), non-ascii characters not read (by interpreter ?). have read responses on utf-8 on haven't been able figure out solution.

why code not working? need change?

update 1:

following examples of failed encoding:

(rdflib.term.uriref(u"<http://dbpedia.org/resource/as_dragons_fc_de_l'ou%c3%a9m%c3%a9>"),  rdflib.term.uriref(u'<http://dbpedia.org/property/ground>'),  rdflib.term.uriref(u'<http://dbpedia.org/resource/benin>'))  (rdflib.term.uriref(u'<http://dbpedia.org/resource/benin>'),  rdflib.term.uriref(u'<http://www.w3.org/2000/01/rdf-schema#comment>'),  rdflib.term.uriref(u'"o benim, oficialmente designado como rep\xfablica benim (em franc\xeas: r\xe9publique du b\xe9nin), \xe9 um pa\xeds da regi\xe3o ocidental da \xc1frica limitado norte pelo burkina faso e pelo n\xedger, leste pela nig\xe9ria, sul pela enseada benim e oeste pelo togo.a capital constitucional \xe9 cidade de porto-novo, mas cotonou \xe9 sede governo e maior cidade pa\xeds. o pa\xeds tem 112 622 km\xb2 e uma popula\xe7\xe3o de quase 9 milh\xf5es de habitantes (2009)."'))  (rdflib.term.uriref(u'<http://dbpedia.org/resource/benin>'),  rdflib.term.uriref(u'<http://dbpedia.org/ontology/abstract>'),  rdflib.term.uriref(u'"benin [be\u02c8ni\u02d0n] (frz. b\xe9nin [be\u02c8n\u025b\u0303]) ist ein staat in westafrika. er grenzt im westen togo, im norden burkina faso und niger, im osten nigeria und im s\xfcden den golf von guinea, genauer die bucht von benin.bis 1975 hie\xdf das land dahomey. die bezeichnung steht in tradition zum historischen k\xf6nigreich dahomey, das bis zur eroberung durch die franzosen ende des 19. jahrhunderts den s\xfcdlichen teil des modernen staates und des nachbarstaates togo umfasste. beim human development index steht das land auf dem 165. platz von 187."')) 


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -