pyLodStorage 0.2.12__tar.gz → 0.2.13__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.12/pylodstorage.egg-info → pylodstorage-0.2.13}/PKG-INFO +1 -1
  2. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/trulytabular.py +67 -8
  3. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/version.py +1 -1
  4. {pylodstorage-0.2.12 → pylodstorage-0.2.13/pylodstorage.egg-info}/PKG-INFO +1 -1
  5. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/LICENSE +0 -0
  6. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/README.md +0 -0
  7. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/__init__.py +0 -0
  8. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/csv.py +0 -0
  9. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/entity.py +0 -0
  10. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/jsonable.py +0 -0
  11. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/jsonpicklemixin.py +0 -0
  12. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/lod.py +0 -0
  13. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/mwTable.py +0 -0
  14. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/plot.py +0 -0
  15. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/query.py +0 -0
  16. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/querymain.py +0 -0
  17. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/sample.py +0 -0
  18. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/schema.py +0 -0
  19. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/sparql.py +0 -0
  20. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/sql.py +0 -0
  21. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/storageconfig.py +0 -0
  22. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/tabulateCounter.py +0 -0
  23. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/uml.py +0 -0
  24. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/xml.py +0 -0
  25. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/lodstorage/yamlablemixin.py +0 -0
  26. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/pylodstorage.egg-info/SOURCES.txt +0 -0
  27. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/pylodstorage.egg-info/dependency_links.txt +0 -0
  28. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/pylodstorage.egg-info/entry_points.txt +0 -0
  29. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/pylodstorage.egg-info/requires.txt +0 -0
  30. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/pylodstorage.egg-info/top_level.txt +0 -0
  31. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/sampledata/__init__.py +0 -0
  32. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/sampledata/endpoints.yaml +0 -0
  33. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/sampledata/formats.yaml +0 -0
  34. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/sampledata/queries.yaml +0 -0
  35. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/sampledata/scholia.yaml +0 -0
  36. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/sampledata/trulytabular.yaml +0 -0
  37. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/sampledata/wf.yaml +0 -0
  38. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/sampledata/wikidata.yaml +0 -0
  39. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/setup.cfg +0 -0
  40. {pylodstorage-0.2.12 → pylodstorage-0.2.13}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.2.12
3
+ Version: 0.2.13
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -3,12 +3,32 @@ Created on 2022-04-14
3
3
 
4
4
  @author: wf
5
5
  '''
6
+ import datetime
6
7
  from lodstorage.sparql import SPARQL
7
8
  from lodstorage.query import Query,QueryManager,YamlPath
9
+ from pathlib import Path
8
10
  import os
9
11
  import textwrap
10
12
  import re
11
13
 
14
+ class Variable:
15
+ '''
16
+ Variable e.g. name handling
17
+ '''
18
+ @classmethod
19
+ def validVarName(cls,varStr:str)->str:
20
+ '''
21
+ convert the given potential variable name string to a valid
22
+ variable name
23
+
24
+ Args:
25
+ varStr(str): the string to convert
26
+
27
+ Returns:
28
+ str: a valid variable name
29
+ '''
30
+ return re.sub('\W|^(?=\d)','_', varStr)
31
+
12
32
  class WikidataProperty():
13
33
  '''
14
34
  a WikidataProperty
@@ -29,13 +49,13 @@ class WikidataProperty():
29
49
  get me as a Predicate
