otlmow-template 0.3__py3-none-any.whl → 0.4__py3-none-any.whl

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.
@@ -3,6 +3,7 @@ import ntpath
3
3
  import os
4
4
  import tempfile
5
5
  from pathlib import Path
6
+ from typing import List, Sequence, Optional
6
7
 
7
8
  from otlmow_converter.DotnotationHelper import DotnotationHelper
8
9
  from otlmow_converter.OtlmowConverter import OtlmowConverter
@@ -62,8 +63,8 @@ class CsvTemplateCreator:
62
63
  if add_geo_artefact is False:
63
64
  [header, data] = cls.remove_geo_artefact_csv(header=header, data=data)
64
65
  if add_attribute_info:
65
- [info, header] = cls.add_attribute_info_csv(header=header, data=data,
66
- instantiated_attributes=instantiated_attributes)
66
+ info = cls.add_attribute_info_csv(header=header, data=data,
67
+ instantiated_objects=instantiated_attributes)
67
68
  new_file.write(delimiter.join(info) + '\n')
68
69
  data = cls.remove_mock_data_csv(data=data, rows_of_examples=amount_of_examples)
69
70
  if highlight_deprecated_attributes:
@@ -75,30 +76,25 @@ class CsvTemplateCreator:
75
76
  new_file.close()
76
77
 
77
78
  @classmethod
78
- def add_attribute_info_csv(cls, header, data, instantiated_attributes):
79
+ def add_attribute_info_csv(cls, header: List[str], data: List[List[str]], instantiated_objects: List) -> List[str]:
79
80
  info_data = []
80
81
  info_data.extend(header)
81
- found_uri = []
82
+
82
83
  dotnotation_module = DotnotationHelper()
83
- uri_index = cls.find_uri_in_csv(header)
84
- for d in data:
85
- if d[uri_index] not in found_uri:
86
- found_uri.append(d[uri_index])
87
- for uri in found_uri:
88
- single_object = next(x for x in instantiated_attributes if x.typeURI == uri)
89
- for dotnototation_title in info_data:
84
+
85
+ uri_index = cls.get_type_uri_index_in_row(header)
86
+ found_uris = set(d[uri_index] for d in data)
87
+
88
+ for uri in found_uris:
89
+ single_object = next(x for x in instantiated_objects if x.typeURI == uri)
90
+ for index, dotnototation_title in enumerate(info_data):
90
91
  if dotnototation_title == 'typeURI':
91
- index = info_data.index(dotnototation_title)
92
92
  info_data[index] = 'De URI van het object volgens https://www.w3.org/2001/XMLSchema#anyURI .'
93
93
  else:
94
- index = info_data.index(dotnototation_title)
95
- try:
96
- dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(
97
- single_object, dotnototation_title)
98
- except AttributeError as e:
99
- continue
94
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(
95
+ single_object, dotnototation_title)
100
96
  info_data[index] = dotnotation_attribute.definition
101
- return [info_data, header]
97
+ return info_data
102
98
 
103
99
  @classmethod
104
100
  def remove_mock_data_csv(cls, data, rows_of_examples):
@@ -110,7 +106,7 @@ class CsvTemplateCreator:
110
106
  def highlight_deprecated_attributes_csv(cls, header, data, instantiated_attributes):
111
107
  found_uri = []
112
108
  dotnotation_module = DotnotationHelper()
113
- uri_index = cls.find_uri_in_csv(header)
109
+ uri_index = cls.get_type_uri_index_in_row(header)
114
110
  for d in data:
115
111
  if d[uri_index] not in found_uri:
116
112
  found_uri.append(d[uri_index])
@@ -142,11 +138,11 @@ class CsvTemplateCreator:
142
138
  return header
143
139
 
144
140
  @classmethod
145
- def find_uri_in_csv(cls, header):
146
- filter_uri = None
147
- if 'typeURI' in header:
148
- filter_uri = header.index('typeURI')
149
- return filter_uri
141
+ def get_type_uri_index_in_row(cls, header: Sequence[str]) -> Optional[int]:
142
+ try:
143
+ return header.index('typeURI')
144
+ except ValueError:
145
+ return None
150
146
 
