User:DwivediAntima/Extract the author's information from scientific articles
(Redirected from User:DwivediAntima/Outreachy 2)
Impoting libraries and loading Outreachy_1 page:
[edit]import pywikibot
# Connect to ptwiki
ptwiki = pywikibot.Site('wikidata:wikidata', user='DwivediAntima')
# and then to wikidata
ptwiki_repo = ptwiki.data_repository()
page = pywikibot.Page(ptwiki, 'User:DwivediAntima/Outreachy 1')
Adding Hello to the end of page:
[edit]def Add_Hello(page):
text = page.get()
text = text + "\nHello"
page.text = text
try:
page.save("Saving test edit")
return 1
except:
print("That didn't work!")
return 0
print(Add_Hello(page))
Output:
[edit]Page [[User:DwivediAntima/Outreachy 1]] saved
1
Information of sandbox page:
[edit]Information of sandbox page
def sandbox_info(item):
qid = item.title()
item_dict =item.get()
try:
print('Name: ' + item_dict['labels']['en'])
except:
print('No English label!')
try:
for claim in item_dict['claims']['P31']:
p31_value = claim.getTarget()
p31_item_dict = p31_value.get()
print('Instance of: ' + p31_item_dict['labels']['en'])
except:
print("That didn't work!")
try:
for claim in item_dict['claims']['P17']:
p17_value = claim.getTarget()
p17_item_dict = p17_value.get()
print('Country: ' + p17_item_dict['labels']['en'])
except:
print("That didn't work!")
try:
for claim in item_dict['claims']['P36']:
p36_value = claim.getTarget()
p36_item_dict = p36_value.get()
print ('Capital: ' + p36_item_dict['labels']['en'])
except:
print ("That didn't work!")
try:
for claim in item_dict['claims']['P131']:
p131_value = claim.getTarget()
p131_item_dict = p131_value.get()
print("located in the administrative territorial entity: " + p131_item_dict['labels']['en'])
except:
print("That didn't work!")
try:
for claim in item_dict['claims']['P150']:
p131_value = claim.getTarget()
p131_item_dict = p131_value.get()
print('contains the administrative territorial entity: ' + p131_item_dict['labels']['en'])
except:
print("That didn't work!")
try:
for claim in item_dict['claims']['P4565']:
p4565_value = claim.getTarget()
print(f"{label_of_property('P4565')}: {p4565_value}")
except:
print("That didn't work!")
try:
for claim in item_dict['claims']['P460']:
p131_value = claim.getTarget()
p131_item_dict = p131_value.get()
print('said to be the same as: ' + p131_item_dict['labels']['en'])
except:
print("That didn't work!")
return 0
Output:
[edit]Name: Wikidata Sandbox
Instance of: Wikidata internal entity
Instance of: electoral district
Instance of: Template:Municipalities Liechtenstein
Country: Netherlands
Capital: Rotterdam
located in the administrative-territorial entity: South Holland
contains the administrative-territorial entity: Rotterdam
electoral district number: I
electoral district number: 2
said to be the same as: Wikidata sandbox 2
said to be the same as: Wikidata Sandbox 3
0
extracting author information from scientific articles:
[edit]def name_information(author, pid):
return author.claims[pid][0].getTarget().labels['en']
def label_of_property(pid):
property_page = pywikibot.PropertyPage(ptwiki_repo, pid)
return property_page.labels['en']
def printwikidata(wd_item):
item_dict = wd_item.get()
try:
print('Name: ' + item_dict['labels']['en'])
except:
print('No English label!')
try:
for claim in item_dict['claims']['P50']:
p50_value = claim.getTarget()
p50_item_dict = p50_value.get()
qid=p50_value.title()
print('author :' + p50_item_dict['labels']['en'])
author = pywikibot.ItemPage(ptwiki_repo, qid)
if author.get():
print('Redirecting.......')
try:
print(f"{label_of_property('P735')}: {name_information(author, 'P735')}")
except:
print("That didn't work. (given name information is not available)")
try:
print(f"{label_of_property('P734')}: {name_information(author, 'P734')}")
except:
print("That didn't work. (family name information is not available)")
except:
print("That didn't work!")
try:
for claim in item_dict['claims']['P2093']:
p2093_value = claim.getTarget()
print(f"{label_of_property('P2093')}: {p2093_value}")
except:
print("That didn't work!")
print("************************************************************************************************************************************")
return 0
list_of_articles=['Q33562513','Q35224842','Q38873946']
for article in range(len(list_of_articles)):
page = pywikibot.ItemPage(ptwiki_repo, list_of_articles[article])
test = printwikidata(page)
Output:
[edit]Name: Tunneling/shear force microscopy using piezoelectric tuning forks for characterization of topography and local electric surface properties
Q63660686
author :Grzegorz Jóźwiak
Redirecting.......
given name: Grzegorz
family name: Jóźwiak
author name string: Mirosław Woszczyna
author name string: Paweł Zawierucha
author name string: Agata Masalska
author name string: Elzbieta Staryga
author name string: Teodor Gotszalk
************************************************************************************************************************************
Name: Electric double-layer potentials and surface regulation properties measured by colloidal-probe atomic force microscopy
Q84282867
author :Francisco Javier Montes Ruiz-Cabello
Redirecting.......
given name: Francisco
That didn't work because family name information is not available.
Q58467705
author :Gregor Trefalt
Redirecting.......
That didn't work because given name information is not available.
That didn't work because family name information is not available.
author name string: Plinio Maroni
author name string: Michal Borkovec
**************************************************************************************************************************************
Name: Friction forces position the neural anlage.
Q59702553
author :Michael Smutny
Redirecting.......
given name: Michael
family name: Smutny
Q1426002
author :Tamás Vicsek
Redirecting.......
given name: Tamás
That didn't work because family name information is not available.
Q41901644
author :Guillaume Salbreux
Redirecting.......
given name: Guillaume
That didn't work because family name information is not available.
Q33125331
author :Carl-Philipp Heisenberg
Redirecting.......
given name: Carl
That didn't work because family name information is not available.
author name string: Zsuzsa Ákos
author name string: Silvia Grigolon
author name string: Shayan Shamipour
author name string: Verena Ruprecht
author name string: Daniel Čapek
author name string: Martin Behrndt
author name string: Ekaterina Papusheva
author name string: Masazumi Tada
author name string: Björn Hof