pyLodStorage 0.0.83__tar.gz → 0.0.85__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.0.83/pylodstorage.egg-info → pylodstorage-0.0.85}/PKG-INFO +1 -1
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/query.py +52 -5
- {pylodstorage-0.0.83 → pylodstorage-0.0.85/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/pylodstorage.egg-info/requires.txt +2 -1
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/setup.py +2 -2
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/LICENSE +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/README.md +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/csv.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/entity.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/lod.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/plot.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/sample.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/schema.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/sql.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/uml.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.0.83 → pylodstorage-0.0.85}/setup.cfg +0 -0
|
@@ -7,11 +7,13 @@ import os
|
|
|
7
7
|
import yaml
|
|
8
8
|
from tabulate import tabulate
|
|
9
9
|
import urllib
|
|
10
|
+
import copy
|
|
10
11
|
#from wikibot.mwTable import MediaWikiTable
|
|
11
12
|
# redundant copy in this library to avoid dependency issues
|
|
12
13
|
# original is at
|
|
13
14
|
from lodstorage.mwTable import MediaWikiTable
|
|
14
15
|
from pylatexenc.latexencode import unicode_to_latex
|
|
16
|
+
import re
|
|
15
17
|
|
|
16
18
|
class QueryResultDocumentation():
|
|
17
19
|
'''
|
|
@@ -42,6 +44,7 @@ class QueryResultDocumentation():
|
|
|
42
44
|
self.resultHeader=resultHeader
|
|
43
45
|
self.result=result
|
|
44
46
|
|
|
47
|
+
|
|
45
48
|
@staticmethod
|
|
46
49
|
def uniCode2Latex(text:str)->str:
|
|
47
50
|
'''
|
|
@@ -59,7 +62,27 @@ class QueryResultDocumentation():
|
|
|
59
62
|
'''
|
|
60
63
|
for code in range(8320,8330):
|
|
61
64
|
text=text.replace(chr(code),f"$_{code-8320}$")
|
|
62
|
-
return unicode_to_latex(text)
|
|
65
|
+
return unicode_to_latex(text)
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
def wikiDataLink(record,key,value,tablefmt):
|
|
69
|
+
'''
|
|
70
|
+
replace wikiData Link with tablefmt specific link
|
|
71
|
+
'''
|
|
72
|
+
if isinstance(value,str):
|
|
73
|
+
wid=None
|
|
74
|
+
# "pure" Wikidata Q ID
|
|
75
|
+
if re.match(r"(Q|Property:P)[0-9]+",value):
|
|
76
|
+
wid=value
|
|
77
|
+
else:
|
|
78
|
+
match=re.match(r"http(s)?://.*/((Q|Property:P)[0-9]+)",value)
|
|
79
|
+
if match:
|
|
80
|
+
wid=match.group(2)
|
|
81
|
+
if wid is not None:
|
|
82
|
+
if tablefmt=="github":
|
|
83
|
+
record[key]=f"[{wid}](https://www.wikidata.org/wiki/{wid})"
|
|
84
|
+
elif tablefmt=="mediawiki":
|
|
85
|
+
record[key]=f"[https://www.wikidata.org/wiki/{wid} {wid}]"
|
|
63
86
|
|
|
64
87
|
def __str__(self):
|
|
65
88
|
'''
|
|
@@ -100,6 +123,26 @@ class Query(object):
|
|
|
100
123
|
self.description="" if description is None else description
|
|
101
124
|
self.prefixes=prefixes
|
|
102
125
|
self.debug=debug
|
|
126
|
+
self.formatCallBacks=[]
|
|
127
|
+
|
|
128
|
+
def addFormatCallBack(self,callback):
|
|
129
|
+
self.formatCallBacks.append(callback)
|
|
130
|
+
|
|
131
|
+
def preFormatWithCallBacks(self,lod,tablefmt:str):
|
|
132
|
+
'''
|
|
133
|
+
run the configured call backs to pre-format the given list of dicts for the given tableformat
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
lod(list): the list of dicts to handle
|
|
137
|
+
tablefmt(str): the table format (according to tabulate) to apply
|
|
138
|
+
|
|
139
|
+
'''
|
|
140
|
+
for record in lod:
|
|
141
|
+
for key in record.keys():
|
|
142
|
+
value=record[key]
|
|
143
|
+
if value is not None:
|
|
144
|
+
for formatCallBack in self.formatCallBacks:
|
|
145
|
+
formatCallBack(record,key,value,tablefmt)
|
|
103
146
|
|
|
104
147
|
def getTryItUrl(self,baseurl:str):
|
|
105
148
|
'''
|
|
@@ -140,6 +183,7 @@ class Query(object):
|
|
|
140
183
|
def prefixToLink(self,lod:list,prefix:str,tablefmt:str):
|
|
141
184
|
'''
|
|
142
185
|
convert url prefixes to link according to the given table format
|
|
186
|
+
TODO - refactor as preFormat callback
|
|
143
187
|
|
|
144
188
|
Args:
|
|
145
189
|
lod(list): the list of dicts to convert
|
|
@@ -188,12 +232,12 @@ class Query(object):
|
|
|
188
232
|
markup=mwTable.asWikiMarkup()
|
|
189
233
|
return markup
|
|
190
234
|
|
|
191
|
-
def documentQueryResult(self,
|
|
235
|
+
def documentQueryResult(self,qlod:list,limit=None,tablefmt:str="mediawiki",tryItUrl:str=None,withSourceCode=True,**kwArgs):
|
|
192
236
|
'''
|
|
193
|
-
document the given query results
|
|
237
|
+
document the given query results - note that a copy of the whole list is going to be created for being able to format
|
|
194
238
|
|
|
195
239
|
Args:
|
|
196
|
-
|
|
240
|
+
qlod: the list of dicts result
|
|
197
241
|
limit(int): the maximum number of records to display in result tabulate
|
|
198
242
|
tablefmt(str): the table format to use
|
|
199
243
|
tryItUrl: the "try it!" url to show
|
|
@@ -205,7 +249,10 @@ class Query(object):
|
|
|
205
249
|
sourceCode=self.query
|
|
206
250
|
title=self.title
|
|
207
251
|
if limit is not None:
|
|
208
|
-
lod=
|
|
252
|
+
lod=copy.deepcopy(qlod[:limit])
|
|
253
|
+
else:
|
|
254
|
+
lod=copy.deepcopy(qlod)
|
|
255
|
+
self.preFormatWithCallBacks(lod,tablefmt=tablefmt)
|
|
209
256
|
result=tabulate(lod,headers="keys",tablefmt=tablefmt,**kwArgs)
|
|
210
257
|
if tryItUrl is None and hasattr(self,'tryItUrl'):
|
|
211
258
|
tryItUrl=self.tryItUrl
|
|
@@ -11,7 +11,7 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
|
|
|
11
11
|
|
|
12
12
|
setup(
|
|
13
13
|
name='pylodstorage',
|
|
14
|
-
version='0.0.
|
|
14
|
+
version='0.0.85',
|
|
15
15
|
|
|
16
16
|
packages=['lodstorage',],
|
|
17
17
|
author='Wolfgang Fahl',
|
|
@@ -32,7 +32,7 @@ setup(
|
|
|
32
32
|
'PyYAML',
|
|
33
33
|
'pandas',
|
|
34
34
|
'jsonpickle',
|
|
35
|
-
'tabulate'
|
|
35
|
+
'tabulate',
|
|
36
36
|
'pylatexenc~=2.10'
|
|
37
37
|
],
|
|
38
38
|
classifiers=[
|
|
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
|