pyLodStorage 0.2.14__tar.gz → 0.3.0__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 (40) hide show
  1. {pylodstorage-0.2.14/pylodstorage.egg-info → pylodstorage-0.3.0}/PKG-INFO +1 -1
  2. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/trulytabular.py +48 -8
  3. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/version.py +2 -2
  4. {pylodstorage-0.2.14 → pylodstorage-0.3.0/pylodstorage.egg-info}/PKG-INFO +1 -1
  5. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/LICENSE +0 -0
  6. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/README.md +0 -0
  7. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/__init__.py +0 -0
  8. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/csv.py +0 -0
  9. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/entity.py +0 -0
  10. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/jsonable.py +0 -0
  11. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/jsonpicklemixin.py +0 -0
  12. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/lod.py +0 -0
  13. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/mwTable.py +0 -0
  14. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/plot.py +0 -0
  15. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/query.py +0 -0
  16. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/querymain.py +0 -0
  17. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/sample.py +0 -0
  18. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/schema.py +0 -0
  19. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/sparql.py +0 -0
  20. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/sql.py +0 -0
  21. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/storageconfig.py +0 -0
  22. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/tabulateCounter.py +0 -0
  23. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/uml.py +0 -0
  24. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/xml.py +0 -0
  25. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/yamlablemixin.py +0 -0
  26. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/SOURCES.txt +0 -0
  27. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/dependency_links.txt +0 -0
  28. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/entry_points.txt +0 -0
  29. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/requires.txt +0 -0
  30. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/top_level.txt +0 -0
  31. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/__init__.py +0 -0
  32. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/endpoints.yaml +0 -0
  33. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/formats.yaml +0 -0
  34. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/queries.yaml +0 -0
  35. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/scholia.yaml +0 -0
  36. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/trulytabular.yaml +0 -0
  37. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/wf.yaml +0 -0
  38. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/wikidata.yaml +0 -0
  39. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/setup.cfg +0 -0
  40. {pylodstorage-0.2.14 → pylodstorage-0.3.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.2.14
3
+ Version: 0.3.0
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -6,11 +6,13 @@ Created on 2022-04-14
6
6
  import datetime
7
7
  from lodstorage.sparql import SPARQL
8
8
  from lodstorage.query import Query,QueryManager,YamlPath
9
+ from lodstorage.version import Version
9
10
  from pathlib import Path
10
11
  import os
11
12
  import textwrap
12
13
  import re
13
14
 
15
+
14
16
  class Variable:
15
17
  '''
16
18
  Variable e.g. name handling
@@ -368,43 +370,81 @@ WHERE
368
370
  return qm
369
371
  return None
370
372
 
371
-
372
- def generateSparqlQuery(self,lang:str='en',naive:bool=True)->str:
373
+ def generateSparqlQuery(self,genMap:dict,listSeparator:str="⇹",naive:bool=True,lang:str='en')->str:
373
374
  '''
374
375
  generate a SPARQL Query
376
+
377
+ Args:
378
+ genMap(dict): a dictionary of generation items aggregates/ignores/labels
379
+ listSeparator(str): the symbole to use as a list separator for GROUP_CONCAT
380
+ naive(bool): if True - generate a naive straight forward SPARQL query
381
+ if False generate a proper truly tabular aggregate query
382
+ lang(str): the language to generate for
383
+
384
+ Returns:
385
+ str: the generated SPARQL Query
375
386
  '''
387
+ # The Wikidata item to generate the query for
376
388
  item=self.item
389
+ # the name of this script
377
390
  script=Path(__file__).name
391
+ # the mode of generation
378
392
  naiveText="naive" if naive else "aggregate"
393
+ # start with th preamble and PREFIX section
394
+ # select the item and it's label
379
395
  sparqlQuery=f"""# truly tabular {naiveText} query for
380
396
  # {item.qid}:{item.qlabel}
381
- # generated by {script} on {self.isodate}
397
+ # generated by {script} version {Version.version} on {self.isodate}
382
398
  PREFIX wd: <http://www.wikidata.org/entity/>
383
399
  PREFIX wdt: <http://www.wikidata.org/prop/direct/>
384
400
  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
385
401
  SELECT ?{item.varname} ?{item.varname}Label"""
402
+ # loop over all properties
386
403
  for wdProp in self.properties.values():
387
404
  if naive:
388
405
  sparqlQuery+=f"\n ?{wdProp.varname}"
389
406
  else:
390
- sparqlQuery+=f"\n (SAMPLE (?{wdProp.varname}) AS ?{wdProp.varname})"
407
+ if wdProp.pid in genMap:
408
+ genList=genMap[wdProp.pid]
409
+ for aggregate in genList:
410
+ if not aggregate in ["ignore","label"]:
411
+ if aggregate=="list":
412
+ aggregateFunc="GROUP_CONCAT"
413
+ aggregateParam=f';SEPARATOR="{listSeparator}"'
414
+ else:
415
+ aggregateFunc=aggregate.upper()
416
+ aggregateParam=""
417
+ sparqlQuery+=f"\n ({aggregateFunc} (?{wdProp.varname}{aggregateParam}) AS ?{wdProp.varname}_{aggregate})"
418
+ elif aggregate=="label":
419
+ sparqlQuery+=f"\n ?{wdProp.varname}Label"
391
420
  sparqlQuery+=f"""
392
421
  WHERE {{
393
422
  # instanceof {item.qid}:{item.qlabel}
394
423
  ?{item.varname} wdt:P31 wd:{item.qid}.
395
424
  # label
396
- ?{item.varname} rdfs:label ?{item.varname}Label
425
+ ?{item.varname} rdfs:label ?{item.varname}Label.
397
426
  FILTER (LANG(?{item.varname}Label) = "{lang}").
398
427
  """
399
428
  for wdProp in self.properties.values():
400
- sparqlQuery+=f""" # {wdProp}
401
- OPTIONAL {{ ?{item.varname} wdt:{wdProp.pid} ?{wdProp.varname}. }}
402
- """
429
+ sparqlQuery+=f""" # {wdProp}
430
+ OPTIONAL {{
431
+ ?{item.varname} wdt:{wdProp.pid} ?{wdProp.varname}. """
432
+ if wdProp.pid in genMap:
433
+ genList=genMap[wdProp.pid]
434
+ if "label" in genList:
435
+ sparqlQuery+=f"""\n ?{wdProp.varname} rdfs:label ?{wdProp.varname}Label."""
436
+ sparqlQuery+=f"""\n FILTER (LANG(?{wdProp.varname}Label) = "{lang}")."""
437
+ sparqlQuery+="\n }\n"
403
438
  # close where Clause
404
439
  sparqlQuery+="""}\n"""
405
440
  # optionally add Aggregate
406
441
  if not naive:
407
442
  sparqlQuery+=f"GROUP BY ?{item.varname} ?{item.varname}Label"
443
+ for wdProp in self.properties.values():
444
+ if wdProp.pid in genMap:
445
+ genList=genMap[wdProp.pid]
446
+ if "ignore" in genList:
447
+ sparqlQuery+=f"\nHAVING (COUNT(?{wdProp.varname})=1)"
408
448
  return sparqlQuery
409
449
 
410
450
  def mostFrequentPropertiesQuery(self,whereClause:str=None):
@@ -9,7 +9,7 @@ class Version(object):
9
9
  Version handling for pyLoDStorage
10
10
  '''
11
11
  name="pylodstorage"
12
- version='0.2.14'
12
+ version='0.3.0'
13
13
  date = '2020-09-10'
14
- updated = '2022-07-27'
14
+ updated = '2022-07-28'
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.2.14
3
+ Version: 0.3.0
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