pyLodStorage 0.2.13__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.13/pylodstorage.egg-info → pylodstorage-0.3.0}/PKG-INFO +1 -1
  2. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/query.py +1 -1
  3. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/trulytabular.py +60 -14
  4. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/version.py +2 -2
  5. {pylodstorage-0.2.13 → pylodstorage-0.3.0/pylodstorage.egg-info}/PKG-INFO +1 -1
  6. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/LICENSE +0 -0
  7. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/README.md +0 -0
  8. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/__init__.py +0 -0
  9. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/csv.py +0 -0
  10. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/entity.py +0 -0
  11. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/jsonable.py +0 -0
  12. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/jsonpicklemixin.py +0 -0
  13. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/lod.py +0 -0
  14. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/mwTable.py +0 -0
  15. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/plot.py +0 -0
  16. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/querymain.py +0 -0
  17. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/sample.py +0 -0
  18. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/schema.py +0 -0
  19. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/sparql.py +0 -0
  20. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/sql.py +0 -0
  21. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/storageconfig.py +0 -0
  22. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/tabulateCounter.py +0 -0
  23. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/uml.py +0 -0
  24. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/xml.py +0 -0
  25. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/lodstorage/yamlablemixin.py +0 -0
  26. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/pylodstorage.egg-info/SOURCES.txt +0 -0
  27. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/pylodstorage.egg-info/dependency_links.txt +0 -0
  28. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/pylodstorage.egg-info/entry_points.txt +0 -0
  29. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/pylodstorage.egg-info/requires.txt +0 -0
  30. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/pylodstorage.egg-info/top_level.txt +0 -0
  31. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/sampledata/__init__.py +0 -0
  32. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/sampledata/endpoints.yaml +0 -0
  33. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/sampledata/formats.yaml +0 -0
  34. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/sampledata/queries.yaml +0 -0
  35. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/sampledata/scholia.yaml +0 -0
  36. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/sampledata/trulytabular.yaml +0 -0
  37. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/sampledata/wf.yaml +0 -0
  38. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/sampledata/wikidata.yaml +0 -0
  39. {pylodstorage-0.2.13 → pylodstorage-0.3.0}/setup.cfg +0 -0
  40. {pylodstorage-0.2.13 → 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.13
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
@@ -336,7 +336,7 @@ class Query(object):
336
336
  str: the "try it!" url for the given query
337
337
  '''
338
338
  # https://stackoverflow.com/a/9345102/1497139
339
- quoted=urllib.parse.quote(self.query)
339
+ quoted=urllib.parse.quote(str(self.query))
340
340
  quoted=f"#{quoted}"
341
341
  url=f"{baseurl}/{quoted}"
342
342
  return url
@@ -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
@@ -21,6 +23,8 @@ class Variable:
21
23
  convert the given potential variable name string to a valid
22
24
  variable name
23
25
 
26
+ see https://stackoverflow.com/a/3305731/1497139
27
+
24
28
  Args:
25
29
  varStr(str): the string to convert
26
30
 
@@ -366,39 +370,81 @@ WHERE
366
370
  return qm
367
371
  return None
368
372
 
369
-
370
-
371
- 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:
372
374
  '''
373
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
374
386
  '''
387
+ # The Wikidata item to generate the query for
375
388
  item=self.item
389
+ # the name of this script
376
390
  script=Path(__file__).name
377
- sparqlQuery=f"""
378
- # truly tabular query for
391
+ # the mode of generation
392
+ naiveText="naive" if naive else "aggregate"
393
+ # start with th preamble and PREFIX section
394
+ # select the item and it's label
395
+ sparqlQuery=f"""# truly tabular {naiveText} query for
379
396
  # {item.qid}:{item.qlabel}
380
- # generated by {script} on {self.isodate}
397
+ # generated by {script} version {Version.version} on {self.isodate}
381
398
  PREFIX wd: <http://www.wikidata.org/entity/>
382
399
  PREFIX wdt: <http://www.wikidata.org/prop/direct/>
383
400
  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
384
401
  SELECT ?{item.varname} ?{item.varname}Label"""
402
+ # loop over all properties
385
403
  for wdProp in self.properties.values():
386
- sparqlQuery+=f"\n ?{wdProp.varname}"
404
+ if naive:
405
+ sparqlQuery+=f"\n ?{wdProp.varname}"
406
+ else:
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"
387
420
  sparqlQuery+=f"""
388
421
  WHERE {{
389
422
  # instanceof {item.qid}:{item.qlabel}
390
423
  ?{item.varname} wdt:P31 wd:{item.qid}.
391
424
  # label
392
- ?{item.varname} rdfs:label ?{item.varname}Label
425
+ ?{item.varname} rdfs:label ?{item.varname}Label.
393
426
  FILTER (LANG(?{item.varname}Label) = "{lang}").
394
427
  """
395
- if naive:
396
- for wdProp in self.properties.values():
397
- sparqlQuery+=f""" # {wdProp}
398
- OPTIONAL {{ ?{item.varname} wdt:{wdProp.pid} ?{wdProp.varname}. }}
399
- """
400
- pass
428
+ for wdProp in self.properties.values():
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"
438
+ # close where Clause
401
439
  sparqlQuery+="""}\n"""
440
+ # optionally add Aggregate
441
+ if not naive:
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)"
402
448
  return sparqlQuery
403
449
 
404
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.13'
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.13
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