User talk:Osamaahmed17/Outreachy-2

From Wikidata
Jump to navigation Jump to search

Hi @Osamaahmed17: Nice work! One quick question, when you run the code, part of the output is giving exceptions:

[[wikidata:Q4115189]] P18
Q4115189
Name: sandbox
P18 value:File:Earth.svg
That didn't work!"

and

[[wikidata:Q4115189]] P06
Q4115189
Name: sandbox
That didn't work!

Do you understand why these are happening? How would you solve them? Thanks. Mike Peel (talk) 08:56, 11 October 2021 (UTC)[reply]

Hi Mike,
Thank you, I appreciate it.
Well for the first exception, if we follow the below code
item_dict = wd_item.get()
print ('Name: ' + item_dict['labels']['en'])
try:
for claim in item_dict['claims'][x]:
value = claim.getTarget()
item_dict = value.get()
print (x+ ' value:' + value.title())
print (x+' label:' + item_dict['labels']['en'])
This code follows every claim (attribute) in the article (which we get from wd_item). Image property was having different type information as compared to different types and I first noticed it when I mentioned
in my first task https://www.wikidata.org/wiki/User:Osamaahmed17/Outreachy-1, so we can mention it as
print (x+' Description:' + item_dict[38:200]) , this will only take the required string for the description(have replaced label with description as it makes more sense). (I have mentioned on my task 2, https://www.wikidata.org/wiki/User:Osamaahmed17/Outreachy-2)
Whereas for the second exception, this specific type doesn't exist which can be seen if you follow this link (https://www.wikidata.org/wiki/Property:P06), hence, the code is showing an error as pywikibot can't find this type in the system but I have made improvement in the code to handle such cases (I have mentioned on my task 2, https://www.wikidata.org/wiki/User:Osamaahmed17/Outreachy-2) Osamaahmed17 (talk) 08:56, 12 October 2021 (UTC)[reply]
@Osamaahmed17: Thanks for the replies and the changes. P06 - that makes sense! P18 - it now returns P18 Description:scription={{de|1=Ruine der ''Commanderie du Mas Déu'', Trouillas, Frankreich (Ansicht von S). Mauerwerk des 18.-19. Jahrhunderts, erbaut auf Resten des mittelallt - I think because of item_dict[38:200]? If you look through the item_dict array structure, there should be a nicer way to extract this than to hard-code start and end numbers. Thanks. Mike Peel (talk) 11:21, 13 October 2021 (UTC)[reply]
@Mike Peel Well, I can explore that as well and see if there is any other way of extracting the description. Will update in a moment. Osamaahmed17 (talk) 13:03, 13 October 2021 (UTC)[reply]
I just added an extra function to my task which specifically takes out the description the text
def getFileDescription(text):
for i in mwparserfromhell.parse(text).filter_templates():
if 'information' in i.name.lower():
text=i.get('description').value
return text
Here is the response of it the https://phabricator.wikimedia.org/P17491 and for P18, it can be seen that the only description part is take out from the above function. Osamaahmed17 (talk) 16:18, 16 October 2021 (UTC)[reply]
@Osamaahmed17: That looks good, you can mark this as accepted/completed on Outreachy now! Thanks. Mike Peel (talk) 19:01, 16 October 2021 (UTC)[reply]