151
147
  @classmethod
152
148
  def remove_geo_artefact_csv(cls, header, data):
@@ -1,15 +1,22 @@
1
1
  import ntpath
2
2
  import os
3
+ import csv
3
4
  import site
4
5
  import tempfile
5
6
  from pathlib import Path
7
+ from typing import List
8
+ from openpyxl.reader.excel import load_workbook
9
+ from openpyxl.styles import PatternFill
10
+ from openpyxl.utils import get_column_letter
11
+ from openpyxl.worksheet.datavalidation import DataValidation
12
+ from openpyxl.worksheet.dimensions import DimensionHolder, ColumnDimension
13
+ from otlmow_converter.DotnotationHelper import DotnotationHelper
6
14
  from otlmow_converter.OtlmowConverter import OtlmowConverter
7
- from otlmow_model.OtlmowModel.Helpers.AssetCreator import dynamic_create_instance_from_uri
15
+ from otlmow_model.OtlmowModel.BaseClasses.BooleanField import BooleanField
16
+ from otlmow_model.OtlmowModel.BaseClasses.KeuzelijstField import KeuzelijstField
17
+ from otlmow_model.OtlmowModel.BaseClasses.OTLObject import dynamic_create_instance_from_uri
8
18
  from otlmow_modelbuilder.OSLOCollector import OSLOCollector
9
19
 
10
- from otlmow_template.CsvTemplateCreator import CsvTemplateCreator
11
- from otlmow_template.ExcelTemplateCreator import ExcelTemplateCreator
12
-
13
20
  ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
14
21
 
15
22
  enumeration_validation_rules = {
@@ -31,31 +38,35 @@ class SubsetTemplateCreator:
31
38
 
32
39
  def generate_template_from_subset(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
33
40
  **kwargs):
34
- temporary_path = self.return_temp_path(path_to_template_file_and_extension=path_to_template_file_and_extension)
41
+ tempdir = Path(tempfile.gettempdir()) / 'temp-otlmow'
42
+ if not tempdir.exists():
43
+ os.makedirs(tempdir)
44
+ test = ntpath.basename(path_to_template_file_and_extension)
45
+ temporary_path = Path(tempdir) / test
35
46
  instantiated_attributes = self.generate_basic_template(path_to_subset=path_to_subset,
36
47
  temporary_path=temporary_path,
37
48
  path_to_template_file_and_extension=path_to_template_file_and_extension,
38
49
  **kwargs)
39
50
  extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
40
51
  if extension == '.xlsx':
41
- ExcelTemplateCreator().alter_excel_template(
42
- path_to_template_file_and_extension=path_to_template_file_and_extension,
43
- temporary_path=temporary_path, instantiated_attributes=instantiated_attributes, **kwargs)
52
+ self.alter_excel_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
53
+ temporary_path=temporary_path,
54
+ path_to_subset=path_to_subset, instantiated_attributes=instantiated_attributes,
55
+ **kwargs)
44
56
  elif extension == '.csv':
45
- CsvTemplateCreator().determine_multiplicity_csv(
46
- path_to_template_file_and_extension=path_to_template_file_and_extension,
47
- path_to_subset=path_to_subset,
48
- temporary_path=temporary_path,
49
- **kwargs)
57
+ self.determine_multiplicity_csv(path_to_template_file_and_extension=path_to_template_file_and_extension,
58
+ path_to_subset=path_to_subset,
59
+ instantiated_attributes=instantiated_attributes,
60
+ temporary_path=temporary_path,
61
+ **kwargs)
50
62
 
51
63
  def generate_basic_template(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
52
64
  temporary_path: Path, **kwargs):
53
65
  collector = self._load_collector_from_subset_path(path_to_subset=path_to_subset)
54
66
  otl_objects = []
