The problem I have is a bit far-fetched, but I will try to express it as clearly as I can.
I have two python files that contain different dictionaries.
In the file science.py the result of the dictionary is as follows:
dict1 = { "microbiome": {
"lang": "en",
"lemmatizer": "microbiome",
"Wikidata": "http://www.wikidata.org/entity/Q1330402"
"DBpedia": "http://dbpedia.org/resource/Microbiota"
}, "teaching innovation": {
"lang": "en",
"lemmatizer": "innovación docente",
"Wikidata": null,
"DBpedia": null
},
......
}
The content of the structure of this dictionary is built in a function that I have called process (word).
The output of the compact.py file is as follows:
dict2 = { http://dbpedia.org/resource/Microbiota :[
{'keyword': 'Microbiota', 'language': 'ca'},
{'keyword': 'Microbiota', 'language': 'en'},
{'keyword': 'Microbioma', 'language': 'es'}],
'teaching innovation': [{'keyword': 'Semantics',
'language': 'en'},
{'keyword': 'Semàntica', 'language': 'ca'},
{'keyword': 'Semántica lingüística',
'language': 'es'}],
.... }
The content of the structure of this dictionary is built by means of a function called query_kw (uri) where a query is made to the DBpedia page to get the translations of the word from the uri. This returns a list with the different translations of the word in the form of dictionaries.
As seen in dict2, it contains translations of a word along with the language they are in. What I am trying to do is check if the word from dict1 is found in dict2.
In the small example that I have put above you can see. If we look at dict1 a dictionary key is" microbiome "then I have to check if it is in the dictionary list of dict2. If it is not found as is the case then add it to the dict2 list in the same way as the others ({'keyword': microbiome, 'language': 'en'}).
Then the result would have to be the following:
dict2 = { http://dbpedia.org/resource/Microbiota :[
{'keyword': 'Microbiota', 'language': 'ca'},
{'keyword': 'Microbiota', 'language': 'en'},
{'keyword': 'Microbioma', 'language': 'es'},
{'keyword': 'microbiome', 'language': 'en'}],
'teaching innovation': [{'keyword': 'Semantics',
'language': 'en'},
{'keyword': 'Semàntica', 'language': 'ca'},
{'keyword': 'Semántica lingüística',
'language': 'es'}],
{'keyword': 'teaching innovation',
'language': 'en'}],
.... }
What I have tried has been the following (I know it is not optimal but it was to have an idea of how I can do it):
wrapper = query_kw(uri)
res_keys = process(palabra)
for k in rest_keys.keys():
wrap = {'keyword': rest_keys[k], 'language': rest_keys[k]['language']
for ind in wrapper:
for key, value in wrapper[ind]:
for ky, v in wrap:
if key is not ky and value is not v:
wrapper.append(wrap)
I already said, it is not beautiful to see nor is it optimal and above all it does not work correctly, but I can not think of how to do it. I hope I have explained myself well.