pyLodStorage 0.0.76__tar.gz → 0.0.78__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.76/pylodstorage.egg-info → pylodstorage-0.0.78}/PKG-INFO +1 -1
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/entity.py +26 -13
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/sql.py +7 -5
- {pylodstorage-0.0.76 → pylodstorage-0.0.78/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/setup.py +1 -1
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/LICENSE +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/README.md +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/csv.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/lod.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/plot.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/query.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/sample.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/schema.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/uml.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.0.76 → pylodstorage-0.0.78}/setup.cfg +0 -0
|
@@ -10,6 +10,7 @@ from lodstorage.sparql import SPARQL
|
|
|
10
10
|
from lodstorage.sql import SQLDB
|
|
11
11
|
from lodstorage.lod import LOD
|
|
12
12
|
from lodstorage.jsonable import JSONAbleList
|
|
13
|
+
import sys
|
|
13
14
|
import os
|
|
14
15
|
import time
|
|
15
16
|
|
|
@@ -148,26 +149,33 @@ GROUP by ?source
|
|
|
148
149
|
elif mode is StoreMode.SQL:
|
|
149
150
|
cacheFile=self.getCacheFile(config=self.config,mode=StoreMode.SQL)
|
|
150
151
|
if os.path.isfile(cacheFile):
|
|
151
|
-
sqlQuery="SELECT COUNT(*) AS count FROM
|
|
152
|
+
sqlQuery=f"SELECT COUNT(*) AS count FROM {self.tableName}"
|
|
152
153
|
try:
|
|
153
154
|
sqlDB=self.getSQLDB(cacheFile)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
countResults=sqlDB.query(sqlQuery)
|
|
156
|
+
countResult=countResults[0]
|
|
157
|
+
count=countResult['count']
|
|
158
|
+
result=count>=0
|
|
157
159
|
except Exception as ex:
|
|
160
|
+
msg=str(ex)
|
|
161
|
+
if self.debug:
|
|
162
|
+
print(msg,file=sys.stderr)
|
|
163
|
+
sys.stderr.flush()
|
|
158
164
|
# e.g. sqlite3.OperationalError: no such table: Event_crossref
|
|
159
165
|
pass
|
|
160
166
|
else:
|
|
161
167
|
raise Exception("unsupported mode %s" % self.mode)
|
|
162
168
|
return result
|
|
163
169
|
|
|
164
|
-
def fromCache(self,force:bool=False,getListOfDicts=None,sampleRecordCount=-1):
|
|
170
|
+
def fromCache(self,force:bool=False,getListOfDicts=None,withDrop=True,sampleRecordCount=-1):
|
|
165
171
|
'''
|
|
166
|
-
get my entries from the cache or from the callback
|
|
172
|
+
get my entries from the cache or from the callback provided
|
|
167
173
|
|
|
168
174
|
Args:
|
|
169
175
|
force(bool): force ignoring the cache
|
|
170
176
|
getListOfDicts(callable): a function to call for getting the data
|
|
177
|
+
withDrop(bool): True if the table should be (re) created
|
|
178
|
+
sampleRecordCount(int): the number of records to analyze for type information
|
|
171
179
|
|
|
172
180
|
Returns:
|
|
173
181
|
the list of Dicts and as a side effect setting self.cacheFile
|
|
@@ -176,11 +184,14 @@ GROUP by ?source
|
|
|
176
184
|
startTime=time.time()
|
|
177
185
|
self.showProgress(f"getting {self.entityPluralName} for {self.name} ...")
|
|
178
186
|
if getListOfDicts is None:
|
|
179
|
-
|
|
187
|
+
if hasattr(self, "getListOfDicts"):
|
|
188
|
+
getListOfDicts=self.getListOfDicts
|
|
189
|
+
else:
|
|
190
|
+
raise Exception("from Cache failed and no secondary cache via getListOfDicts specified")
|
|
180
191
|
listOfDicts=getListOfDicts()
|
|
181
192
|
duration=time.time()-startTime
|
|
182
193
|
self.showProgress(f"got {len(listOfDicts)} {self.entityPluralName} in {duration:5.1f} s")
|
|
183
|
-
self.cacheFile=self.storeLoD(listOfDicts,sampleRecordCount=sampleRecordCount)
|
|
194
|
+
self.cacheFile=self.storeLoD(listOfDicts,withDrop=withDrop,sampleRecordCount=sampleRecordCount)
|
|
184
195
|
self.setListFromLoD(listOfDicts)
|
|
185
196
|
else:
|
|
186
197
|
# fromStore also sets self.cacheFile
|
|
@@ -259,13 +270,14 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
|
|
|
259
270
|
lod.append(entity.__dict__)
|
|
260
271
|
return lod
|
|
261
272
|
|
|
262
|
-
def store(self,limit=10000000,batchSize=250,fixNone=True,sampleRecordCount=-1)->str:
|
|
273
|
+
def store(self,limit=10000000,batchSize=250,withDrop=True,fixNone=True,sampleRecordCount=-1)->str:
|
|
263
274
|
'''
|
|
264
275
|
store my list of dicts
|
|
265
276
|
|
|
266
277
|
Args:
|
|
267
|
-
limit(int): maximum number of records to store
|
|
278
|
+
limit(int): maximum number of records to store per batch
|
|
268
279
|
batchSize(int): size of batch for storing
|
|
280
|
+
withDrop(bool): True if the table should be (re) created
|
|
269
281
|
fixNone(bool): if True make sure the dicts are filled with None references for each record
|
|
270
282
|
sampleRecordCount(int): the number of records to analyze for type information
|
|
271
283
|
|
|
@@ -273,9 +285,9 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
|
|
|
273
285
|
str: The cachefile being used
|
|
274
286
|
'''
|
|
275
287
|
lod=self.getLoD()
|
|
276
|
-
return self.storeLoD(lod,limit=limit,batchSize=batchSize,fixNone=fixNone,sampleRecordCount=sampleRecordCount)
|
|
288
|
+
return self.storeLoD(lod,limit=limit,batchSize=batchSize,withDrop=withDrop,fixNone=fixNone,sampleRecordCount=sampleRecordCount)
|
|
277
289
|
|
|
278
|
-
def storeLoD(self,listOfDicts,limit=10000000,batchSize=250,cacheFile=None,fixNone=True,sampleRecordCount=1)->str:
|
|
290
|
+
def storeLoD(self,listOfDicts,limit=10000000,batchSize=250,cacheFile=None,withDrop=True,fixNone=True,sampleRecordCount=1)->str:
|
|
279
291
|
'''
|
|
280
292
|
store my entities
|
|
281
293
|
|
|
@@ -284,6 +296,7 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
|
|
|
284
296
|
limit(int): maximum number of records to store
|
|
285
297
|
batchSize(int): size of batch for storing
|
|
286
298
|
cacheFile(string): the name of the storage e.g path to JSON or sqlite3 file
|
|
299
|
+
withDrop(bool): True if the table should be (re) created
|
|
287
300
|
fixNone(bool): if True make sure the dicts are filled with None references for each record
|
|
288
301
|
sampleRecordCount(int): the number of records to analyze for type information
|
|
289
302
|
|
|
@@ -318,7 +331,7 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
|
|
|
318
331
|
cacheFile=self.getCacheFile(config=self.config,mode=self.config.mode)
|
|
319
332
|
sqldb=self.getSQLDB(cacheFile)
|
|
320
333
|
self.showProgress ("storing %d %s for %s to %s:%s" % (len(listOfDicts),self.entityPluralName,self.name,config.mode,cacheFile))
|
|
321
|
-
entityInfo=sqldb.createTable(listOfDicts, self.tableName, primaryKey=self.primaryKey,withDrop=
|
|
334
|
+
entityInfo=sqldb.createTable(listOfDicts, self.tableName, primaryKey=self.primaryKey,withDrop=withDrop,sampleRecordCount=sampleRecordCount)
|
|
322
335
|
self.sqldb.store(listOfDicts, entityInfo,executeMany=self.executeMany,fixNone=fixNone)
|
|
323
336
|
self.showProgress ("store for %s done after %5.1f secs" % (self.name,time.time()-startTime))
|
|
324
337
|
else:
|
|
@@ -56,7 +56,7 @@ class SQLDB(object):
|
|
|
56
56
|
'''
|
|
57
57
|
self.c.execute(ddlCmd)
|
|
58
58
|
|
|
59
|
-
def createTable(self,listOfRecords,entityName,primaryKey=None,withDrop=False,sampleRecordCount=1,failIfTooFew=True):
|
|
59
|
+
def createTable(self,listOfRecords,entityName:str,primaryKey:str=None,withCreate:bool=True,withDrop:bool=False,sampleRecordCount=1,failIfTooFew=True):
|
|
60
60
|
'''
|
|
61
61
|
derive Data Definition Language CREATE TABLE command from list of Records by examining first recorda
|
|
62
62
|
as defining sample record and execute DDL command
|
|
@@ -68,6 +68,7 @@ class SQLDB(object):
|
|
|
68
68
|
entityName(string): the entity / table name to use
|
|
69
69
|
primaryKey(string): the key/column to use as a primary key
|
|
70
70
|
withDrop(boolean): true if the existing Table should be dropped
|
|
71
|
+
withCreate(boolean): true if the create Table command should be executed - false if only the entityInfo should be returned
|
|
71
72
|
sampleRecords(int): number of sampleRecords expected and to be inspected
|
|
72
73
|
failIfTooFew(boolean): raise an Exception if to few sampleRecords else warn only
|
|
73
74
|
Returns:
|
|
@@ -87,10 +88,11 @@ class SQLDB(object):
|
|
|
87
88
|
entityInfo=EntityInfo(sampleRecords,entityName,primaryKey,debug=self.debug)
|
|
88
89
|
if withDrop:
|
|
89
90
|
self.c.execute(entityInfo.dropTableCmd)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
if withCreate:
|
|
92
|
+
try:
|
|
93
|
+
self.c.execute(entityInfo.createTableCmd)
|
|
94
|
+
except sqlite3.OperationalError as oe:
|
|
95
|
+
raise Exception(f"createTable failed with error {oe} for {entityInfo.createTableCmd}")
|
|
94
96
|
return entityInfo
|
|
95
97
|
|
|
96
98
|
def getDebugInfo(self,record,index,executeMany):
|
|
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
|