55
67
  amount_of_examples = kwargs.get('amount_of_examples', 0)
56
- class_list = self.filters_assets_by_subset(path_to_subset=path_to_subset, **kwargs)
57
68
 
58
- for class_object in list(class_list):
69
+ for class_object in list(filter(lambda cl: cl.abstract == 0, collector.classes)):
59
70
  model_directory = None
60
71
  if kwargs is not None:
61
72
  model_directory = kwargs.get('model_directory', None)
@@ -73,27 +84,72 @@ class SubsetTemplateCreator:
73
84
  instance.fill_with_dummy_data()
74
85
  otl_objects.append(instance)
75
86
 
87
+ # TODO: check if this is needed, as the above line should cover this
88
+ attributen = collector.find_attributes_by_class(class_object)
89
+ for attribute_object in attributen:
90
+ attr = getattr(instance, '_' + attribute_object.name)
91
+ attr.fill_with_dummy_data()
76
92
  converter = OtlmowConverter()
77
- converter.create_file_from_assets(filepath=temporary_path,
78
- list_of_objects=otl_objects, **kwargs)
93
+ converter.from_objects_to_file(file_path=temporary_path,
94
+ sequence_of_objects=otl_objects, **kwargs)
79
95
  path_is_split = kwargs.get('split_per_type', True)
80
96
  extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
81
97
  instantiated_attributes = []
82
98
  if path_is_split is False or extension == '.xlsx':
83
- instantiated_attributes = converter.create_assets_from_file(filepath=temporary_path,
99
+ instantiated_attributes = converter.from_file_to_objects(file_path=temporary_path,
84
100
  path_to_subset=path_to_subset)
85
101
  return instantiated_attributes
86
102
 
87
103
  @classmethod
88
- def filters_assets_by_subset(cls, path_to_subset: Path, **kwargs):
89
- list_of_otl_object_uri = kwargs.get('list_of_otl_objectUri', None)
90
- collector = cls._load_collector_from_subset_path(path_to_subset=path_to_subset)
91
- if list_of_otl_object_uri is None:
92
- return [x for x in collector.classes if x.abstract == 0]
104
+ def alter_excel_template(cls, path_to_template_file_and_extension: Path, path_to_subset: Path,
105
+ instantiated_attributes: List, temporary_path, **kwargs):
106
+ generate_choice_list = kwargs.get('generate_choice_list', False)
107
+ add_geo_artefact = kwargs.get('add_geo_artefact', False)
108
+ add_attribute_info = kwargs.get('add_attribute_info', False)
109
+ highlight_deprecated_attributes = kwargs.get('highlight_deprecated_attributes', False)
110
+ amount_of_examples = kwargs.get('amount_of_examples', 0)
111
+ wb = load_workbook(temporary_path)
112
+ wb.create_sheet('Keuzelijsten')
113
+ # Volgorde is belangrijk! Eerst rijen verwijderen indien nodig dan choice list toevoegen,
114
+ # staat namelijk vast op de kolom en niet het attribuut in die kolom
115
+ if add_geo_artefact is False:
116
+ cls.remove_geo_artefact_excel(workbook=wb)
117
+ if generate_choice_list:
118
+ cls.add_choice_list_excel(workbook=wb, instantiated_attributes=instantiated_attributes,
119
+ path_to_subset=path_to_subset)
120
+ cls.add_mock_data_excel(workbook=wb, rows_of_examples=amount_of_examples)
121
+ if highlight_deprecated_attributes:
122
+ cls.check_for_deprecated_attributes(workbook=wb, instantiated_attributes=instantiated_attributes)
123
+ if add_attribute_info:
124
+ cls.add_attribute_info_excel(workbook=wb, instantiated_attributes=instantiated_attributes)
125
+ cls.design_workbook_excel(workbook=wb)
126
+ wb.save(path_to_template_file_and_extension)
127
+ file_location = os.path.dirname(temporary_path)
128
+ [f.unlink() for f in Path(file_location).glob("*") if f.is_file()]
129
+
130
+ def determine_multiplicity_csv(self, path_to_template_file_and_extension: Path, path_to_subset: Path,
131
+ instantiated_attributes: List, temporary_path: Path, **kwargs):
132
+ path_is_split = kwargs.get('split_per_type', True)
133
+ if path_is_split is False:
134
+ self.alter_csv_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
135
+ temporary_path=temporary_path, path_to_subset=path_to_subset, **kwargs)
93
136
  else:
