pyLodStorage 0.4.2__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.2/pylodstorage.egg-info → pylodstorage-0.4.4}/PKG-INFO +1 -1
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/query.py +1 -1
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/trulytabular.py +36 -19
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/version.py +2 -2
- {pylodstorage-0.4.2 → pylodstorage-0.4.4/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/LICENSE +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/README.md +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/csv.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/entity.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/lod.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/plot.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/querymain.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/sample.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/schema.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/sql.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/uml.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/xml.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/__init__.py +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/got.yaml +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/trulytabular.yaml +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/wikidata.yaml +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/setup.cfg +0 -0
- {pylodstorage-0.4.2 → pylodstorage-0.4.4}/setup.py +0 -0
|
@@ -530,7 +530,7 @@ class QueryManager(object):
|
|
|
530
530
|
@staticmethod
|
|
531
531
|
def getQueries(queriesPath=None):
|
|
532
532
|
'''
|
|
533
|
-
get the queries for
|
|
533
|
+
get the queries for the given queries Path
|
|
534
534
|
'''
|
|
535
535
|
queriesPaths=YamlPath.getPaths("queries.yaml", queriesPath)
|
|
536
536
|
queries={}
|
|
@@ -4,9 +4,12 @@ Created on 2022-04-14
|
|
|
4
4
|
@author: wf
|
|
5
5
|
'''
|
|
6
6
|
import datetime
|
|
7
|
+
from typing import Union
|
|
8
|
+
|
|
7
9
|
from lodstorage.sparql import SPARQL
|
|
8
10
|
from lodstorage.query import Query,QueryManager,YamlPath,Endpoint
|
|
9
11
|
from lodstorage.version import Version
|
|
12
|
+
import logging
|
|
10
13
|
from pathlib import Path
|
|
11
14
|
import os
|
|
12
15
|
import textwrap
|
|
@@ -141,6 +144,8 @@ SELECT ?property ?propertyLabel ?wbType WHERE {{
|
|
|
141
144
|
prop.url=url
|
|
142
145
|
wdProperties[prop.plabel]=prop
|
|
143
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}"
|
|
144
149
|
pass
|
|
145
150
|
return wdProperties
|
|
146
151
|
|
|
@@ -166,6 +171,8 @@ class WikidataItem:
|
|
|
166
171
|
if sparql is not None:
|
|
167
172
|
self.qlabel,self.description=WikidataItem.getLabelAndDescription(sparql, self.qid, self.lang)
|
|
168
173
|
self.varname=Variable.validVarName(self.qlabel)
|
|
174
|
+
self.itemVarname=f"{self.varname}Item"
|
|
175
|
+
self.labelVarname=f"{self.varname}"
|
|
169
176
|
|
|
170
177
|
def __str__(self):
|
|
171
178
|
return self.asText(long=False)
|
|
@@ -436,11 +443,11 @@ WHERE
|
|
|
436
443
|
# {item.qid}:{item.qlabel}
|
|
437
444
|
# generated by {script} version {Version.version} on {self.isodate}
|
|
438
445
|
{WikidataItem.getPrefixes()}
|
|
439
|
-
SELECT ?{item.
|
|
446
|
+
SELECT ?{item.itemVarname} ?{item.labelVarname}"""
|
|
440
447
|
# loop over all properties
|
|
441
448
|
for wdProp in self.properties.values():
|
|
442
449
|
if naive:
|
|
443
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
450
|
+
sparqlQuery+=f"\n ?{wdProp.valueVarname}"
|
|
444
451
|
else:
|
|
445
452
|
if wdProp.pid in genMap:
|
|
446
453
|
genList=genMap[wdProp.pid]
|
|
@@ -456,42 +463,44 @@ SELECT ?{item.varname} ?{item.varname}Label"""
|
|
|
456
463
|
distinct="DISTINCT "
|
|
457
464
|
aggregateFunc=aggregate.upper()
|
|
458
465
|
aggregateParam=""
|
|
459
|
-
sparqlQuery+=f"\n ({aggregateFunc} ({distinct}?{wdProp.
|
|
466
|
+
sparqlQuery+=f"\n ({aggregateFunc} ({distinct}?{wdProp.valueVarname}{aggregateParam}) AS ?{wdProp.valueVarname}_{aggregate})"
|
|
460
467
|
elif aggregate=="label":
|
|
461
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
462
|
-
elif aggregate=="ignore":
|
|
463
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
468
|
+
sparqlQuery+=f"\n ?{wdProp.labelVarname}"
|
|
469
|
+
elif aggregate=="ignore" and not "label" in genList:
|
|
470
|
+
sparqlQuery+=f"\n ?{wdProp.valueVarname}"
|
|
464
471
|
sparqlQuery+=f"""
|
|
465
472
|
WHERE {{
|
|
466
473
|
# instanceof {item.qid}:{item.qlabel}
|
|
467
|
-
?{item.
|
|
474
|
+
?{item.itemVarname} wdt:P31 wd:{item.qid}.
|
|
468
475
|
# label
|
|
469
|
-
?{item.
|
|
470
|
-
FILTER (LANG(?{item.
|
|
476
|
+
?{item.itemVarname} rdfs:label ?{item.labelVarname}.
|
|
477
|
+
FILTER (LANG(?{item.labelVarname}) = "{lang}").
|
|
471
478
|
"""
|
|
472
479
|
for wdProp in self.properties.values():
|
|
473
480
|
sparqlQuery+=f""" # {wdProp}
|
|
474
481
|
OPTIONAL {{
|
|
475
|
-
?{item.
|
|
482
|
+
?{item.itemVarname} wdt:{wdProp.pid} ?{wdProp.valueVarname}. """
|
|
476
483
|
if wdProp.pid in genMap:
|
|
477
484
|
genList=genMap[wdProp.pid]
|
|
478
485
|
if "label" in genList:
|
|
479
|
-
sparqlQuery+=f"""\n ?{wdProp.
|
|
480
|
-
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}")."""
|
|
481
488
|
sparqlQuery+="\n }\n"
|
|
482
489
|
# close where Clause
|
|
483
490
|
sparqlQuery+="""}\n"""
|
|
484
491
|
# optionally add Aggregate
|
|
485
492
|
if not naive:
|
|
486
493
|
sparqlQuery+=f"""GROUP BY
|
|
487
|
-
?{item.
|
|
488
|
-
?{item.
|
|
494
|
+
?{item.itemVarname}
|
|
495
|
+
?{item.labelVarname}
|
|
489
496
|
"""
|
|
490
497
|
for wdProp in self.properties.values():
|
|
491
498
|
if wdProp.pid in genMap:
|
|
492
499
|
genList=genMap[wdProp.pid]
|
|
493
500
|
if "label" in genList:
|
|
494
|
-
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}"
|
|
495
504
|
havingCount=0
|
|
496
505
|
havingDelim=" "
|
|
497
506
|
for wdProp in self.properties.values():
|
|
@@ -502,7 +511,7 @@ WHERE {{
|
|
|
502
511
|
if havingCount==1:
|
|
503
512
|
sparqlQuery+=f"\nHAVING ("
|
|
504
513
|
|
|
505
|
-
sparqlQuery+=f"\n {havingDelim}COUNT(?{wdProp.
|
|
514
|
+
sparqlQuery+=f"\n {havingDelim}COUNT(?{wdProp.valueVarname})<=1"
|
|
506
515
|
havingDelim="&& "
|
|
507
516
|
if havingCount>0:
|
|
508
517
|
sparqlQuery+=f"\n)"
|
|
@@ -618,16 +627,24 @@ ORDER BY DESC(?count)"""
|
|
|
618
627
|
'''
|
|
619
628
|
query=self.noneTabularQuery(wdProperty)
|
|
620
629
|
if self.debug:
|
|
621
|
-
|
|
630
|
+
logging.info(query.query)
|
|
622
631
|
qlod=self.sparql.queryAsListOfDicts(query.query)
|
|
623
632
|
return qlod
|
|
624
633
|
|
|
625
|
-
def addStatsColWithPercent(self,m,col,value,total):
|
|
634
|
+
def addStatsColWithPercent(self, m:dict, col:str, value:Union[int, float], total:Union[int, float]):
|
|
626
635
|
'''
|
|
627
636
|
add a statistics Column
|
|
637
|
+
Args:
|
|
638
|
+
m(dict):
|
|
639
|
+
col(str): name of the column
|
|
640
|
+
value: value
|
|
641
|
+
total: total value
|
|
628
642
|
'''
|
|
629
643
|
m[col]=value
|
|
630
|
-
|
|
644
|
+
if total > 0:
|
|
645
|
+
m[f"{col}%"]=float(f"{value/total*100:.1f}")
|
|
646
|
+
else:
|
|
647
|
+
m[f"{col}%"] = None
|
|
631
648
|
|
|
632
649
|
def genWdPropertyStatistic(self,wdProperty:WikidataProperty,itemCount:int,withQuery=True)->dict:
|
|
633
650
|
'''
|
|
@@ -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
|