Parsing dbpedia JSON in Python

I am trying to figure out the dbpedia JSON schema and cannot find an efficient way to retrieve a specific node:

This is what dbpedia gives me:

http://dbpedia.org/data/Ceramic_art.json

I have everything as a JSON object in Python, but I really don't understand how to get an English abstraction from this data. I got this far:

u = "http://dbpedia.org/data/Ceramic_art.json" data = urlfetch.fetch(url=u) json_data = json.loads(data.content) for j in json_data["http://dbpedia.org/resource/Ceramic_art"]: if(j == "http://dbpedia.org/ontology/abstract"): print "it here" 

Not sure how to get out of here. As you can see, there are several languages. I need to get an annotation in English.

Thanks for your help,

g

+4
source share
2 answers
 print [abstract['value'] for abstract in json_data["http://dbpedia.org/resource/Ceramic_art"]["http://dbpedia.org/ontology/abstract"] if abstract['lang'] == 'en'][0] 

Obviously, you want to make more mistakes than this, in case the data is bad, but that is the main idea.

+3
source

This is a list of dicts. Just iterate over the list items until you find one whose value for u'lang' is equal to u'en' .

+3
source

Source: https://habr.com/ru/post/1309602/


All Articles