94
- collector = cls._load_collector_from_subset_path(path_to_subset=path_to_subset)
95
- filtered_list = [x for x in collector.classes if x.objectUri in list_of_otl_object_uri]
96
- return filtered_list
137
+ self.multiple_csv_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
138
+ temporary_path=temporary_path,
139
+ path_to_subset=path_to_subset, instantiated_attributes=instantiated_attributes,
140
+ **kwargs)
141
+ file_location = os.path.dirname(temporary_path)
142
+ [f.unlink() for f in Path(file_location).glob("*") if f.is_file()]
143
+
144
+ @classmethod
145
+ def filters_assets_by_subset(cls, path_to_subset: Path, list_of_otl_objectUri: [str] = None):
146
+ if list_of_otl_objectUri is None:
147
+ list_of_otl_objectUri = []
148
+
149
+ collector = cls._load_collector_from_subset_path(path_to_subset=path_to_subset)
150
+ if list_of_otl_objectUri == []:
151
+ return [x for x in collector.classes]
152
+ return [x for x in collector.classes if x.objectUri in list_of_otl_objectUri]
97
153
 
98
154
  @staticmethod
99
155
  def _try_getting_settings_of_converter() -> Path:
@@ -101,22 +157,309 @@ class SubsetTemplateCreator:
101
157
  return converter_path / 'settings_otlmow_converter.json'
102
158
 
103
159
  @classmethod