30
50
  '''
31
51
  reverseToken="^" if self.reverse else ""
32
- pLabel=f"{reverseToken}wdt:{self.pid}"
33
- return pLabel
52
+ plabel=f"{reverseToken}wdt:{self.pid}"
53
+ return plabel
34
54
 
35
55
  def __str__(self):
36
56
  text=self.pid
37
- if hasattr(self, "label"):
38
- text=f"{self.label} ({self.pid})"
57
+ if hasattr(self, "plabel"):
58
+ text=f"{self.plabel} ({self.pid})"
39
59
  return text
40
60
 
41
61
  @classmethod
@@ -115,9 +135,10 @@ SELECT ?property ?propertyLabel WHERE {
115
135
  url=record["property"]
116
136
  pid=re.sub(r"http://www.wikidata.org/entity/(.*)",r"\1",url)
117
137
  prop=WikidataProperty(pid)
118
- prop.pLabel=record["propertyLabel"]
138
+ prop.plabel=record["propertyLabel"]
119
139
  prop.url=url
120
- wdProperties[prop.pLabel]=prop
140
+ wdProperties[prop.plabel]=prop
141
+ prop.varname=Variable.validVarName(prop.plabel)
121
142
  pass
122
143
  return wdProperties
123
144
 
@@ -140,6 +161,7 @@ class WikidataItem:
140
161
  self.sparql=sparql
141
162
  if sparql is not None:
142
163
  self.qlabel,self.description=WikidataItem.getLabelAndDescription(sparql, self.qid, self.lang)
164
+ self.varname=Variable.validVarName(self.qlabel)
143
165
 
144
166
  def __str__(self):
145
167
  return self.asText(long=False)
@@ -238,6 +260,7 @@ WHERE {
238
260
  item=WikidataItem(qid)
239
261
  item.url=url
240
262
  item.qlabel=record["itemLabel"]
263
+ item.varname=Variable.validVarName(item.qlabel)
241
264
  item.description=record["itemDescription"]
242
265
  items.append(item)
243
266
  return items
@@ -274,6 +297,7 @@ class TrulyTabular(object):
274
297
  self.queryManager=TrulyTabular.getQueryManager(debug=self.debug)
275
298
  self.properties=WikidataProperty.getPropertiesByIds(self.sparql,propertyIds,lang)
276
299
  self.properties.update(WikidataProperty.getPropertiesByLabels(self.sparql, propertyLabels, lang))
300
+ self.isodate=datetime.datetime.now().isoformat()
277
301
  self.error=None
278
302
 
279
303
  def __str__(self):
@@ -342,6 +366,41 @@ WHERE
342
366
  return qm
343
367
  return None
344
368
 
369
+
370
+
371
+ def generateSparqlQuery(self,lang:str='en',naive:bool=True)->str:
372
+ '''
373
+ generate a SPARQL Query
374
+ '''
375
+ item=self.item
376
+ script=Path(__file__).name
377
+ sparqlQuery=f"""
378
+ # truly tabular query for
379
+ # {item.qid}:{item.qlabel}
380
+ # generated by {script} on {self.isodate}
381
+ PREFIX wd: <http://www.wikidata.org/entity/>
382
+ PREFIX wdt: <http://www.wikidata.org/prop/direct/>
383
+ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
384
+ SELECT ?{item.varname} ?{item.varname}Label"""
385
+ for wdProp in self.properties.values():
386
+ sparqlQuery+=f"\n ?{wdProp.varname}"
387
+ sparqlQuery+=f"""
388
+ WHERE {{
389
+ # instanceof {item.qid}:{item.qlabel}
390
+ ?{item.varname} wdt:P31 wd:{item.qid}.
391
+ # label
392
+ ?{item.varname} rdfs:label ?{item.varname}Label
393
+ FILTER (LANG(?{item.varname}Label) = "{lang}").
394
+ """
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
401
+ sparqlQuery+="""}\n"""
402
+ return sparqlQuery
403
+
345
404
  def mostFrequentPropertiesQuery(self,whereClause:str=None):
346
405
  '''
347
406
  get the most frequently used properties
@@ -367,7 +426,7 @@ WHERE
367
426
  wdProperty(WikidataProperty): the property to analyze
368
427
  asFrequency(bool): if true do a frequency analysis
369
428
  '''
370
- propertyLabel=wdProperty.pLabel
429
+ propertyLabel=wdProperty.plabel
371
430
  propertyId=wdProperty.pid
372
431
  # work around https://github.com/RDFLib/sparqlwrapper/issues/211
373
432
  if "described at" in propertyLabel:
@@ -436,7 +495,7 @@ ORDER BY DESC(?count)"""
436
495
  dict: a statistics row
437
496
  '''
438
497
  ntlod=self.noneTabular(wdProperty)
439
- statsRow={"property":wdProperty.pLabel}
498
+ statsRow={"property":wdProperty.plabel}
440
499
  total=0
441
500
  nttotal=0
442
501
  maxCount=0
@@ -9,7 +9,7 @@ class Version(object):
9
9
  Version handling for pyLoDStorage
10
10
  '''
11
11
  name="pylodstorage"
12
- version='0.2.12'
12
+ version='0.2.13'
13
13
  date = '2020-09-10'
14
14
  updated = '2022-07-27'
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.12
3
+ Version: 0.2.13
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