Skip to content

Commit 995a47f

Browse files
authored
Merge pull request #16 from MrIbrahem/update
z
2 parents d60aa91 + 2a3f185 commit 995a47f

File tree

4 files changed

+80
-6
lines changed

4 files changed

+80
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ python/src/no_data_tab.json
2020
public_html/web.config
2121
/public_html
2222
python/src/static/js/duplicate_lemmas2.js
23+
python/src/static/js/‏‏duplicate_lemmas - نسخة.js

python/src/static/js/duplicate_lemmas.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ async function get_wdresult(same_category = false) {
106106
WHERE {
107107
{
108108
SELECT DISTINCT *
109-
#?1_item ?2_item ?lemma ?1_category ?2_category
110109
WHERE
111110
{
112111
# values ?lemma {"أنتما"@ar }
@@ -155,7 +154,7 @@ async function get_wdresult(same_category = false) {
155154
async function get_data_dup(same_category) {
156155
let wdresult = await get_wdresult(same_category);
157156
// ---
158-
console.table(wdresult);
157+
// console.table(wdresult);
159158
// ---
160159
wdresult = convertData(wdresult);
161160
// ---

python/src/static/js/lex/find_labels.js

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,95 @@
1+
2+
let urls_types = {
3+
// "P": "https://www.wikidata.org/w/rest.php/wikibase/v1/entities/properties/$1/labels", // {"ar": "", "en": ""}
4+
"Q": "https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/$1/labels", // {"ar": "", "en": ""}
5+
"L": "https://www.wikidata.org/wiki/Special:EntityData/$1.json", // entities.lemmas
6+
};
7+
18
async function find_labels() {
9+
const spans = document.querySelectorAll("span[find-label]");
10+
console.log(`find_labels: ${spans.length}`);
11+
12+
spans.forEach(async (span) => {
13+
const qid = span.getAttribute("find-label");
14+
const both = span.getAttribute("find-label-both");
15+
const noCache = span.getAttribute("no-cache");
16+
if (!qid) return;
17+
18+
const cached = localStorage.getItem(`wikidata-label-2-${qid}`);
19+
if (cached && !noCache) {
20+
span.textContent = cached;
21+
return;
22+
}
23+
24+
try {
25+
const prefix = qid.charAt(0).toUpperCase();
26+
const urlTemplate = urls_types[prefix] || urls_types["L"];
27+
const url = urlTemplate.replace("$1", qid);
28+
29+
let urls_load = $("#urls_load");
30+
if (urls_load.length) {
31+
let link = `<a href="${url}" target="_blank">${url}</a>`;
32+
urls_load.append(`<li>${link}</li>`);
33+
}
34+
35+
const response = await fetch(url);
36+
if (!response.ok) throw new Error("فشل في جلب البيانات");
37+
38+
const data = await response.json();
39+
40+
let labelAr;
41+
42+
if (urls_types[prefix] && (prefix === "Q" || prefix === "P")) {
43+
labelAr = data?.ar || data?.en || data?.mul || qid;
44+
} else {
45+
const entity = data.entities[qid];
46+
if (entity?.type === "lexeme") {
47+
labelAr = Object.values(entity.lemmas || {})
48+
.map(l => l.value)
49+
.filter(Boolean)
50+
.join(" / ") || "(غير متوفر)";
51+
} else {
52+
let labels = entity?.labels || {};
53+
labelAr = labels?.ar?.value || labels?.en?.value || labels?.mul?.value || "(غير متوفر)";
54+
}
55+
}
56+
57+
if (labelAr) {
58+
const labelFinal = both ? `${labelAr} (${qid})` : labelAr;
59+
span.textContent = labelFinal;
60+
localStorage.setItem(`wikidata-label-2-${qid}`, labelFinal);
61+
}
62+
63+
} catch (error) {
64+
console.error(`خطأ في جلب الاسم لـ ${qid}:`, error);
65+
}
66+
});
67+
}
68+
69+
async function find_labels_old() {
270
const spans = document.querySelectorAll("span[find-label]");
371
console.log(`find_labels: ${spans.length}`)
472
spans.forEach(async (span) => {
573
const qid = span.getAttribute("find-label");
674
const both = span.getAttribute("find-label-both");
75+
const noCache = span.getAttribute("no-cache");
776
if (!qid) return;
877

978
// حاول الحصول على الاسم من localStorage أولاً
1079
const cached = localStorage.getItem(`wikidata-label-2-${qid}`);
11-
if (cached) {
80+
if (cached && !noCache) {
1281
span.textContent = cached;
1382
return;
1483
}
1584

1685
try {
1786
const url = `https://www.wikidata.org/wiki/Special:EntityData/${qid}.json`;
87+
let urls_load = $("#urls_load");
88+
if (urls_load.length) {
89+
let link = `<a href="${url}" target="_blank">${qid}</a>`;
90+
urls_load.append(`<li>${link}</li>`);
91+
}
92+
1893
const response = await fetch(url);
1994
if (!response.ok) throw new Error("فشل في جلب البيانات");
2095

@@ -40,3 +115,4 @@ async function find_labels() {
40115
}
41116
});
42117
}
118+

python/src/static/js/lex/lex.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,7 @@ async function Q24905(entity) {
446446
// display_mt_cells[verb] = [number, row, col, gender].includes("");
447447
display_mt_cells[verb] = [number, col, gender].includes("");
448448
//
449-
if (display_mt_cells[verb]) {
450-
console.table(form.id);
451-
}
449+
// if (display_mt_cells[verb]) { console.table(form.id); }
452450
}
453451
// ---
454452
let result = "";

0 commit comments

Comments
 (0)