pyLodStorage 0.0.80__tar.gz → 0.0.82__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.80/pylodstorage.egg-info → pylodstorage-0.0.82}/PKG-INFO +1 -1
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/query.py +44 -7
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/sql.py +19 -4
- {pylodstorage-0.0.80 → pylodstorage-0.0.82/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/setup.py +1 -1
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/LICENSE +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/README.md +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/csv.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/entity.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/lod.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/plot.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/sample.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/schema.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/uml.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.0.80 → pylodstorage-0.0.82}/setup.cfg +0 -0
|
@@ -11,20 +11,21 @@ import urllib
|
|
|
11
11
|
# redundant copy in this library to avoid dependency issues
|
|
12
12
|
# original is at
|
|
13
13
|
from lodstorage.mwTable import MediaWikiTable
|
|
14
|
-
|
|
14
|
+
from pylatexenc.latexencode import unicode_to_latex
|
|
15
15
|
|
|
16
16
|
class QueryResultDocumentation():
|
|
17
17
|
'''
|
|
18
18
|
documentation of a query result
|
|
19
19
|
'''
|
|
20
20
|
|
|
21
|
-
def __init__(self,query,title:str,tryItMarkup:str,sourceCodeHeader:str,sourceCode:str,resultHeader:str,result:str):
|
|
21
|
+
def __init__(self,query,title:str,tablefmt:str,tryItMarkup:str,sourceCodeHeader:str,sourceCode:str,resultHeader:str,result:str):
|
|
22
22
|
'''
|
|
23
23
|
constructor
|
|
24
24
|
|
|
25
25
|
Args:
|
|
26
26
|
query(Query): the query to be documented
|
|
27
27
|
title(str): the title markup
|
|
28
|
+
tablefmt(str): the tableformat that has been used
|
|
28
29
|
tryItMarkup: the "try it!" markup to show
|
|
29
30
|
sourceCodeHeader(str): the header title to use for the sourceCode
|
|
30
31
|
sourceCode(str): the sourceCode
|
|
@@ -34,24 +35,53 @@ class QueryResultDocumentation():
|
|
|
34
35
|
'''
|
|
35
36
|
self.query=query
|
|
36
37
|
self.title=title
|
|
38
|
+
self.tablefmt=tablefmt
|
|
37
39
|
self.tryItMarkup=f"\n{tryItMarkup}"
|
|
38
40
|
self.sourceCodeHeader=sourceCodeHeader
|
|
39
41
|
self.sourceCode=sourceCode
|
|
40
42
|
self.resultHeader=resultHeader
|
|
41
43
|
self.result=result
|
|
42
44
|
|
|
45
|
+
@staticmethod
|
|
46
|
+
def uniCode2Latex(text:str)->str:
|
|
47
|
+
'''
|
|
48
|
+
converts unicode text to latex and
|
|
49
|
+
fixes UTF-8 chars for latex in a certain range:
|
|
50
|
+
₀:$_0$ ... ₉:$_9$
|
|
51
|
+
|
|
52
|
+
see https://github.com/phfaist/pylatexenc/issues/72
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
text(str): the string to fix
|
|
56
|
+
|
|
57
|
+
Return:
|
|
58
|
+
str: latex presentation of UTF-8 char
|
|
59
|
+
'''
|
|
60
|
+
for code in range(8320,8330):
|
|
61
|
+
text=text.replace(chr(code),f"$_{code-8320}$")
|
|
62
|
+
return unicode_to_latex(text)
|
|
43
63
|
|
|
44
64
|
def __str__(self):
|
|
45
65
|
'''
|
|
46
66
|
simple string representation
|
|
47
67
|
'''
|
|
68
|
+
return self.asText()
|
|
69
|
+
|
|
70
|
+
def asText(self):
|
|
71
|
+
'''
|
|
72
|
+
return my text representation
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
str: description, sourceCodeHeader, sourceCode, tryIt link and result table
|
|
76
|
+
'''
|
|
48
77
|
text=f"{self.title}\n{self.query.description}\n{self.sourceCodeHeader}\n{self.sourceCode}{self.tryItMarkup}\n{self.resultHeader}\n{self.result}"
|
|
49
|
-
|
|
78
|
+
fixedStr=self.uniCode2Latex(text) if self.tablefmt.lower()=="latex" else text
|
|
79
|
+
return fixedStr
|
|
50
80
|
|
|
51
81
|
class Query(object):
|
|
52
82
|
''' a Query e.g. for SPAQRL '''
|
|
53
83
|
|
|
54
|
-
def __init__(self,name:str,query:str,lang='sparql',title:str=None,description:str=None,debug=False):
|
|
84
|
+
def __init__(self,name:str,query:str,lang='sparql',title:str=None,description:str=None,prefixes=None,debug=False):
|
|
55
85
|
'''
|
|
56
86
|
constructor
|
|
57
87
|
Args:
|
|
@@ -60,6 +90,7 @@ class Query(object):
|
|
|
60
90
|
lang(string): the language of the query e.g. SPARQL
|
|
61
91
|
title(string): the header/title of the query
|
|
62
92
|
description(string): the description of the query
|
|
93
|
+
prefixes(list): list of prefixes to be resolved
|
|
63
94
|
debug(boolean): true if debug mode should be switched on
|
|
64
95
|
'''
|
|
65
96
|
self.name=name
|
|
@@ -67,6 +98,7 @@ class Query(object):
|
|
|
67
98
|
self.lang=lang
|
|
68
99
|
self.title=title=name if title is None else title
|
|
69
100
|
self.description="" if description is None else description
|
|
101
|
+
self.prefixes=prefixes
|
|
70
102
|
self.debug=debug
|
|
71
103
|
|
|
72
104
|
def getTryItUrl(self,baseurl:str):
|
|
@@ -156,14 +188,15 @@ class Query(object):
|
|
|
156
188
|
markup=mwTable.asWikiMarkup()
|
|
157
189
|
return markup
|
|
158
190
|
|
|
159
|
-
def documentQueryResult(self,lod:list,tablefmt:str="mediawiki",tryItUrl:str=None,withSourceCode=True,**kwArgs):
|
|
191
|
+
def documentQueryResult(self,lod:list,limit=None,tablefmt:str="mediawiki",tryItUrl:str=None,withSourceCode=True,**kwArgs):
|
|
160
192
|
'''
|
|
161
193
|
document the given query results
|
|
162
194
|
|
|
163
195
|
Args:
|
|
164
196
|
lod: the list of dicts result
|
|
165
|
-
|
|
197
|
+
limit(int): the maximum number of records to display in result tabulate
|
|
166
198
|
tablefmt(str): the table format to use
|
|
199
|
+
tryItUrl: the "try it!" url to show
|
|
167
200
|
withSourceCode(bool): if True document the source code
|
|
168
201
|
|
|
169
202
|
Return:
|
|
@@ -171,7 +204,11 @@ class Query(object):
|
|
|
171
204
|
'''
|
|
172
205
|
sourceCode=self.query
|
|
173
206
|
title=self.title
|
|
207
|
+
if limit is not None:
|
|
208
|
+
lod=lod[:limit]
|
|
174
209
|
result=tabulate(lod,headers="keys",tablefmt=tablefmt,**kwArgs)
|
|
210
|
+
if tryItUrl is None and hasattr(self,'tryItUrl'):
|
|
211
|
+
tryItUrl=self.tryItUrl
|
|
175
212
|
if withSourceCode:
|
|
176
213
|
tryItMarkup=self.getLink(tryItUrl, "try it!", tablefmt)
|
|
177
214
|
if tablefmt=="github":
|
|
@@ -216,7 +253,7 @@ class Query(object):
|
|
|
216
253
|
sourceCode=f"{self.query}"
|
|
217
254
|
if self.lang!="sparql":
|
|
218
255
|
tryItMarkup=""
|
|
219
|
-
queryResultDocumentation=QueryResultDocumentation(query=self,title=title,tryItMarkup=tryItMarkup,sourceCodeHeader=sourceCodeHeader,sourceCode=sourceCode,resultHeader=resultHeader,result=result)
|
|
256
|
+
queryResultDocumentation=QueryResultDocumentation(query=self,title=title,tablefmt=tablefmt,tryItMarkup=tryItMarkup,sourceCodeHeader=sourceCodeHeader,sourceCode=sourceCode,resultHeader=resultHeader,result=result)
|
|
220
257
|
return queryResultDocumentation
|
|
221
258
|
|
|
222
259
|
class QueryManager(object):
|
|
@@ -43,6 +43,15 @@ class SQLDB(object):
|
|
|
43
43
|
else:
|
|
44
44
|
self.c=connection
|
|
45
45
|
|
|
46
|
+
def logError(self,msg):
|
|
47
|
+
'''
|
|
48
|
+
log the given error message to stderr
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
msg(str): the error messsage to display
|
|
52
|
+
'''
|
|
53
|
+
print(msg,file=sys.stderr,flush=True)
|
|
54
|
+
|
|
46
55
|
def close(self):
|
|
47
56
|
''' close my connection '''
|
|
48
57
|
self.c.close()
|
|
@@ -83,7 +92,7 @@ class SQLDB(object):
|
|
|
83
92
|
raise Exception(msg)
|
|
84
93
|
else:
|
|
85
94
|
if self.debug:
|
|
86
|
-
|
|
95
|
+
self.logError(msg)
|
|
87
96
|
sampleRecords=listOfRecords[:sampleRecordCount]
|
|
88
97
|
entityInfo=EntityInfo(sampleRecords,entityName,primaryKey,debug=self.debug)
|
|
89
98
|
if withDrop:
|
|
@@ -188,9 +197,15 @@ class SQLDB(object):
|
|
|
188
197
|
query = cur.execute(sqlQuery)
|
|
189
198
|
colname = [ d[0] for d in query.description ]
|
|
190
199
|
resultList=[]
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
200
|
+
try:
|
|
201
|
+
# loop over all rows
|
|
202
|
+
for row in query:
|
|
203
|
+
record=dict(zip(colname, row))
|
|
204
|
+
resultList.append(record)
|
|
205
|
+
except Exception as ex:
|
|
206
|
+
msg=str(ex)
|
|
207
|
+
self.logError(msg)
|
|
208
|
+
pass
|
|
194
209
|
cur.close()
|
|
195
210
|
return resultList
|
|
196
211
|
|
|
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
|