@@ -403,7 +403,68 @@ def query_q(self):
403
403
# }
404
404
def query_p (self ):
405
405
# @TODO implement an MVP
406
- return self .query_q ()
406
+ langpair_full = self ._query_linguam ()
407
+ self .D1613_1_51_langpair = self ._query_linguam_limit (langpair_full )
408
+
409
+ qid = ['wd:' + x for x in self .qid if isinstance (x , str )]
410
+
411
+ _pid = self .pid [0 ]
412
+ # select = '?item ' + " ".join(self._query_linguam())
413
+
414
+ # select = ['(?item AS ?item__conceptum__codicem)']
415
+ select = [
416
+ '(STRAFTER(STR(?item), "entity/") AS ?item__conceptum__codicem)' ]
417
+ # select.append('(?itemLabel AS ?meta____rem__i_por__is_latn)')
418
+ # select = [
419
+ # '(STRAFTER(STR(?item), "entity/") AS ?item__conceptum__codicem)',
420
+ # '(STRAFTER(STR(?item), "entity/") AS ?item__rem__i_qcc__is_zxxx__ix_wikiq)'
421
+ # ]
422
+ filter_otional = []
423
+ for pair in self .D1613_1_51_langpair :
424
+ select .append ('?' + pair [1 ])
425
+
426
+ filter_otional .append (
427
+ 'OPTIONAL { ?item rdfs:label ?' +
428
+ pair [1 ] + ' filter (lang(?' + pair [1 ] +
429
+ ') = "' + pair [0 ] + '"). }'
430
+ )
431
+ filter_otional_done = [' ' + x for x in filter_otional ]
432
+
433
+ # term = """
434
+ # SELECT {select}
435
+ # WHERE
436
+ # {{
437
+ # VALUES ?item {{ {qitems} }}
438
+ # bind(xsd:integer(strafter(str(?item), 'Q')) as ?id_numeric) .
439
+ # {langfilter}
440
+ # }}
441
+ # ORDER BY ASC (?id_numeric)
442
+ # """.format(
443
+ # qitems=" ".join(qid),
444
+ # select=" ".join(select),
445
+ # langfilter="\n".join(filter_otional_done),
446
+ # )
447
+ term = """
448
+ SELECT {select} WHERE {{
449
+ {{
450
+ SELECT DISTINCT ?item WHERE {{
451
+ ?item p:{wikidata_p} ?statement0.
452
+ ?statement0 (ps:{wikidata_p}) _:anyValue{wikidata_p}.
453
+ }}
454
+ }}
455
+ {langfilter}
456
+ bind(xsd:integer(strafter(str(?item), 'Q')) as ?id_numeric) .
457
+ }}
458
+ ORDER BY ASC (?id_numeric)
459
+ """ .format (
460
+ wikidata_p = _pid ,
461
+ qitems = " " .join (qid ),
462
+ select = " " .join (select ),
463
+ langfilter = "\n " .join (filter_otional_done ),
464
+ )
465
+
466
+ # [TRY IT ↗]()
467
+ return term
407
468
408
469
def exportatum_sparql (self ):
409
470
resultatum = []
0 commit comments