Browse Source

finished function for dict import, started function to check for existing entities, already running for ishuman (q5)

master
corsaronero 1 year ago
parent
commit
7ade95deb5
6 changed files with 70 additions and 2 deletions
  1. BIN
      .main.py.kate-swp
  2. +2
    -0
      main.py
  3. +33
    -0
      q5.txt
  4. BIN
      wikidata/.wdPEP.py.kate-swp
  5. BIN
      wikidata/__pycache__/wdPEP.cpython-310.pyc
  6. +35
    -2
      wikidata/wdPEP.py

BIN
.main.py.kate-swp View File


+ 2
- 0
main.py View File

@ -25,3 +25,5 @@ listOfCountries = ['nicaragua']
wikidataPEP = WikidataPEP(config) wikidataPEP = WikidataPEP(config)
wikidataPEP.importMembersOfParliamentDict(listOfCountries) wikidataPEP.importMembersOfParliamentDict(listOfCountries)
wikidataPEP.checkForEntityIds(listOfCountries)

+ 33
- 0
q5.txt View File

@ -0,0 +1,33 @@
started to parse data of members of nicaragua ..
Q107326760
---------
Ángela Espinoza Tórrez
is a human
Q475730
---------
Carlos Humberto Ruíz
is a human
Q107316535
---------
Iris Marina Montenegro Blandón
is a human
Q107332750
---------
Iris Marina Montenegro Blandón
is a human
Q107320919
---------
Iris Marina Montenegro Blandón
is a human
Q63794924
---------
Loria Raquel Dixon Brautigam
is a human
Q107406987
---------
María Haydee Osuna Ruíz
is a human
Q106514750
---------
Shaira Natasha Downs Morgan
is a human

BIN
wikidata/.wdPEP.py.kate-swp View File


BIN
wikidata/__pycache__/wdPEP.cpython-310.pyc View File


+ 35
- 2
wikidata/wdPEP.py View File

@ -24,14 +24,47 @@ class WikidataPEP(object):
for country in listOfCountries: for country in listOfCountries:
print('started to parse data of member of ' + country + ' ..')
print('started to parse data of members of ' + country + ' ..')
f = open('crawlers/output/' + country +'MemberList.txt') f = open('crawlers/output/' + country +'MemberList.txt')
text = f.read() text = f.read()
self.fullDictionaryMemberLists[country] = eval(text) self.fullDictionaryMemberLists[country] = eval(text)
print(self.fullDictionaryMemberLists)
#print(self.fullDictionaryMemberLists)
def checkForEntityIds(self, listOfCountries):
from wikibaseintegrator import WikibaseIntegrator
from wikibaseintegrator import wbi_helpers
fullDictionaryMemberLists = self.fullDictionaryMemberLists
for country in listOfCountries:
for memberId in fullDictionaryMemberLists[country].keys():
name = fullDictionaryMemberLists[country][memberId]['name']
results = wbi_helpers.search_entities(search_string=name)
for entityId in results:
wbi = WikibaseIntegrator()
wikidata_item = wbi.item.get(entity_id=entityId)
for claimkey in wikidata_item.get_json()['claims'].keys():
if claimkey == 'P31':
if wikidata_item.get_json()['claims'][claimkey][0]['mainsnak']['datavalue']['value']['id'] == 'Q5':
print(entityId)
print('---------')
print(name)
print('is a human')

Loading…
Cancel
Save