pyLodStorage 0.0.78__tar.gz → 0.0.80__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.78/pylodstorage.egg-info → pylodstorage-0.0.80}/PKG-INFO +1 -1
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/entity.py +34 -10
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/jsonable.py +15 -4
- {pylodstorage-0.0.78 → pylodstorage-0.0.80/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/setup.py +1 -1
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/LICENSE +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/README.md +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/csv.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/lod.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/plot.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/query.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/sample.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/schema.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/sql.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/uml.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.0.78 → pylodstorage-0.0.80}/setup.cfg +0 -0
|
@@ -5,6 +5,7 @@ Created on 2020-08-19
|
|
|
5
5
|
'''
|
|
6
6
|
from lodstorage.yamlablemixin import YamlAbleMixin
|
|
7
7
|
from lodstorage.jsonpicklemixin import JsonPickleMixin
|
|
8
|
+
from lodstorage.jsonable import JSONAble
|
|
8
9
|
from lodstorage.storageconfig import StorageConfig, StoreMode
|
|
9
10
|
from lodstorage.sparql import SPARQL
|
|
10
11
|
from lodstorage.sql import SQLDB
|
|
@@ -102,7 +103,7 @@ class EntityManager(YamlAbleMixin, JsonPickleMixin,JSONAbleList):
|
|
|
102
103
|
cacheFile=self.getCacheFile(mode=mode)
|
|
103
104
|
if os.path.isfile(cacheFile):
|
|
104
105
|
os.remove(cacheFile)
|
|
105
|
-
|
|
106
|
+
|
|
106
107
|
def getSQLDB(self,cacheFile):
|
|
107
108
|
'''
|
|
108
109
|
get the SQL database for the given cacheFile
|
|
@@ -114,6 +115,23 @@ class EntityManager(YamlAbleMixin, JsonPickleMixin,JSONAbleList):
|
|
|
114
115
|
sqldb=self.sqldb=SQLDB(cacheFile,debug=config.debug,errorDebug=config.errorDebug)
|
|
115
116
|
return sqldb
|
|
116
117
|
|
|
118
|
+
def initSQLDB(self,sqldb,listOfDicts=None,withCreate:bool=True,withDrop:bool=True,sampleRecordCount=-1):
|
|
119
|
+
'''
|
|
120
|
+
initialize my sql DB
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
listOfDicts(list): the list of dicts to analyze for type information
|
|
124
|
+
withDrop(boolean): true if the existing Table should be dropped
|
|
125
|
+
withCreate(boolean): true if the create Table command should be executed - false if only the entityInfo should be returned
|
|
126
|
+
sampleRecordCount(int): the number of records to analyze for type information
|
|
127
|
+
Return:
|
|
128
|
+
EntityInfo: the entity information such as CREATE Table command
|
|
129
|
+
'''
|
|
130
|
+
if listOfDicts is None:
|
|
131
|
+
listOfDicts=JSONAble.getJsonTypeSamplesForClass(self.clazz)
|
|
132
|
+
entityInfo=sqldb.createTable(listOfDicts, self.tableName, primaryKey=self.primaryKey,withCreate=withCreate,withDrop=withDrop,sampleRecordCount=sampleRecordCount)
|
|
133
|
+
return entityInfo
|
|
134
|
+
|
|
117
135
|
def setNone(self,record,fields):
|
|
118
136
|
'''
|
|
119
137
|
make sure the given fields in the given record are set to none
|
|
@@ -167,14 +185,14 @@ GROUP by ?source
|
|
|
167
185
|
raise Exception("unsupported mode %s" % self.mode)
|
|
168
186
|
return result
|
|
169
187
|
|
|
170
|
-
def fromCache(self,force:bool=False,getListOfDicts=None,
|
|
188
|
+
def fromCache(self,force:bool=False,getListOfDicts=None,append=False,sampleRecordCount=-1):
|
|
171
189
|
'''
|
|
172
190
|
get my entries from the cache or from the callback provided
|
|
173
191
|
|
|
174
192
|
Args:
|
|
175
193
|
force(bool): force ignoring the cache
|
|
176
194
|
getListOfDicts(callable): a function to call for getting the data
|
|
177
|
-
|
|
195
|
+
append(bool): True if records should be appended
|
|
178
196
|
sampleRecordCount(int): the number of records to analyze for type information
|
|
179
197
|
|
|
180
198
|
Returns:
|
|
@@ -191,7 +209,7 @@ GROUP by ?source
|
|
|
191
209
|
listOfDicts=getListOfDicts()
|
|
192
210
|
duration=time.time()-startTime
|
|
193
211
|
self.showProgress(f"got {len(listOfDicts)} {self.entityPluralName} in {duration:5.1f} s")
|
|
194
|
-
self.cacheFile=self.storeLoD(listOfDicts,
|
|
212
|
+
self.cacheFile=self.storeLoD(listOfDicts,append=append,sampleRecordCount=sampleRecordCount)
|
|
195
213
|
self.setListFromLoD(listOfDicts)
|
|
196
214
|
else:
|
|
197
215
|
# fromStore also sets self.cacheFile
|
|
@@ -270,14 +288,14 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
|
|
|
270
288
|
lod.append(entity.__dict__)
|
|
271
289
|
return lod
|
|
272
290
|
|
|
273
|
-
def store(self,limit=10000000,batchSize=250,
|
|
291
|
+
def store(self,limit=10000000,batchSize=250,append=False,fixNone=True,sampleRecordCount=-1)->str:
|
|
274
292
|
'''
|
|
275
293
|
store my list of dicts
|
|
276
294
|
|
|
277
295
|
Args:
|
|
278
296
|
limit(int): maximum number of records to store per batch
|
|
279
297
|
batchSize(int): size of batch for storing
|
|
280
|
-
|
|
298
|
+
append(bool): True if records should be appended
|
|
281
299
|
fixNone(bool): if True make sure the dicts are filled with None references for each record
|
|
282
300
|
sampleRecordCount(int): the number of records to analyze for type information
|
|
283
301
|
|
|
@@ -285,9 +303,9 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
|
|
|
285
303
|
str: The cachefile being used
|
|
286
304
|
'''
|
|
287
305
|
lod=self.getLoD()
|
|
288
|
-
return self.storeLoD(lod,limit=limit,batchSize=batchSize,
|
|
306
|
+
return self.storeLoD(lod,limit=limit,batchSize=batchSize,append=append,fixNone=fixNone,sampleRecordCount=sampleRecordCount)
|
|
289
307
|
|
|
290
|
-
def storeLoD(self,listOfDicts,limit=10000000,batchSize=250,cacheFile=None,
|
|
308
|
+
def storeLoD(self,listOfDicts,limit=10000000,batchSize=250,cacheFile=None,append=False,fixNone=True,sampleRecordCount=1)->str:
|
|
291
309
|
'''
|
|
292
310
|
store my entities
|
|
293
311
|
|
|
@@ -296,7 +314,7 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
|
|
|
296
314
|
limit(int): maximum number of records to store
|
|
297
315
|
batchSize(int): size of batch for storing
|
|
298
316
|
cacheFile(string): the name of the storage e.g path to JSON or sqlite3 file
|
|
299
|
-
|
|
317
|
+
append(bool): True if records should be appended
|
|
300
318
|
fixNone(bool): if True make sure the dicts are filled with None references for each record
|
|
301
319
|
sampleRecordCount(int): the number of records to analyze for type information
|
|
302
320
|
|
|
@@ -331,7 +349,13 @@ SELECT ?eventId ?acronym ?series ?title ?year ?country ?city ?startDate ?endDate
|
|
|
331
349
|
cacheFile=self.getCacheFile(config=self.config,mode=self.config.mode)
|
|
332
350
|
sqldb=self.getSQLDB(cacheFile)
|
|
333
351
|
self.showProgress ("storing %d %s for %s to %s:%s" % (len(listOfDicts),self.entityPluralName,self.name,config.mode,cacheFile))
|
|
334
|
-
|
|
352
|
+
if append:
|
|
353
|
+
withDrop=False
|
|
354
|
+
withCreate=False
|
|
355
|
+
else:
|
|
356
|
+
withDrop=True
|
|
357
|
+
withCreate=True
|
|
358
|
+
entityInfo=self.initSQLDB(sqldb,listOfDicts,withCreate=withCreate,withDrop=withDrop,sampleRecordCount=sampleRecordCount)
|
|
335
359
|
self.sqldb.store(listOfDicts, entityInfo,executeMany=self.executeMany,fixNone=fixNone)
|
|
336
360
|
self.showProgress ("store for %s done after %5.1f secs" % (self.name,time.time()-startTime))
|
|
337
361
|
else:
|
|
@@ -122,10 +122,21 @@ class JSONAble(object):
|
|
|
122
122
|
cls=self.__class__
|
|
123
123
|
if isinstance(self, JSONAbleList) and not hasattr(cls, 'getSamples'):
|
|
124
124
|
cls=self.clazz
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
return JSONAble.getJsonTypeSamplesForClass(cls)
|
|
126
|
+
return None
|
|
127
|
+
|
|
128
|
+
@staticmethod
|
|
129
|
+
def getJsonTypeSamplesForClass(cls):
|
|
130
|
+
'''
|
|
131
|
+
return the type samples for the given class
|
|
132
|
+
|
|
133
|
+
Return:
|
|
134
|
+
list: a list of dict that specify the types by example
|
|
135
|
+
'''
|
|
136
|
+
if hasattr(cls, 'getSamples'):
|
|
137
|
+
getSamples=getattr(cls,'getSamples');
|
|
138
|
+
if callable(getSamples):
|
|
139
|
+
return getSamples()
|
|
129
140
|
return None
|
|
130
141
|
|
|
131
142
|
@staticmethod
|
|
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
|