104
- def return_temp_path(cls, path_to_template_file_and_extension: Path):
160
+ def design_workbook_excel(cls, workbook):
161
+ for sheet in workbook:
162
+ dim_holder = DimensionHolder(worksheet=sheet)
163
+ for col in range(sheet.min_column, sheet.max_column + 1):
164
+ dim_holder[get_column_letter(col)] = ColumnDimension(sheet, min=col, max=col, width=20)
165
+ sheet.column_dimensions = dim_holder
166
+
167
+ @classmethod
168
+ def add_attribute_info_excel(cls, workbook, instantiated_attributes: List):
169
+ dotnotation_module = DotnotationHelper()
170
+ for sheet in workbook:
171
+ if sheet == workbook['Keuzelijsten']:
172
+ break
173
+ filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
174
+ single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
175
+ sheet.insert_rows(1)
176
+ for rows in sheet.iter_rows(min_row=2, max_row=2, min_col=1):
177
+ for cell in rows:
178
+ if cell.value == 'typeURI':
179
+ value = 'De URI van het object volgens https://www.w3.org/2001/XMLSchema#anyURI .'
180
+ elif cell.value.find('[DEPRECATED]') != -1:
181
+ strip = cell.value.split(' ')
182
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
183
+ strip[1])
184
+ value = dotnotation_attribute.definition
185
+ else:
186
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
187
+ cell.value)
188
+ value = dotnotation_attribute.definition
189
+
190
+ sheet.cell(row=1, column=cell.column, value=value)
191
+ sheet.cell(row=1, column=cell.column).fill = PatternFill(start_color="808080", end_color="808080",
192
+ fill_type="solid")
193
+
194
+ @classmethod
195
+ def check_for_deprecated_attributes(cls, workbook, instantiated_attributes: List):
196
+ dotnotation_module = DotnotationHelper()
197
+ for sheet in workbook:
198
+ if sheet == workbook['Keuzelijsten']:
199
+ break
200
+ filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
201
+ single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
202
+ for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=2):
203
+ for cell in rows:
204
+ is_deprecated = False
205
+ if cell.value.count('.') == 1:
206
+ dot_split = cell.value.split('.')
207
+ attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
208
+ dot_split[0])
209
+
210
+ if len(attribute.deprecated_version) > 0:
211
+ is_deprecated = True
212
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
213
+ cell.value)
214
+ if len(dotnotation_attribute.deprecated_version) > 0:
215
+ is_deprecated = True
216
+
217
+ if is_deprecated:
218
+ cell.value = '[DEPRECATED] ' + cell.value
219
+
220
+ @classmethod
221
+ def find_uri_in_sheet(cls, sheet):
222
+ filter_uri = None
223
+ for row in sheet.iter_rows(min_row=1, max_row=1):
224
+ for cell in row:
225
+ if cell.value == 'typeURI':
226
+ row_index = cell.row
227
+ column_index = cell.column
228
+ filter_uri = sheet.cell(row=row_index + 1, column=column_index).value
229
+ return filter_uri
230
+
231
+ @classmethod
232
+ def remove_geo_artefact_excel(cls, workbook):
233
+ for sheet in workbook:
234
+ for row in sheet.iter_rows(min_row=1, max_row=1):
235
+ for cell in row:
236
+ if cell.value == 'geometry':
237
+ sheet.delete_cols(cell.column)
238
+
239
+ @classmethod
240
+ def add_choice_list_excel(cls, workbook, instantiated_attributes: List, path_to_subset: Path):
241
+ choice_list_dict = {}
242
+ dotnotation_module = DotnotationHelper()
243
+ for sheet in workbook:
244
+ if sheet == workbook['Keuzelijsten']:
245
+ break
246
+ filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
247
+ single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
248
+ for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=2):
249
+ for cell in rows:
250
+ if cell.value.find('[DEPRECATED]') != -1:
251
+ strip = cell.value.split(' ')
252
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
253
+ strip[1])
254
+ else:
255
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
256
+ cell.value)
257
+
258
+ if issubclass(dotnotation_attribute.field, KeuzelijstField):
259
+ name = dotnotation_attribute.field.naam
260
+ valid_options = [v.invulwaarde for k, v in dotnotation_attribute.field.options.items()
261
+ if v.status != 'verwijderd']
262
+ if dotnotation_attribute.field.naam in choice_list_dict:
263
+ column = choice_list_dict[dotnotation_attribute.field.naam]
264
+ else:
265
+ choice_list_dict = cls.add_choice_list_to_sheet(workbook=workbook, name=name,
266
+ options=valid_options,
267
+ choice_list_dict=choice_list_dict)
268
+ column = choice_list_dict[dotnotation_attribute.field.naam]
269
+ print(column)
270
+ option_list = []
271
+ for option in valid_options:
272
+ option_list.append(option)
273
+ start_range = f"${column}$2"
274
+ end_range = f"${column}${len(valid_options) + 1}"
275
+ data_val = DataValidation(type="list", formula1=f"Keuzelijsten!{start_range}:{end_range}",
276
+ allowBlank=True)
277
+ sheet.add_data_validation(data_val)
278
+ data_val.add(f'{get_column_letter(cell.column)}2:{get_column_letter(cell.column)}1000')
279
+ if issubclass(dotnotation_attribute.field, BooleanField):
280
+ data_validation = DataValidation(type="list", formula1='"TRUE,FALSE,-"', allow_blank=True)
281
+ column = cell.column
282
+ sheet.add_data_validation(data_validation)
283
+ data_validation.add(f'{get_column_letter(column)}2:{get_column_letter(column)}1000')
284
+ sheet.add_data_validation(data_validation)
285
+
286
+ @classmethod
287
+ def add_mock_data_excel(cls, workbook, rows_of_examples: int):
288
+ for sheet in workbook:
289
+ if sheet == workbook["Keuzelijsten"]:
290
+ break
291
+ if rows_of_examples == 0:
292
+ for rows in sheet.iter_rows(min_row=2, max_row=2):
293
+ for cell in rows:
294
+ cell.value = ''
295
+
296
+ @classmethod
297
+ def remove_geo_artefact_csv(cls, header, data):
298
+ if 'geometry' in header:
299
+ deletion_index = header.index('geometry')
300
+ header.remove('geometry')
301
+ for d in data:
302
+ d.pop(deletion_index)
303
+ return [header, data]
304
+
305
+ @classmethod
306
+ def multiple_csv_template(cls, path_to_template_file_and_extension, path_to_subset, temporary_path,
307
+ instantiated_attributes, **kwargs):
308
+ file_location = os.path.dirname(path_to_template_file_and_extension)
105
309
  tempdir = Path(tempfile.gettempdir()) / 'temp-otlmow'
