pyLodStorage 0.4.3__tar.gz → 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pylodstorage-0.4.3/pylodstorage.egg-info → pylodstorage-0.4.4}/PKG-INFO +1 -1
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/trulytabular.py +23 -16
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/version.py +2 -2
- {pylodstorage-0.4.3 → pylodstorage-0.4.4/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/LICENSE +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/README.md +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/csv.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/entity.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/lod.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/plot.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/query.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/querymain.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/sample.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/schema.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/sql.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/uml.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/xml.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/__init__.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/got.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/trulytabular.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/sampledata/wikidata.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/setup.cfg +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.4}/setup.py +0 -0
|
@@ -9,6 +9,7 @@ from typing import Union
|
|
|
9
9
|
from lodstorage.sparql import SPARQL
|
|
10
10
|
from lodstorage.query import Query,QueryManager,YamlPath,Endpoint
|
|
11
11
|
from lodstorage.version import Version
|
|
12
|
+
import logging
|
|
12
13
|
from pathlib import Path
|
|
13
14
|
import os
|
|
14
15
|
import textwrap
|
|
@@ -143,6 +144,8 @@ SELECT ?property ?propertyLabel ?wbType WHERE {{
|
|
|
143
144
|
prop.url=url
|
|
144
145
|
wdProperties[prop.plabel]=prop
|
|
145
146
|
prop.varname=Variable.validVarName(prop.plabel)
|
|
147
|
+
prop.valueVarname=f"{prop.varname}Item" if "WikibaseItem" in prop.wbtype else "" f"{prop.varname}"
|
|
148
|
+
prop.labelVarname=f"{prop.varname}"
|
|
146
149
|
pass
|
|
147
150
|
return wdProperties
|
|
148
151
|
|
|
@@ -168,6 +171,8 @@ class WikidataItem:
|
|
|
168
171
|
if sparql is not None:
|
|
169
172
|
self.qlabel,self.description=WikidataItem.getLabelAndDescription(sparql, self.qid, self.lang)
|
|
170
173
|
self.varname=Variable.validVarName(self.qlabel)
|
|
174
|
+
self.itemVarname=f"{self.varname}Item"
|
|
175
|
+
self.labelVarname=f"{self.varname}"
|
|
171
176
|
|
|
172
177
|
def __str__(self):
|
|
173
178
|
return self.asText(long=False)
|
|
@@ -438,11 +443,11 @@ WHERE
|
|
|
438
443
|
# {item.qid}:{item.qlabel}
|
|
439
444
|
# generated by {script} version {Version.version} on {self.isodate}
|
|
440
445
|
{WikidataItem.getPrefixes()}
|
|
441
|
-
SELECT ?{item.
|
|
446
|
+
SELECT ?{item.itemVarname} ?{item.labelVarname}"""
|
|
442
447
|
# loop over all properties
|
|
443
448
|
for wdProp in self.properties.values():
|
|
444
449
|
if naive:
|
|
445
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
450
|
+
sparqlQuery+=f"\n ?{wdProp.valueVarname}"
|
|
446
451
|
else:
|
|
447
452
|
if wdProp.pid in genMap:
|
|
448
453
|
genList=genMap[wdProp.pid]
|
|
@@ -458,42 +463,44 @@ SELECT ?{item.varname} ?{item.varname}Label"""
|
|
|
458
463
|
distinct="DISTINCT "
|
|
459
464
|
aggregateFunc=aggregate.upper()
|
|
460
465
|
aggregateParam=""
|
|
461
|
-
sparqlQuery+=f"\n ({aggregateFunc} ({distinct}?{wdProp.
|
|
466
|
+
sparqlQuery+=f"\n ({aggregateFunc} ({distinct}?{wdProp.valueVarname}{aggregateParam}) AS ?{wdProp.valueVarname}_{aggregate})"
|
|
462
467
|
elif aggregate=="label":
|
|
463
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
468
|
+
sparqlQuery+=f"\n ?{wdProp.labelVarname}"
|
|
464
469
|
elif aggregate=="ignore" and not "label" in genList:
|
|
465
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
470
|
+
sparqlQuery+=f"\n ?{wdProp.valueVarname}"
|
|
466
471
|
sparqlQuery+=f"""
|
|
467
472
|
WHERE {{
|
|
468
473
|
# instanceof {item.qid}:{item.qlabel}
|
|
469
|
-
?{item.
|
|
474
|
+
?{item.itemVarname} wdt:P31 wd:{item.qid}.
|
|
470
475
|
# label
|
|
471
|
-
?{item.
|
|
472
|
-
FILTER (LANG(?{item.
|
|
476
|
+
?{item.itemVarname} rdfs:label ?{item.labelVarname}.
|
|
477
|
+
FILTER (LANG(?{item.labelVarname}) = "{lang}").
|
|
473
478
|
"""
|
|
474
479
|
for wdProp in self.properties.values():
|
|
475
480
|
sparqlQuery+=f""" # {wdProp}
|
|
476
481
|
OPTIONAL {{
|
|
477
|
-
?{item.
|
|
482
|
+
?{item.itemVarname} wdt:{wdProp.pid} ?{wdProp.valueVarname}. """
|
|
478
483
|
if wdProp.pid in genMap:
|
|
479
484
|
genList=genMap[wdProp.pid]
|
|
480
485
|
if "label" in genList:
|
|
481
|
-
sparqlQuery+=f"""\n ?{wdProp.
|
|
482
|
-
sparqlQuery+=f"""\n FILTER (LANG(?{wdProp.
|
|
486
|
+
sparqlQuery+=f"""\n ?{wdProp.valueVarname} rdfs:label ?{wdProp.labelVarname}."""
|
|
487
|
+
sparqlQuery+=f"""\n FILTER (LANG(?{wdProp.labelVarname}) = "{lang}")."""
|
|
483
488
|
sparqlQuery+="\n }\n"
|
|
484
489
|
# close where Clause
|
|
485
490
|
sparqlQuery+="""}\n"""
|
|
486
491
|
# optionally add Aggregate
|
|
487
492
|
if not naive:
|
|
488
493
|
sparqlQuery+=f"""GROUP BY
|
|
489
|
-
?{item.
|
|
490
|
-
?{item.
|
|
494
|
+
?{item.itemVarname}
|
|
495
|
+
?{item.labelVarname}
|
|
491
496
|
"""
|
|
492
497
|
for wdProp in self.properties.values():
|
|
493
498
|
if wdProp.pid in genMap:
|
|
494
499
|
genList=genMap[wdProp.pid]
|
|
495
500
|
if "label" in genList:
|
|
496
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
501
|
+
sparqlQuery+=f"\n ?{wdProp.labelVarname}"
|
|
502
|
+
if "ignore" in genList and not "label" in genList:
|
|
503
|
+
sparqlQuery+=f"\n ?{wdProp.valueVarname}"
|
|
497
504
|
havingCount=0
|
|
498
505
|
havingDelim=" "
|
|
499
506
|
for wdProp in self.properties.values():
|
|
@@ -504,7 +511,7 @@ WHERE {{
|
|
|
504
511
|
if havingCount==1:
|
|
505
512
|
sparqlQuery+=f"\nHAVING ("
|
|
506
513
|
|
|
507
|
-
sparqlQuery+=f"\n {havingDelim}COUNT(?{wdProp.
|
|
514
|
+
sparqlQuery+=f"\n {havingDelim}COUNT(?{wdProp.valueVarname})<=1"
|
|
508
515
|
havingDelim="&& "
|
|
509
516
|
if havingCount>0:
|
|
510
517
|
sparqlQuery+=f"\n)"
|
|
@@ -620,7 +627,7 @@ ORDER BY DESC(?count)"""
|
|
|
620
627
|
'''
|
|
621
628
|
query=self.noneTabularQuery(wdProperty)
|
|
622
629
|
if self.debug:
|
|
623
|
-
|
|
630
|
+
logging.info(query.query)
|
|
624
631
|
qlod=self.sparql.queryAsListOfDicts(query.query)
|
|
625
632
|
return qlod
|
|
626
633
|
|
|
@@ -9,7 +9,7 @@ class Version(object):
|
|
|
9
9
|
Version handling for pyLoDStorage
|
|
10
10
|
'''
|
|
11
11
|
name="pylodstorage"
|
|
12
|
-
version='0.4.
|
|
12
|
+
version='0.4.4'
|
|
13
13
|
date = '2020-09-10'
|
|
14
|
-
updated = '2022-08-
|
|
14
|
+
updated = '2022-08-04'
|
|
15
15
|
description='python List of Dict (Table) Storage library'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|