pyLodStorage 0.0.69__tar.gz → 0.0.71__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 (28) hide show
  1. {pylodstorage-0.0.69/pylodstorage.egg-info → pylodstorage-0.0.71}/PKG-INFO +1 -1
  2. pylodstorage-0.0.71/lodstorage/query.py +253 -0
  3. {pylodstorage-0.0.69 → pylodstorage-0.0.71/pylodstorage.egg-info}/PKG-INFO +1 -1
  4. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/setup.py +1 -1
  5. pylodstorage-0.0.69/lodstorage/query.py +0 -148
  6. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/LICENSE +0 -0
  7. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/README.md +0 -0
  8. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/__init__.py +0 -0
  9. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/csv.py +0 -0
  10. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/entity.py +0 -0
  11. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/jsonable.py +0 -0
  12. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/jsonpicklemixin.py +0 -0
  13. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/lod.py +0 -0
  14. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/mwTable.py +0 -0
  15. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/plot.py +0 -0
  16. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/sample.py +0 -0
  17. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/schema.py +0 -0
  18. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/sparql.py +0 -0
  19. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/sql.py +0 -0
  20. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/storageconfig.py +0 -0
  21. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/tabulateCounter.py +0 -0
  22. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/uml.py +0 -0
  23. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/lodstorage/yamlablemixin.py +0 -0
  24. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/pylodstorage.egg-info/SOURCES.txt +0 -0
  25. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/pylodstorage.egg-info/dependency_links.txt +0 -0
  26. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/pylodstorage.egg-info/requires.txt +0 -0
  27. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/pylodstorage.egg-info/top_level.txt +0 -0
  28. {pylodstorage-0.0.69 → pylodstorage-0.0.71}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.0.69
