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