Skip to content

Commit

Permalink
Merge pull request #117 from WikiAr/update
Browse files Browse the repository at this point in the history
.
  • Loading branch information
MrIbrahem authored Dec 20, 2024
2 parents e6e1ca4 + 5eb4de9 commit 771982b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
16 changes: 12 additions & 4 deletions nep/si3g_qua.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
python3 core8/pwb.py nep/si3g_qua returnlab
python3 core8/pwb.py nep/si3g_qua returnlab -p27:Q1028
python3 core8/pwb.py nep/si3g_qua returnlab -p27:Q79
"""
import time
import random
import sys
from newapi import printe

Expand Down Expand Up @@ -48,6 +50,11 @@
if not P27[1]:
P27[1] = list(set(qid_to_p27.keys()))

# ---
random.shuffle(P106[1])
random.shuffle(P27[1])
# ---


def get_qua():
# ---
Expand Down Expand Up @@ -76,9 +83,9 @@ def get_qua():
# ---
qua += f"\n limit {limit[1]}"
# ---
printe.output(f" len P106:{len(P106[1])}")
printe.output(f" len P106 :{len(P106[1])}")
# ---
printe.output(f" len P27:{len(P27[1])}")
printe.output(f" len P27 :{len(P27[1])}")
# ---
if P106[1]:
line = "values ?p106 {" + " ".join([f"wd:{x}" for x in P106[1]]) + "} \n #sr"
Expand All @@ -93,7 +100,6 @@ def get_qua():

def one_item(qid, num):
# {'item': 'http://www.wikidata.org/entity/Q21457154', 'qid': 'Q21457154'}

item = wd_bot.Get_Item_API_From_Qid(qid, props="claims|descriptions|labels")
# ---
if not item:
Expand All @@ -119,7 +125,7 @@ def main():
# ---
printe.output(f"n:{n}/{len(P27[1])} work:")
# ---
line = f"?item wdt:P27 wd:{nat_qid}."
line = f"?item wdt:P27 wd:{nat_qid}. # " + qid_to_p27.get(nat_qid, "")
# ---
qua = base_qua
# ---
Expand All @@ -132,6 +138,8 @@ def main():
# ---
for num, tab in enumerate(lista, start=1):
qid = tab["qid"]
# ---
printe.output(f'*<<lightred>> >{num}/{len(lista)} one_item "{qid}" < :')
# si3.ISRE(qid, num, len(lista), get_nl_des=False)
one_item(qid, num)
# ---
Expand Down
2 changes: 1 addition & 1 deletion nep/wr_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def work_people2(item, topic, num=0, years=""):
if not taber:
return ""
# ---
printe.output(taber)
# printe.output(taber)
# ---
descriptions = item.get("descriptions", {})
# ---
Expand Down
39 changes: 26 additions & 13 deletions people/people_get_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,36 +421,49 @@ def get_claim_id(item, prop):
return claim


def get_claim_ids(item, prop):
claims = item.get("claims", {}).get(prop, [])
claim_ids = [claim.get("mainsnak", {}).get("datavalue", {}).get("value", {}).get("id", "") for claim in claims]
return claim_ids


new_jobs = {}
new_nats = {}


def get_topic(item):
# ---
P106 = get_claim_id(item, "P106")
P27 = get_claim_id(item, "P27")
P106_list = get_claim_ids(item, "P106")
P27_list = get_claim_ids(item, "P27")
# ---
printe.output(f" P106:{P106}: P27:{P27}")
p27_lab = ""
p106_lab = ""
# ---
lab = ""
for x in P106_list:
p106_lab = qid_to_job.get(x)
if p106_lab:
break
else:
new_jobs.setdefault(x, 0)
new_jobs[x] += 1
# ---
p106_lab = qid_to_job.get(P106)
p27_lab = qid_to_p27.get(P27)
for x in P27_list:
p27_lab = qid_to_p27.get(x)
if p27_lab:
break
else:
new_nats.setdefault(x, 0)
new_nats[x] += 1
# ---
if not p106_lab:
new_jobs.setdefault(P106, 0)
new_jobs[P106] += 1
# ---
if not p27_lab:
new_nats.setdefault(P27, 0)
new_nats[P27] += 1
lab = ""
# ---
if p106_lab and p27_lab:
# lab = p106_lab.replace("~", p27_lab)
lab = f"{p27_lab} {p106_lab}"
printe.output(f" topic:{lab}")
# ---
if not lab:
printe.output(f"{p106_lab=} {p27_lab=}")
return ""
# ---
if "returnlab" in sys.argv:
Expand Down

0 comments on commit 771982b

Please sign in to comment.