3
+ Version: 0.0.71
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -0,0 +1,253 @@
1
+ '''
2
+ Created on 2020-08-22
3
+
4
+ @author: wf
5
+ '''
6
+ import os
7
+ import yaml
8
+ from tabulate import tabulate
9
+ import urllib
10
+ #from wikibot.mwTable import MediaWikiTable
11
+ # redundant copy in this library to avoid dependency issues
12
+ # original is at
13
+ from lodstorage.mwTable import MediaWikiTable
14
+
15
+
16
+ class QueryResultDocumentation():
17
+ '''
18
+ documentation of a query result
19
+ '''
20
+
21
+ def __init__(self,query,title:str,tryItMarkup:str,sourceCodeHeader:str,sourceCode:str,resultHeader:str,result:str):
22
+ '''
23
+ constructor
24
+
25
+ Args:
26
+ query(Query): the query to be documented
27
+ title(str): the title markup
28
+ tryItMarkup: the "try it!" markup to show
29
+ sourceCodeHeader(str): the header title to use for the sourceCode
30
+ sourceCode(str): the sourceCode
31
+ resultCodeHeader(str): the header title to use for the result
32
+ result(str): the result header
33
+
34
+ '''
35
+ self.query=query
36
+ self.title=title
37
+ self.tryItMarkup=f"\n{tryItMarkup}"
38
+ self.sourceCodeHeader=sourceCodeHeader
39
+ self.sourceCode=sourceCode
40
+ self.resultHeader=resultHeader
41
+ self.result=result
42
+
43
+
44
+ def __str__(self):
45
+ '''
46
+ simple string representation
47
+ '''
48
+ text=f"{self.title}\n{self.query.description}\n{self.sourceCodeHeader}\n{self.sourceCode}{self.tryItMarkup}\n{self.resultHeader}\n{self.result}"
49
+ return text
50
+
51
+ class Query(object):
52
+ ''' a Query e.g. for SPAQRL '''
53
+
54
+ def __init__(self,name:str,query:str,lang='sparql',title:str=None,description:str=None,debug=False):
55
+ '''
56
+ constructor
57
+ Args:
58
+ name(string): the name/label of the query
59
+ query(string): the native Query text e.g. in SPARQL
60
+ lang(string): the language of the query e.g. SPARQL
61
+ title(string): the header/title of the query
62
+ description(string): the description of the query
63
+ debug(boolean): true if debug mode should be switched on
64
+ '''
65
+ self.name=name
66
+ self.query=query
67
+ self.lang=lang
68
+ self.title=title=name if title is None else title
69
+ self.description="" if description is None else description
70
+ self.debug=debug
71
+
72
+ def getTryItUrl(self,baseurl:str):
73
+ '''
74
+ return the "try it!" url for the given baseurl
75
+
76
+ Args:
77
+ baseurl(str): the baseurl to used
78
+
79
+ Returns:
80
+ str: the "try it!" url for the given query
81
+ '''
82
+ quoted=urllib.parse.quote(self.query)
83
+ quoted=f"#{quoted}"
84
+ url=f"{baseurl}/{quoted}"
85
+ return url
86
+
87
+ def getLink(self,url,title,tablefmt):
88
+ '''
89
+ convert the given url and title to a link for the given tablefmt
90
+
91
+ Args:
92
+ url(str): the url to convert
93
+ title(str): the title to show
94
+ tablefmt(str): the table format to use
95
+ '''
96
+ # create a safe url
97
+ if url is None:
98
+ return ""
99
+ markup=f"{title}:{url}"
100
+ if tablefmt=="mediawiki":
101
+ markup=f"[{url} {title}]"
102
+ elif tablefmt=="github":
103
+ markup=f"[{title}]({url})"
104
+ elif tablefmt=="latex":
105
+ markup=r"\href{%s}{%s}" % (url,title)
106
+ return markup
107
+
108
+
109
+ def prefixToLink(self,lod:list,prefix:str,tablefmt:str):
110
+ '''
111
+ convert url prefixes to link according to the given table format
112
+
113
+ Args:
114
+ lod(list): the list of dicts to convert
115
+ prefix(str): the prefix to strip
116
+ tablefmt(str): the tabulate tableformat to use
117
+
118
+ '''
119
+ for record in lod:
120
+ for key in record.keys():
121
+ value=record[key]
122
+ if value is not None and isinstance(value,str) and value.startswith(prefix):
123
+ item=value.replace(prefix,"")
124
+ item=urllib.parse.quote(item)
125
+ if tablefmt=="latex":
126
+ link=item
127
+ else:
128
+ link=self.getLink(value,item,tablefmt)
129
+ record[key]=link
130
+
131
+
132
+ def asWikiSourceMarkup(self):
133
+ '''
134
+ convert me to Mediawiki markup for syntax highlighting using the "source" tag
135
+
136
+
137
+ Returns:
138
+ string: the Markup
139
+ '''
140
+ markup="<source lang='%s'>\n%s\n</source>\n" %(self.lang,self.query)
141
+ return markup
142
+
143
+ def asWikiMarkup(self,listOfDicts):
144
+ '''
145
+ convert the given listOfDicts result to MediaWiki markup
146
+
147
+ Args:
148
+ listOfDicts(list): the list of Dicts to convert to MediaWiki markup
149
+
150
+ Returns:
151
+ string: the markup
152
+ '''
153
+ if self.debug:
154
+ print(listOfDicts)
155
+ mwTable=MediaWikiTable()
156
+ mwTable.fromListOfDicts(listOfDicts)
157
+ markup=mwTable.asWikiMarkup()
158
+ return markup
159
+
160
+ def documentQueryResult(self,lod:list,tablefmt:str="mediawiki",tryItUrl:str=None,withSourceCode=True,**kwArgs):
161
+ '''
162
+ document the given query results
163
+
164
+ Args:
165
+ lod: the list of dicts result
166
+ tryItUrl: the "try it!" url to show
167
+ tablefmt(str): the table format to use
168
+ withSourceCode(bool): if True document the source code
169
+
170
+ Return:
171
+ str: the documentation tabular text for the given parameters
172
+ '''
173
+ sourceCode=self.query
174
+ title=self.title
175
+ result=tabulate(lod,headers="keys",tablefmt=tablefmt,**kwArgs)
176
+ if withSourceCode:
177
+ tryItMarkup=self.getLink(tryItUrl, "try it!", tablefmt)
178
+ if tablefmt=="github":
179
+ title=f"**{self.title}**"
180
+ sourceCodeHeader="**query**"
181
+ resultHeader="**result**"
182
+ sourceCode=f"""```sql
183
+ {self.query}
184
+ ```"""
185
+
186
+ elif tablefmt=="mediawiki":
187
+ title=f"== {self.title} =="
188
+ sourceCodeHeader="=== query ==="
189
+ resultHeader="=== result ==="
190
+ sourceCode=f"""<source lang='{self.lang}'>
191
+ {self.query}
192
+ </source>
193
+ """
194
+ elif tablefmt=="latex":
195
+ sourceCodeHeader=r"see query listing \ref{listing:%s} and result table \ref{tab:%s}" % (self.name,self.name)
196
+ resultHeader=""
197
+ sourceCode=r"""\begin{listing}[ht]
198
+ \caption{%s}
199
+ \label{listing:%s}
200
+ \begin{minted}{%s}
201
+ %s
202
+ \end{minted}
203
+ %s
204
+ \end{listing}
205
+ """ % (self.title,self.name,self.lang.lower(),self.query,tryItMarkup)
206
+ tryItMarkup=""
207
+ result=r"""\begin{table}
208
+ \caption{%s}
209
+ \label{tab:%s}
210
+ %s
211
+ \end{table}
212
+ """ % (self.title,self.name,result)
213
+ else:
214
+ title=f"{self.title}"
215
+ sourceCodeHeader="query:"
216
+ resultHeader="result:"
217
+ sourceCode=f"{self.query}"
218
+ if self.lang!="sparql":
219
+ tryItMarkup=""
220
+ queryResultDocumentation=QueryResultDocumentation(query=self,title=title,tryItMarkup=tryItMarkup,sourceCodeHeader=sourceCodeHeader,sourceCode=sourceCode,resultHeader=resultHeader,result=result)
221
+ return queryResultDocumentation
222
+
223
+ class QueryManager(object):
224
+ '''
225
+ manages pre packaged Queries
226
+ '''
227
+
228
+ def __init__(self,lang='sql',debug=False,path=None):
229
+ '''
230
+ Constructor
231
+ Args:
232
+ lang(string): the language to use for the queries sql or sparql
233
+ debug(boolean): True if debug information should be shown
234
+ '''
235
+ self.queriesByName={}
236
+ self.lang=lang
237
+ self.debug=debug
238
+ queries=QueryManager.getQueries(path=path)
239
+ for name,queryDict in queries.items():
240
+ if self.lang in queryDict:
241
+ queryText=queryDict[self.lang]
242
+ query=Query(name,queryText,lang=self.lang,debug=self.debug)
243
+ self.queriesByName[name]=query
244
+
245
+ @staticmethod
246
+ def getQueries(path=None):
247
+ if path is None:
248
+ path=os.path.dirname(__file__)+"/.."
249
+ queriesPath=path+"/queries.yaml"
250
+ with open(queriesPath, 'r') as stream:
251
+ examples = yaml.safe_load(stream)
252
+ return examples
253
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.0.69
3
+ Version: 0.0.71
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -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.69',
14
+ version='0.0.71',
15
15
 
