pyLodStorage 0.0.2__tar.gz → 0.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: python List of Dict (Table) Storage library
5
5
  Home-page: https://github.com/WolfgangFahl/pyLodStorage
6
6
  Author: Wolfgang Fahl
@@ -4,7 +4,6 @@ Created on 2020-09-04
4
4
  @author: wf
5
5
  '''
6
6
  from collections import Counter
7
-
8
7
  class UML(object):
9
8
  '''
10
9
  UML diagrams via plantuml
@@ -114,10 +113,15 @@ hide Circle
114
113
  '''
115
114
  gCol=None
116
115
  for table in tableList:
117
- for col in table['columns']:
116
+ for col in table['columns']:
118
117
  if col['name']==colName:
119
- gCol=col
120
- table['columns'].remove(col)
118
+ gCol=col.copy()
119
+ # no linking yet @FIXME - will need this later
120
+ if 'link' in gCol:
121
+ gCol.pop('link')
122
+ # is generalization protected for this column?
123
+ if not 'special' in col or not col['special']:
124
+ table['columns'].remove(col)
121
125
  return gCol
122
126
 
123
127
  def getGeneral(self,tableList,name):
@@ -145,12 +149,13 @@ hide Circle
145
149
  general['columns'].append(generalCol)
146
150
  return general
147
151
 
148
- def tableListToPlantUml(self,tableList, packageName=None,generalizeTo=None,withSkin=True):
152
+ def tableListToPlantUml(self,tableList,title=None,packageName=None,generalizeTo=None,withSkin=True):
149
153
  '''
150
154
  convert tableList to PlantUml notation
151
155
 
152
156
  Args:
153
157
  tableList(list): the tableList list of Dicts from getTableList() to convert
158
+ title(string): optional title to be added
154
159
  packageName(string): optional packageName to be added
155
160
  generalizeTo(string): optional name of a general table to be derived
156
161
  withSkin(boolean): if True add default BITPlan skin parameters
@@ -161,6 +166,8 @@ hide Circle
161
166
  uml=""
162
167
  indent=""
163
168
  inherit=""
169
+ if title is not None:
170
+ uml+="title\n%s\nend title\n" % title
164
171
  if packageName is not None:
165
172
  uml+="package %s {\n" % packageName
166
173
  indent=" "
@@ -171,11 +178,19 @@ hide Circle
171
178
  tableList.insert(0,generalTable)
172
179
  for table in tableList:
173
180
  colUml=""
174
- for col in table['columns']:
181
+ sortedColumns=sorted(table['columns'],key=lambda col:col['name'])
182
+ for col in sortedColumns:
175
183
  mandatory="*" if col['notnull']==1 else ""
176
184
  pk="<<PK>>" if col['pk']==1 else ""
177
- colUml+="%s %s%s : %s %s\n" % (indent,mandatory,col['name'],col['type'],pk)
178
- uml+="%sentity %s {\n%s%s}\n" % (indent,table['name'],colUml,indent)
185
+ colName=col['name']
186
+ colType=col['type']
187
+ if 'link' in col:
188
+ colName=col['link']
189
+ colUml+="%s %s%s : %s %s\n" % (indent,mandatory,colName,colType,pk)
190
+ tableName=table['name']
191
+ if 'notes' in table:
192
+ uml+="Note top of %s\n%s\nEnd note\n" % (tableName,table['notes'])
193
+ uml+="%sclass %s << Entity >> {\n%s%s}\n" % (indent,tableName,colUml,indent)
179
194
  uml+=inherit
180
195
  if packageName is not None:
181
196
  uml+="}\n"
@@ -183,5 +198,42 @@ hide Circle
183
198
  uml+=UML.skinparams
184
199
  return uml
185
200
 
186
-
187
-
201
+ def mergeSchema(self,schemaManager,tableList, title=None,packageName=None,generalizeTo=None,withSkin=True):
202
+ '''
203
+ merge Schema and tableList to PlantUml notation
204
+
205
+ Args:
206
+ schemaManager(SchemaManager): a schema manager to be used
207
+ tableList(list): the tableList list of Dicts from getTableList() to convert
208
+ title(string): optional title to be added
209
+ packageName(string): optional packageName to be added
210
+ generalizeTo(string): optional name of a general table to be derived
211
+ withSkin(boolean): if True add default BITPlan skin parameters
212
+
213
+ Returns:
214
+ string: the Plantuml notation for the entities in columns of the given tablelist
215
+
216
+ '''
217
+ if schemaManager is not None:
218
+ for table in tableList:
219
+ if 'schema' in table:
220
+ schema=schemaManager.schemasByName[table['schema']]
221
+ url="%s/%s" % (schemaManager.baseUrl,schema.name)
222
+ url=url.replace(" ", "_") # mediawiki
223
+ instanceNote=""
224
+ if 'instances' in table:
225
+ instanceNote="\n%d instances " % (table['instances'])
226
+ table['notes']="""[[%s %s]]%s""" % (url,schema.name,instanceNote)
227
+ for col in table['columns']:
228
+ colName=col['name']
229
+ if colName in schema.propsByName:
230
+ prop=schema.propsByName[colName]
231
+ if prop.iri is not None:
232
+ tooltip=""
233
+ if prop.definition is not None:
234
+ tooltip="{%s}" % prop.definition
235
+ col['link']="[[%s%s %s]]" % (prop.iri,tooltip,colName)
236
+ col['special']=True # keep column even if generalized
237
+ pass
238
+ plantuml=self.tableListToPlantUml(tableList, title=title,packageName=packageName, generalizeTo=generalizeTo, withSkin=withSkin)
239
+ return plantuml
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pylodstorage
3
- Version: 0.0.2
3
+ Version: 0.0.3
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,7 +10,7 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
10
10
 
11
11
  setup(
12
12
  name='pylodstorage',
13
- version='0.0.2',
13
+ version='0.0.3',
14
14
 
15
15
  packages=['lodstorage',],
16
16
  author='Wolfgang Fahl',
File without changes
File without changes