@@ -8,27 +8,65 @@ const noResultsDiv = document.getElementById("noResults");
88
99let treeDataWD = [ ] ;
1010
11- async function find_wd_result ( to_group_by = "categoryLabel" , limit = 100 ) {
11+ async function most_used_properties ( data_source ) {
12+ let VALUES = `` ;
13+ // ---
14+ // if data_source match Q\d+
15+ if ( data_source !== "" && data_source . match ( / Q \d + / ) ) {
16+ VALUES = `VALUES ?category { wd:${ data_source } }` ;
17+ }
18+ // ---
19+ let query = `
20+ SELECT ?prop ?propLabel (COUNT(?item) AS ?usage)
21+ WHERE {
22+ ${ VALUES }
23+ ?item rdf:type ontolex:LexicalEntry;
24+ wikibase:lemma ?lemma1;
25+ wikibase:lexicalCategory ?category; # الفئة: فعل
26+ dct:language wd:Q13955. # اللغة: العربية
27+
28+ # اختيار خصائص من مساحة بيانات Wikidata فقط
29+ ?item ?wdtProp ?value.
30+ FILTER(STRSTARTS(STR(?wdtProp), STR(wdt:)))
31+
32+ # تحويل URI للخاصية إلى عنصر الـProperty نفسه (Pxxxx)
33+ BIND(IRI(REPLACE(STR(?wdtProp), STR(wdt:), STR(wd:))) AS ?prop)
34+
35+ SERVICE wikibase:label { bd:serviceParam wikibase:language "ar,en". }
36+ }
37+ GROUP BY ?prop ?propLabel
38+ ORDER BY DESC(?usage)
39+ ` ;
40+ // ---
41+ let result = await loadsparqlQuery ( query ) ;
42+ // ---
43+ return result ;
44+ }
45+
46+ async function find_wd_result ( to_group_by = "categoryLabel" , data_source = "all" , limit = 100 ) {
1247 // ---
1348 let props_in = [
1449 "P31" ,
15- "P6771" ,
16- "P11038" ,
17- "P11757" ,
18- "P12451"
1950 ]
2051 // ---
2152 let add_group = "" ;
2253 let add_group_optional = "" ;
2354 // ---
2455 if ( to_group_by . startsWith ( "P" ) && ! props_in . includes ( to_group_by ) && to_group_by . match ( / ^ P [ 0 - 9 ] + $ / ) ) {
25- to_group_by = to_group_by . replace ( "P" , "" ) ;
26- // if to_group_by is number
56+ // TODO: this has no sense
57+ // to_group_by = to_group_by.replace("P", "");
2758 add_group = `(GROUP_CONCAT(DISTINCT ?${ to_group_by } _z; separator=", ") AS ?${ to_group_by } )` ;
2859 add_group_optional = `OPTIONAL { ?item wdt:${ to_group_by } ?${ to_group_by } _z. }` ;
2960
3061 }
3162 // ---
63+ let VALUES = `` ;
64+ // ---
65+ // if data_source match Q\d+
66+ if ( data_source !== "" && data_source . match ( / Q \d + / ) ) {
67+ VALUES = `VALUES ?category { wd:${ data_source } }` ;
68+ }
69+ // ---
3270 const sparqlQuery = `
3371 SELECT
3472 ?item
@@ -37,10 +75,10 @@ async function find_wd_result(to_group_by = "categoryLabel", limit = 100) {
3775 ?category ?categoryLabel ?P31Label
3876 (GROUP_CONCAT(DISTINCT ?P6771_z; separator=", ") AS ?P6771)
3977 (GROUP_CONCAT(DISTINCT ?P11038_z; separator=", ") AS ?P11038)
40- (GROUP_CONCAT(DISTINCT ?P11757_z; separator=", ") AS ?P11757)
4178 (GROUP_CONCAT(DISTINCT ?P12451_z; separator=", ") AS ?P12451)
4279 ${ add_group }
4380 WHERE {
81+ ${ VALUES }
4482 ?item rdf:type ontolex:LexicalEntry;
4583 wikibase:lemma ?lemma1;
4684 wikibase:lexicalCategory ?category;
@@ -49,7 +87,6 @@ async function find_wd_result(to_group_by = "categoryLabel", limit = 100) {
4987 OPTIONAL { ?item wdt:P31 ?P31. }
5088 OPTIONAL { ?item wdt:P6771 ?P6771_z. }
5189 OPTIONAL { ?item wdt:P11038 ?P11038_z. }
52- OPTIONAL { ?item wdt:P11757 ?P11757_z. }
5390 OPTIONAL { ?item wdt:P12451 ?P12451_z. }
5491 ${ add_group_optional }
5592 }
@@ -62,7 +99,7 @@ async function find_wd_result(to_group_by = "categoryLabel", limit = 100) {
6299 let wd_result = { } ;
63100
64101 for ( const item of result ) {
65- let to_group = item [ to_group_by ] || '! ' ;
102+ let to_group = item [ to_group_by ] || 'غير محدد ' ;
66103
67104 if ( ! wd_result [ to_group ] ) {
68105 // ---
@@ -119,11 +156,21 @@ function renderTree(data, all_open) {
119156 const isOpen = ! ul . classList . contains ( "d-none" ) ;
120157 icon . className = `bi ${ isOpen ? "bi-chevron-double-down" : "bi-chevron-double-left" } arrow-icon` ;
121158 } ;
122-
159+ // ---
160+ let label = category . group_by ;
161+ // ---
162+ if ( label !== "" && ( label . match ( / Q \d + / ) || label . match ( / L \d + / ) ) ) {
163+ label = `<span find-label="${ label } " find-label-both="true">${ label } </span>` ;
164+ }
165+ // ---
123166 // محتوى الزر عند الإنشاء
124167 button . innerHTML = `
125- <span class="fw-medium text-black">${ category . group_by } </span>
126- <span class="text-muted ms-2">(${ category . items . length } )</span>
168+ <span class="fw-medium text-black">
169+ ${ label }
170+ </span>
171+ <span class="text-muted ms-2">
172+ (${ category . items . length } )
173+ </span>
127174 <i class="bi bi-chevron-double-left arrow-icon"></i>
128175 ` ;
129176
@@ -174,9 +221,9 @@ function get_param_from_window_location1(key, defaultvalue) {
174221 return urlParams . get ( key ) || defaultvalue ;
175222}
176223
177- async function fetchData ( limit , group_by ) {
224+ async function fetchData ( limit , data_source , group_by ) {
178225 // ---
179- const treeMap = await find_wd_result ( group_by , limit ) ;
226+ const treeMap = await find_wd_result ( group_by , data_source , limit ) ;
180227
181228 // count all items.length in wd_result
182229 let count = Object . values ( treeMap ) . reduce ( ( sum , obj ) => sum + obj . items . length , 0 ) ;
0 commit comments