106
- if not tempdir.exists():
107
- os.makedirs(tempdir)
108
- test = ntpath.basename(path_to_template_file_and_extension)
109
- temporary_path = Path(tempdir) / test
110
- return temporary_path
310
+ print(file_location)
311
+ file_name = ntpath.basename(path_to_template_file_and_extension)
312
+ split_file_name = file_name.split('.')
313
+ things_in_there = os.listdir(tempdir)
314
+ csv_templates = [x for x in things_in_there if x.startswith(split_file_name[0] + '_')]
315
+ print(csv_templates)
316
+ for file in csv_templates:
317
+ test_template_loc = Path(os.path.dirname(path_to_template_file_and_extension)) / file
318
+ temp_loc = Path(tempdir) / file
319
+ cls.alter_csv_template(path_to_template_file_and_extension=test_template_loc, temporary_path=temp_loc,
320
+ path_to_subset=path_to_subset, **kwargs)
321
+
322
+ @classmethod
323
+ def alter_csv_template(cls, path_to_template_file_and_extension, path_to_subset, temporary_path,
324
+ **kwargs):
325
+ converter = OtlmowConverter()
326
+ instantiated_attributes = converter.from_file_to_objects(file_path=temporary_path,
327
+ path_to_subset=path_to_subset)
328
+ header = []
329
+ data = []
330
+ delimiter = ';'
331
+ add_geo_artefact = kwargs.get('add_geo_artefact', False)
332
+ add_attribute_info = kwargs.get('add_attribute_info', False)
333
+ highlight_deprecated_attributes = kwargs.get('highlight_deprecated_attributes', False)
334
+ amount_of_examples = kwargs.get('amount_of_examples', 0)
335
+ quote_char = '"'
336
+ with open(temporary_path, 'r+', encoding='utf-8') as csvfile:
337
+ new_file = open(path_to_template_file_and_extension, 'w', encoding='utf-8')
338
+ reader = csv.reader(csvfile, delimiter=delimiter, quotechar=quote_char)
339
+ for row_nr, row in enumerate(reader):
340
+ if row_nr == 0:
341
+ header = row
342
+ else:
343
+ data.append(row)
344
+ if add_geo_artefact is False:
345
+ [header, data] = cls.remove_geo_artefact_csv(header=header, data=data)
346
+ if add_attribute_info:
347
+ [info, header] = cls.add_attribute_info_csv(header=header, data=data,
348
+ instantiated_attributes=instantiated_attributes)
349
+ new_file.write(delimiter.join(info) + '\n')
350
+ data = cls.add_mock_data_csv(header=header, data=data, rows_of_examples=amount_of_examples)
351
+ if highlight_deprecated_attributes:
352
+ header = cls.highlight_deprecated_attributes_csv(header=header, data=data,
353
+ instantiated_attributes=instantiated_attributes)
354
+ new_file.write(delimiter.join(header) + '\n')
355
+ for d in data:
356
+ new_file.write(delimiter.join(d) + '\n')
357
+ new_file.close()
358
+
359
+ @classmethod
360
+ def add_attribute_info_csv(cls, header, data, instantiated_attributes):
361
+ info_data = []
362
+ info_data.extend(header)
363
+ found_uri = []
364
+ dotnotation_module = DotnotationHelper()
365
+ uri_index = cls.find_uri_in_csv(header)
366
+ for d in data:
367
+ if d[uri_index] not in found_uri:
368
+ found_uri.append(d[uri_index])
369
+ for uri in found_uri:
370
+ single_object = next(x for x in instantiated_attributes if x.typeURI == uri)
371
+ for dotnototation_title in info_data:
372
+ if dotnototation_title == 'typeURI':
373
+ index = info_data.index(dotnototation_title)
374
+ info_data[index] = 'De URI van het object volgens https://www.w3.org/2001/XMLSchema#anyURI .'
375
+ else:
376
+ index = info_data.index(dotnototation_title)
377
+ try:
378
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(
379
+ single_object, dotnototation_title)
380
+ except AttributeError as e:
381
+ continue
382
+ info_data[index] = dotnotation_attribute.definition
383
+ return [info_data, header]
384
+
385
+ @classmethod
386
+ def add_mock_data_csv(cls, header, data, rows_of_examples):
387
+ if rows_of_examples == 0:
388
+ data = []
389
+ return data
390
+
391
+ @classmethod
392
+ def highlight_deprecated_attributes_csv(cls, header, data, instantiated_attributes):
393
+ found_uri = []
394
+ dotnotation_module = DotnotationHelper()
395
+ uri_index = cls.find_uri_in_csv(header)
396
+ for d in data:
397
+ if d[uri_index] not in found_uri:
398
+ found_uri.append(d[uri_index])
399
+ for uri in found_uri:
400
+ single_object = next(x for x in instantiated_attributes if x.typeURI == uri)
401
+ for dotnototation_title in header:
402
+ if dotnototation_title == 'typeURI':
403
+ continue
404
+ else:
405
+ index = header.index(dotnototation_title)
406
+ value = header[index]
407
+ try:
408
+ is_deprecated = False
409
+ if dotnototation_title.count('.') == 1:
410
+ dot_split = dotnototation_title.split('.')
411
+ attribute = dotnotation_module.get_attribute_by_dotnotation(single_object,
412
+ dot_split[0])
413
+
414
+ if len(attribute.deprecated_version) > 0:
415
+ is_deprecated = True
416
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_object,
417
+ dotnototation_title)
418
+ if len(dotnotation_attribute.deprecated_version) > 0:
419
+ is_deprecated = True
420
+ except AttributeError:
421
+ continue
422
+ if is_deprecated:
423
+ header[index] = "[DEPRECATED] " + value
424
+ return header
425
+
426
+ @classmethod
427
+ def find_uri_in_csv(cls, header):
428
+ filter_uri = None
429
+ if 'typeURI' in header:
430
+ filter_uri = header.index('typeURI')
431
+ return filter_uri
432
+
433
+ @classmethod
434
+ def add_choice_list_to_sheet(cls, workbook, name, options, choice_list_dict):
435
+ active_sheet = workbook['Keuzelijsten']
436
+ print(options)
437
+ row_nr = 2
438
+ for rows in active_sheet.iter_rows(min_row=1, max_row=1, min_col=1, max_col=700):
439
+ for cell in rows:
440
+ if cell.value is None:
441
+ cell.value = name
442
+ column_nr = cell.column
443
+ for option in options:
444
+ print(option)
445
+ active_sheet.cell(row=row_nr, column=column_nr, value=option)
446
+ row_nr += 1
447
+ print(row_nr)
448
+ choice_list_dict[name] = get_column_letter(column_nr)
449
+ break
450
+ return choice_list_dict
111
451
 
