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.
Files changed (41) hide show
  1. {pylodstorage-0.4.2/pylodstorage.egg-info → pylodstorage-0.4.4}/PKG-INFO +1 -1
  2. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/query.py +1 -1
  3. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/trulytabular.py +36 -19
  4. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/version.py +2 -2
  5. {pylodstorage-0.4.2 → pylodstorage-0.4.4/pylodstorage.egg-info}/PKG-INFO +1 -1
  6. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/LICENSE +0 -0
  7. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/README.md +0 -0
  8. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/__init__.py +0 -0
  9. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/csv.py +0 -0
  10. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/entity.py +0 -0
  11. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/jsonable.py +0 -0
  12. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/jsonpicklemixin.py +0 -0
  13. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/lod.py +0 -0
  14. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/mwTable.py +0 -0
  15. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/plot.py +0 -0
  16. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/querymain.py +0 -0
  17. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/sample.py +0 -0
  18. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/schema.py +0 -0
  19. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/sparql.py +0 -0
  20. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/sql.py +0 -0
  21. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/storageconfig.py +0 -0
  22. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/tabulateCounter.py +0 -0
  23. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/uml.py +0 -0
  24. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/xml.py +0 -0
  25. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/lodstorage/yamlablemixin.py +0 -0
  26. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/SOURCES.txt +0 -0
  27. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/dependency_links.txt +0 -0
  28. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/entry_points.txt +0 -0
  29. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/requires.txt +0 -0
  30. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/pylodstorage.egg-info/top_level.txt +0 -0
  31. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/__init__.py +0 -0
  32. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/endpoints.yaml +0 -0
  33. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/formats.yaml +0 -0
  34. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/got.yaml +0 -0
  35. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/queries.yaml +0 -0
  36. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/scholia.yaml +0 -0
  37. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/trulytabular.yaml +0 -0
  38. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/wf.yaml +0 -0
  39. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/sampledata/wikidata.yaml +0 -0
  40. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/setup.cfg +0 -0
  41. {pylodstorage-0.4.2 → pylodstorage-0.4.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -530,7 +530,7 @@ class QueryManager(object):
530
530
  @staticmethod
531
531
  def getQueries(queriesPath=None):
532
532
  '''
533
- get the queries for thee given queries Path
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.varname} ?{item.varname}Label"""
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.varname}"
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.varname}{aggregateParam}) AS ?{wdProp.varname}_{aggregate})"
466
+ sparqlQuery+=f"\n ({aggregateFunc} ({distinct}?{wdProp.valueVarname}{aggregateParam}) AS ?{wdProp.valueVarname}_{aggregate})"
460
467
  elif aggregate=="label":
461
- sparqlQuery+=f"\n ?{wdProp.varname}Label"
462
- elif aggregate=="ignore":
463
- sparqlQuery+=f"\n ?{wdProp.varname}"
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.varname} wdt:P31 wd:{item.qid}.
474
+ ?{item.itemVarname} wdt:P31 wd:{item.qid}.
468
475
  # label
469
- ?{item.varname} rdfs:label ?{item.varname}Label.
470
- FILTER (LANG(?{item.varname}Label) = "{lang}").
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.varname} wdt:{wdProp.pid} ?{wdProp.varname}. """
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.varname} rdfs:label ?{wdProp.varname}Label."""
480
- sparqlQuery+=f"""\n FILTER (LANG(?{wdProp.varname}Label) = "{lang}")."""
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.varname}
488
- ?{item.varname}Label
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.varname}Label"
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.varname})<=1"
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
- print(query.query)
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
- m[f"{col}%"]=float(f"{value/total*100:.1f}")
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.2'
12
+ version='0.4.4'
13
13
  date = '2020-09-10'
14
- updated = '2022-08-03'
14
+ updated = '2022-08-04'
15
15
  description='python List of Dict (Table) Storage library'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
File without changes
File without changes
File without changes
File without changes