pyLodStorage 0.0.85__tar.gz → 0.1.2__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 (29) hide show
  1. {pylodstorage-0.0.85/pylodstorage.egg-info → pylodstorage-0.1.2}/PKG-INFO +1 -1
  2. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/query.py +35 -12
  3. pylodstorage-0.1.2/lodstorage/querymain.py +128 -0
  4. {pylodstorage-0.0.85 → pylodstorage-0.1.2/pylodstorage.egg-info}/PKG-INFO +1 -1
  5. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/pylodstorage.egg-info/SOURCES.txt +2 -0
  6. pylodstorage-0.1.2/pylodstorage.egg-info/entry_points.txt +5 -0
  7. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/setup.py +8 -1
  8. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/LICENSE +0 -0
  9. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/README.md +0 -0
  10. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/__init__.py +0 -0
  11. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/csv.py +0 -0
  12. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/entity.py +0 -0
  13. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/jsonable.py +0 -0
  14. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/jsonpicklemixin.py +0 -0
  15. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/lod.py +0 -0
  16. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/mwTable.py +0 -0
  17. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/plot.py +0 -0
  18. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/sample.py +0 -0
  19. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/schema.py +0 -0
  20. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/sparql.py +0 -0
  21. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/sql.py +0 -0
  22. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/storageconfig.py +0 -0
  23. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/tabulateCounter.py +0 -0
  24. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/uml.py +0 -0
  25. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/lodstorage/yamlablemixin.py +0 -0
  26. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/pylodstorage.egg-info/dependency_links.txt +0 -0
  27. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/pylodstorage.egg-info/requires.txt +0 -0
  28. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/pylodstorage.egg-info/top_level.txt +0 -0
  29. {pylodstorage-0.0.85 → pylodstorage-0.1.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.0.85
3
+ Version: 0.1.2
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -46,7 +46,7 @@ class QueryResultDocumentation():
46
46
 
47
47
 
48
48
  @staticmethod
49
- def uniCode2Latex(text:str)->str:
49
+ def uniCode2Latex(text:str,withConvert:bool=False)->str:
50
50
  '''
51
51
  converts unicode text to latex and
52
52
  fixes UTF-8 chars for latex in a certain range:
@@ -56,13 +56,19 @@ class QueryResultDocumentation():
56
56
 
57
57
  Args:
58
58
  text(str): the string to fix
59
+ withConvert(bool): if unicode to latex libary conversion should be used
59
60
 
60
61
  Return:
61
62
  str: latex presentation of UTF-8 char
62
63
  '''
63
64
  for code in range(8320,8330):
64
65
  text=text.replace(chr(code),f"$_{code-8320}$")
65
- return unicode_to_latex(text)
66
+ if withConvert:
67
+ latex=unicode_to_latex(text)
68
+ # workaround {\textbackslash} being returned
69
+ #latex=latex.replace("{\\textbackslash}",'\\')
70
+ text=latex
71
+ return text
66
72
 
67
73
  @staticmethod
68
74
  def wikiDataLink(record,key,value,tablefmt):
@@ -104,27 +110,36 @@ class QueryResultDocumentation():
104
110
  class Query(object):
105
111
  ''' a Query e.g. for SPAQRL '''
106
112
 
107
- def __init__(self,name:str,query:str,lang='sparql',title:str=None,description:str=None,prefixes=None,debug=False):
113
+ def __init__(self,name:str,query:str,lang='sparql',endpoint:str=None,title:str=None,description:str=None,prefixes=None,tryItUrl:str=None,debug=False):
108
114
  '''
109
115
  constructor
110
116
  Args:
111
117
  name(string): the name/label of the query
112
118
  query(string): the native Query text e.g. in SPARQL
113
119
  lang(string): the language of the query e.g. SPARQL
120
+ endpoint(string): the endpoint url to use
114
121
  title(string): the header/title of the query
115
122
  description(string): the description of the query
116
123
  prefixes(list): list of prefixes to be resolved
124
+ tryItUrl(str): the url of a "tryit" webpage
117
125
  debug(boolean): true if debug mode should be switched on
118
126
  '''
119
127
  self.name=name
120
128
  self.query=query
121
129
  self.lang=lang
130
+ self.endpoint=endpoint
122
131
  self.title=title=name if title is None else title
123
132
  self.description="" if description is None else description
124
133
  self.prefixes=prefixes
125
134
  self.debug=debug
135
+ self.tryItUrl=tryItUrl
126
136
  self.formatCallBacks=[]
127
137
 
138
+ def __str__(self):
139
+ queryStr="\n".join([f"{key}:{value}" for key, value in self.__dict__.items() if value is not None])
140
+ return f"{queryStr}"
141
+
142
+
128
143
  def addFormatCallBack(self,callback):
129
144
  self.formatCallBacks.append(callback)
130
145
 
@@ -203,7 +218,10 @@ class Query(object):
203
218
  link=self.getLink(value,uqitem,tablefmt)
204
219
  record[key]=link
205
220
 
206
-
221
+ def asYaml(self):
222
+ yamlMarkup=yaml.dump(self)
223
+ return yamlMarkup
224
+
207
225
  def asWikiSourceMarkup(self):
208
226
  '''
209
227
  convert me to Mediawiki markup for syntax highlighting using the "source" tag
@@ -308,7 +326,7 @@ class QueryManager(object):
308
326
  manages pre packaged Queries
309
327
  '''
310
328
 
311
- def __init__(self,lang='sql',debug=False,path=None):
329
+ def __init__(self,lang='sql',debug=False,queriesPath=None):
312
330
  '''
313
331
  Constructor
314
332
  Args:
@@ -318,19 +336,24 @@ class QueryManager(object):
318
336
  self.queriesByName={}
319
337
  self.lang=lang
320
338
  self.debug=debug
321
- queries=QueryManager.getQueries(path=path)
339
+ queries=QueryManager.getQueries(queriesPath=queriesPath)
322
340
  for name,queryDict in queries.items():
323
341
  if self.lang in queryDict:
324
- queryText=queryDict[self.lang]
325
- query=Query(name,queryText,lang=self.lang,debug=self.debug)
342
+ queryText=queryDict.pop(self.lang)
343
+ query=Query(name=name,query=queryText,lang=self.lang,**queryDict,debug=self.debug)
326
344
  self.queriesByName[name]=query
327
345
 
328
346
  @staticmethod
329
- def getQueries(path=None):
330
- if path is None:
331
- path=os.path.dirname(__file__)+"/.."
332
- queriesPath=path+"/queries.yaml"
347
+ def getQueries(queriesPath=None):
348
+ '''
349
+ get the queries for thee given queries Path
350
+ '''
351
+ if queriesPath is None:
352
+ queriesPath=f"{os.path.dirname(__file__)}/../sampledata/queries.yaml"
333
353
  with open(queriesPath, 'r') as stream:
334
354
  examples = yaml.safe_load(stream)
335
355
  return examples
356
+
357
+
358
+
336
359
 
@@ -0,0 +1,128 @@
1
+ '''
2
+ Created on 2022-02-13
3
+
4
+ @author: wf
5
+ '''
6
+ __version__ = "0.1.2"
7
+ __date__ = '2020-09-10'
8
+ __updated__ = '2022-02-13'
9
+ DEBUG = 0
10
+
11
+ from enum import Enum
12
+ import sys
13
+ import os
14
+ from argparse import ArgumentParser
15
+ from argparse import RawDescriptionHelpFormatter
16
+ from lodstorage.query import QueryManager, QueryResultDocumentation
17
+ from lodstorage.sparql import SPARQL
18
+ from lodstorage.csv import CSV
19
+
20
+ class Format(Enum):
21
+ csv = 'csv'
22
+ json = 'json'
23
+ xml = 'xml'
24
+ tsv = 'tsv'
25
+ latex = 'latex'
26
+ mediawiki= 'mediawiki'
27
+ github = 'github'
28
+
29
+ def __str__(self):
30
+ return self.value
31
+
32
+ class QueryMain:
33
+ '''
34
+ Commandline handler
35
+ '''
36
+ @classmethod
37
+ def main(cls,args):
38
+ '''
39
+ command line activation with parsed args
40
+ '''
41
+ debug=args.debug
42
+ if args.queryName is not None:
43
+ if debug:
44
+ print(f"named query {args.queryName}:")
45
+ qm=QueryManager(lang=args.language,debug=debug,queriesPath=args.queriesPath)
46
+ if args.queryName not in qm.queriesByName:
47
+ raise Exception(f"named query {args.queryName} not available")
48
+ query=qm.queriesByName[args.queryName]
49
+ if args.language=="sparql":
50
+ endpoint=SPARQL(query.endpoint)
51
+ if "wikidata" in query.endpoint:
52
+ query.addFormatCallBack(QueryResultDocumentation.wikiDataLink)
53
+ qlod=endpoint.queryAsListOfDicts(query.query)
54
+ if args.format is Format.csv:
55
+ csv=CSV.toCSV(qlod)
56
+ print(csv)
57
+ elif args.format is Format.latex or args.format is Format.github or args.format is Format.mediawiki:
58
+ doc=query.documentQueryResult(qlod, tablefmt=str(args.format),floatfmt=".0f")
59
+ docstr=doc.asText()
60
+ print (docstr)
61
+
62
+
63
+
64
+ def mainSQL(argv=None):
65
+ main(argv,lang='SQL')
66
+
67
+ def mainSPARQL(argv=None):
68
+ main(argv,lang='SPARQL')
69
+
70
+ def main(argv=None,lang=None): # IGNORE:C0111
71
+ '''main program.'''
72
+
73
+ if argv is None:
74
+ argv=sys.argv[1:]
75
+
76
+ program_name = os.path.basename(__file__)
77
+ program_version = "v%s" % __version__
78
+ program_build_date = str(__updated__)
79
+ program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date)
80
+ program_shortdesc = "script to read event metadata from http://wikicfp.com"
81
+ user_name="Wolfgang Fahl"
82
+ program_license = '''%s
83
+
84
+ Created by %s on %s.
85
+ Copyright 2020-2022 Wolfgang Fahl. All rights reserved.
86
+
87
+ Licensed under the Apache License 2.0
88
+ http://www.apache.org/licenses/LICENSE-2.0
89
+
90
+ Distributed on an "AS IS" basis without warranties
91
+ or conditions of any kind, either express or implied.
92
+
93
+ USAGE
94
+ ''' % (program_shortdesc,user_name, str(__date__))
95
+
96
+ try:
97
+ # Setup argument parser
98
+ parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
99
+ parser.add_argument("-d", "--debug", dest="debug", action="store_true", help="set debug [default: %(default)s]")
100
+ parser.add_argument('-e', '--endpoint', default="https://query.wikidata.org/sparql", help="SPARQL endpoint to use for queries")
101
+ parser.add_argument('-f','--format', type=Format, choices=list(Format))
102
+ parser.add_argument('-qp', '--queriesPath',help="path to YAML file with query definitions")
103
+ parser.add_argument("-q", "--query",help="the query to run")
104
+ parser.add_argument("-qn","--queryName",help="run a named query")
105
+ parser.add_argument('-V', '--version', action='version', version=program_version_message)
106
+ if lang is None:
107
+ parser.add_argument('-l','--language',help="the query language to use",required=True)
108
+ args = parser.parse_args(argv)
109
+ if lang is not None:
110
+ args.language=lang
111
+ QueryMain.main(args)
112
+
113
+
114
+ except KeyboardInterrupt:
115
+ ### handle keyboard interrupt ###
116
+ return 1
117
+ except Exception as e:
118
+ if DEBUG:
119
+ raise(e)
120
+ indent = len(program_name) * " "
121
+ sys.stderr.write(program_name + ": " + repr(e) + "\n")
122
+ sys.stderr.write(indent + " for help use --help")
123
+ return 2
124
+
125
+ if __name__ == "__main__":
126
+ if DEBUG:
127
+ sys.argv.append("-d")
128
+ sys.exit(main())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.0.85
3
+ Version: 0.1.2
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -10,6 +10,7 @@ lodstorage/lod.py
10
10
  lodstorage/mwTable.py
11
11
  lodstorage/plot.py
12
12
  lodstorage/query.py
13
+ lodstorage/querymain.py
13
14
  lodstorage/sample.py
14
15
  lodstorage/schema.py
15
16
  lodstorage/sparql.py
@@ -21,5 +22,6 @@ lodstorage/yamlablemixin.py
21
22
  pylodstorage.egg-info/PKG-INFO
22
23
  pylodstorage.egg-info/SOURCES.txt
23
24
  pylodstorage.egg-info/dependency_links.txt
25
+ pylodstorage.egg-info/entry_points.txt
24
26
  pylodstorage.egg-info/requires.txt
25
27
  pylodstorage.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ lodquery = lodstorage.querymain:main
3
+ sparqlquery = lodstorage.querymain:mainSPARQL
4
+ sqlquery = lodstorage.querymain:mainSQL
5
+
@@ -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.85',
14
+ version='0.1.2',
15
15
 
16
16
  packages=['lodstorage',],
17
17
  author='Wolfgang Fahl',
@@ -42,6 +42,13 @@ setup(
42
42
  'Programming Language :: Python :: 3.8',
43
43
  'Programming Language :: Python :: 3.9'
44
44
  ],
45
+ entry_points={
46
+ 'console_scripts': [
47
+ 'sparqlquery = lodstorage.querymain:mainSPARQL',
48
+ 'sqlquery=lodstorage.querymain:mainSQL',
49
+ 'lodquery=lodstorage.querymain:main'
50
+ ],
51
+ },
45
52
  long_description=long_description,
46
53
  long_description_content_type='text/markdown'
47
54
  )
File without changes
File without changes
File without changes