112
452
 
113
453
  if __name__ == '__main__':
114
454
  subset_tool = SubsetTemplateCreator()
115
455
  subset_location = Path(ROOT_DIR) / 'UnitTests' / 'Subset' / 'Flitspaal_noAgent3.0.db'
116
- xls_location = Path(ROOT_DIR) / 'UnitTests' / 'Subset' / 'testFileStorage' / 'template_file.xlsx'
456
+ # directory = Path(ROOT_DIR) / 'UnitTests' / 'TestClasses'
457
+ # Slash op het einde toevoegen verandert weinig of niks aan het resultaat
458
+ # directory = os.path.join(directory, '')
459
+ xls_location = Path(ROOT_DIR) / 'UnitTests' / 'Subset' / 'testFileStorage' / 'template_file.csv'
117
460
  subset_tool.generate_template_from_subset(path_to_subset=subset_location,
118
461
  path_to_template_file_and_extension=xls_location, add_attribute_info=True,
119
462
  highlight_deprecated_attributes=True,
120
463
  amount_of_examples=5,
121
464
  generate_choice_list=True,
122
- )
465
+ split_per_type=False)
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
- Name: otlmow-template
3
- Version: 0.3
4
- Author-email: David Vlaminck <david.vlaminck@mow.vlaanderen.be>
2
+ Name: otlmow_template
3
+ Version: 0.4
4
+ Author-email: David Vlaminck <david.vlaminck@mow.vlaanderen.be>, Jasper Berton <jasperberton1@telenet.be>
5
5
  License: GNU GENERAL PUBLIC LICENSE