16
16
  packages=['lodstorage',],
17
17
  author='Wolfgang Fahl',
@@ -1,148 +0,0 @@
1
- '''
2
- Created on 2020-08-22
3
-
4
- @author: wf
5
- '''
6
- import os
7
- import yaml
8
- from tabulate import tabulate
9
- #from wikibot.mwTable import MediaWikiTable
10
- # redundant copy in this library to avoid dependency issues
11
- # original is at
12
- from lodstorage.mwTable import MediaWikiTable
13
-
14
-
15
- class QueryResultDocumentation():
16
- '''
17
- documentation of a query result
18
- '''
19
-
20
- def __init__(self,title,sourceCode,sourceCodeHeader,resultHeader,result):
21
- '''
22
- constructor
23
-
24
- Args:
25
- title(str): the title markup
26
-
27
- '''
28
- self.title=title
29
- self.sourceCodeHeader=sourceCodeHeader
30
- self.sourceCode=sourceCode
31
- self.resultHeader=resultHeader
32
- self.result=result
33
-
34
- def __str__(self):
35
- text=f"{self.title}\n{self.sourceCodeHeader}\n{self.sourceCode}\n{self.resultHeader}\n{self.result}"
36
- return text
37
-
38
- class Query(object):
39
- ''' a Query e.g. for SPAQRL '''
40
-
41
- def __init__(self,name,query,lang='sparql',debug=False):
42
- '''
43
- constructor
44
- Args:
45
- name(string): the name of the query
46
- query(string): the native Query text e.g. in SPARQL
47
- lang(string): the language of the query e.g. SPARQL
48
- debug(boolean): true if debug mode should be switched on
49
- '''
50
- self.name=name
51
- self.lang=lang
52
- self.query=query
53
- self.debug=debug
54
-
55
- def asWikiSourceMarkup(self):
56
- '''
57
- convert me to Mediawiki markup for syntax highlighting using the "source" tag
58
-
59
-
60
- Returns:
61
- string: the Markup
62
- '''
63
- markup="<source lang='%s'>\n%s\n</source>\n" %(self.lang,self.query)
64
- return markup
65
-
66
- def asWikiMarkup(self,listOfDicts):
67
- '''
68
- convert the given listOfDicts result to MediaWiki markup
69
-
70
- Args:
71
- listOfDicts(list): the list of Dicts to convert to MediaWiki markup
72
-
73
- Returns:
74
- string: the markup
75
- '''
76
- if self.debug:
77
- print(listOfDicts)
78
- mwTable=MediaWikiTable()
79
- mwTable.fromListOfDicts(listOfDicts)
80
- markup=mwTable.asWikiMarkup()
81
- return markup
82
-
83
- def documentQueryResult(self,lod:list,tablefmt:str="mediawiki",withSourceCode=True,**kwArgs):
84
- '''
85
- document the given query results
86
-
87
- Args:
88
- lod: the list of dicts result
89
- tablefmt(str): the table format to use
90
- withSourceCode(bool): if True document the source code
91
-
92
- Return:
93
- str(
94
- '''
95
- sourceCode=self.query
96
- title=self.name
97
- if withSourceCode:
98
- sourceCodeHeader="**query**"
99
- resultHeader="**result**"
100
- if tablefmt=="github":
101
- title=f"**{self.name}**"
102
- sourceCode=f"""**query**
103
- ```sql
104
- {self.query}
105
- ```"""
106
- if tablefmt=="mediawiki":
107
- title=f"== {self.name} =="
108
- sourceCodeHeader="=== query ==="
109
- resultHeader="=== result ==="
110
- sourceCode=f"""<source lang='sql'>
111
- {self.query}
112
- </source>
113
- """
114
- tab=tabulate(lod,headers="keys",tablefmt=tablefmt,**kwArgs)
115
- queryResultDocumentation=QueryResultDocumentation(title=title,sourceCode=sourceCode,sourceCodeHeader=sourceCodeHeader,resultHeader=resultHeader,result=tab)
116
- return queryResultDocumentation
117
-
118
- class QueryManager(object):
119
- '''
120
- manages prepackaged Queries
121
- '''
122
-
123
- def __init__(self,lang='sql',debug=False,path=None):
124
- '''
125
- Constructor
126
- Args:
127
- lang(string): the language to use for the queries sql or sparql
128
- debug(boolean): True if debug information should be shown
129
- '''
130
- self.queriesByName={}
131
- self.lang=lang
132
- self.debug=debug
133
- queries=QueryManager.getQueries(path=path)
134
- for name,queryDict in queries.items():
135
- if self.lang in queryDict:
136
- queryText=queryDict[self.lang]
137
- query=Query(name,queryText,lang=self.lang,debug=self.debug)
138
- self.queriesByName[name]=query
139
-
140
- @staticmethod
141
- def getQueries(path=None):
142
- if path is None:
143
- path=os.path.dirname(__file__)+"/.."
144
- queriesPath=path+"/queries.yaml"
145
- with open(queriesPath, 'r') as stream:
146
- examples = yaml.safe_load(stream)
147
- return examples
148
-
File without changes
File without changes
File without changes