Skip to content

Commit

Permalink
1603_3_12.py (#40): --actionem-sparql --de=P --query --ex-interlingui…
Browse files Browse the repository at this point in the history
…s --cum-interlinguis=P1,P2... (bugfix; duplicated related atributes now concatenate with |)
  • Loading branch information
fititnt committed May 12, 2022
1 parent 8a84ec6 commit 36dff26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 40 deletions.
52 changes: 14 additions & 38 deletions officinam/999999999/0/1603_3_12.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,41 +300,12 @@ def est_wikidata_p_interlinguis(self, statum: bool = True):
self.ex_interlinguis = statum

def est_wikidata_p_cum_interlinguis(self, cum_interlinguis: list = None):
# print('oiaa', cum_interlinguis)
if cum_interlinguis and len(cum_interlinguis):
# print('oi3')
for item in cum_interlinguis:
self.cum_interlinguis.append(item.upper().replace('P', ''))
# self.cum_interlinguis = cum_interlinguis
self.cum_interlinguis = sorted(self.cum_interlinguis)
# print('oi a', self.cum_interlinguis)
return self

# def query(self):
# term = """# https://en.wikiversity.org/wiki/Research_in_programming_Wikidata/Countries#List_of_countries
# # https://w.wiki/4ij4
# SELECT ?item ?item__eng_latn ?item__rus_cyrl
# WHERE
# {
# ?item wdt:P31 wd:Q6256. # instance country
# OPTIONAL {
# ?item rdfs:label ?item__eng_latn filter (lang(?item__eng_latn) = "en").
# ?item rdfs:label ?item__rus_cyrl filter (lang(?item__rus_cyrl) = "ru").
# }
# }
# """
# return term
self.cum_interlinguis = sorted(self.cum_interlinguis, key=int)


# SELECT ?item ?item_rem__eng_latn ?item_rem__rus_cyrl
# WHERE
# {
# VALUES ?item { wd:Q1065 wd:Q82151 wd:Q125761 wd:Q7809 }
# OPTIONAL {
# ?item rdfs:label ?item_rem__eng_latn filter (lang(?item_rem__eng_latn) = "en").
# ?item rdfs:label ?item_rem__rus_cyrl filter (lang(?item_rem__rus_cyrl) = "ru").
# }
# }
return self

def query_q(self):
langpair_full = self._query_linguam()
Expand All @@ -346,10 +317,7 @@ def query_q(self):
# select = ['(?item AS ?item__conceptum__codicem)']
select = [
'(STRAFTER(STR(?item), "entity/") AS ?item__conceptum__codicem)']
# select = [
# '(STRAFTER(STR(?item), "entity/") AS ?item__conceptum__codicem)',
# '(STRAFTER(STR(?item), "entity/") AS ?item__rem__i_qcc__is_zxxx__ix_wikiq)'
# ]

filter_otional = []
for pair in self.D1613_1_51_langpair:
select.append('?' + pair[1])
Expand Down Expand Up @@ -479,23 +447,29 @@ def query_p_ex_interlinguis(self):
'(STRAFTER(STR(?item), "entity/") AS '
'?item__rem__i_qcc__is_zxxx__ix_wikiq)'
]
group_by = [
'?wikidata_p_value',
'?item'
]
filter_otional = []
# print('oiii', self.cum_interlinguis)
# cum_interlinguis = []
for item in self.cum_interlinguis:
# print('item')
select.append('?item__rem__i_qcc__is_zxxx__ix_wikip{0}'.format(
# (GROUP_CONCAT(?subdivisionLabel; separator = ", ") as ?subdivisionLabels)
# select.append('?item__rem__i_qcc__is_zxxx__ix_wikip{0}'.format(
select.append('(GROUP_CONCAT(DISTINCT ?p{0}_values; separator = "|") AS ?item__rem__i_qcc__is_zxxx__ix_wikip{0})'.format(
item
))
# OPTIONAL { ?item wdt:P6555 ?item__rem__i_qcc__is_zxxx__ix_wikip6555 . }
filter_otional.append(
'OPTIONAL { ?item wdt:P' + item +
' ?item__rem__i_qcc__is_zxxx__ix_wikip' + item + ' . }'
' ?p' + item + '_values . }'
)
filter_optional_done = [' ' + x for x in filter_otional]

term = """
SELECT {select} WHERE {{
SELECT DISTINCT {select} WHERE {{
{{
SELECT DISTINCT ?item WHERE {{
?item p:{wikidata_p} ?statement0.
Expand All @@ -505,11 +479,13 @@ def query_p_ex_interlinguis(self):
?item wdt:{wikidata_p} ?wikidata_p_value .
{optional_filters}
}}
GROUP BY {group_by}
ORDER BY ASC (?wikidata_p_value)
""".format(
wikidata_p=_pid,
qitems=" ".join(qid),
select=" ".join(select),
group_by=" ".join(group_by),
optional_filters="\n".join(filter_optional_done),
)

Expand Down
4 changes: 2 additions & 2 deletions officinam/999999999/999999_1679.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ ROOTDIR="$(pwd)"

#### tests _____________________________________________________________________

echo "--actionem-sparql --de=P --query --ex-interlinguis"
echo "--actionem-sparql --de=P --query --ex-interlinguis --cum-interlinguis=P402,P1566,P1937,P6555,P8119"
printf "P1585\n" | ./999999999/0/1603_3_12.py \
--actionem-sparql --de=P --query --ex-interlinguis \
--actionem-sparql --de=P --query --ex-interlinguis --cum-interlinguis=P402,P1566,P1937,P6555,P8119 \
| ./999999999/0/1603_3_12.py --actionem-sparql --csv --hxltm \
> 999999/0/P1585.tm.hxl.csv

Expand Down

0 comments on commit 36dff26

Please sign in to comment.