6
6
  Version 3, 29 June 2007
7
7
 
@@ -696,8 +696,8 @@ Classifier: Topic :: Software Development :: Quality Assurance
696
696
  Requires-Python: >=3.8
697
697
  Description-Content-Type: text/markdown
698
698
  License-File: LICENSE
699
- Requires-Dist: otlmow-converter >=0.14
700
- Requires-Dist: otlmow-modelbuilder >=0.11
699
+ Requires-Dist: otlmow-converter>=0.14
700
+ Requires-Dist: otlmow-modelbuilder>=0.11
701
701
 
702
702
  # OTLMOW-Template
703
703
  [![PyPI](https://img.shields.io/pypi/v/otlmow-template?label=latest%20release)](https://pypi.org/project/otlmow-template/)
@@ -0,0 +1,10 @@
1
+ otlmow_template/CsvTemplateCreator.py,sha256=PQq2zGmliWk0N9bhYNB7ZEa8PWV16OTbvoHh3--qCMs,7538
2
+ otlmow_template/ExcelTemplateCreator.py,sha256=wW-7Uq2Gzr1vHYMO1I7TtqZSBTVFFSWotHvjwzCelV4,10853
3
+ otlmow_template/SubsetTemplateCreator.py,sha256=MfmJeVuU-c-jbYifI3AaxSk6ok_ja_x5Mz0Hryt9n7s,25152
4
+ otlmow_template/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
6
+ otlmow_template-0.4.dist-info/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
7
+ otlmow_template-0.4.dist-info/METADATA,sha256=Kxx_tIYNn19guxiAB0hdzrJDpc3bENpPzkYRCA1HXIA,43928
8
+ otlmow_template-0.4.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
9
+ otlmow_template-0.4.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
10
+ otlmow_template-0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- otlmow_template/CsvTemplateCreator.py,sha256=iGdqfTv1itB6931pEkuVG-eYpGM_EW2LcbTDcy0Tdgk,7758
2
- otlmow_template/ExcelTemplateCreator.py,sha256=wW-7Uq2Gzr1vHYMO1I7TtqZSBTVFFSWotHvjwzCelV4,10853
3
- otlmow_template/SubsetTemplateCreator.py,sha256=NB8M7Rn05wtquAqEyj92pxJYtouvX8tPSJbwfU6q9fc,6192
4
- otlmow_template/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
6
- otlmow_template-0.3.dist-info/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
7
- otlmow_template-0.3.dist-info/METADATA,sha256=_wFD-wbiYEjSvdTwA9mcaDx_wMwfVyUbECcxZGPa1qw,43888
8
- otlmow_template-0.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
9
- otlmow_template-0.3.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
10
- otlmow_template-0.3.dist-info/RECORD,,