otlmow-template 1.2__tar.gz → 1.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.
- {otlmow_template-1.2 → otlmow_template-1.3}/PKG-INFO +2 -2
- {otlmow_template-1.2 → otlmow_template-1.3}/otlmow_template/SubsetTemplateCreator.py +78 -14
- {otlmow_template-1.2 → otlmow_template-1.3}/otlmow_template.egg-info/PKG-INFO +2 -2
- {otlmow_template-1.2 → otlmow_template-1.3}/otlmow_template.egg-info/requires.txt +1 -1
- {otlmow_template-1.2 → otlmow_template-1.3}/pyproject.toml +2 -2
- {otlmow_template-1.2 → otlmow_template-1.3}/LICENSE +0 -0
- {otlmow_template-1.2 → otlmow_template-1.3}/README.md +0 -0
- {otlmow_template-1.2 → otlmow_template-1.3}/otlmow_template/Exceptions/MissingTypeUriException.py +0 -0
- {otlmow_template-1.2 → otlmow_template-1.3}/otlmow_template.egg-info/SOURCES.txt +0 -0
- {otlmow_template-1.2 → otlmow_template-1.3}/otlmow_template.egg-info/dependency_links.txt +0 -0
- {otlmow_template-1.2 → otlmow_template-1.3}/otlmow_template.egg-info/top_level.txt +0 -0
- {otlmow_template-1.2 → otlmow_template-1.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: otlmow_template
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3
|
|
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
|
|
@@ -697,7 +697,7 @@ Classifier: Topic :: Software Development :: Quality Assurance
|
|
|
697
697
|
Requires-Python: >=3.9
|
|
698
698
|
Description-Content-Type: text/markdown
|
|
699
699
|
License-File: LICENSE
|
|
700
|
-
Requires-Dist: otlmow-converter>=1.
|
|
700
|
+
Requires-Dist: otlmow-converter>=1.14
|
|
701
701
|
Requires-Dist: otlmow-modelbuilder>=0.27
|
|
702
702
|
Provides-Extra: test
|
|
703
703
|
Requires-Dist: pytest; extra == "test"
|
|
@@ -16,13 +16,15 @@ from openpyxl.worksheet.datavalidation import DataValidation
|
|
|
16
16
|
from openpyxl.worksheet.dimensions import DimensionHolder, ColumnDimension
|
|
17
17
|
from openpyxl.worksheet.worksheet import Worksheet
|
|
18
18
|
from otlmow_converter.DotnotationHelper import DotnotationHelper
|
|
19
|
+
from otlmow_converter.Exceptions.UnknownExcelError import UnknownExcelError
|
|
19
20
|
from otlmow_converter.OtlmowConverter import OtlmowConverter
|
|
20
21
|
from otlmow_model.OtlmowModel.BaseClasses.BooleanField import BooleanField
|
|
21
22
|
from otlmow_model.OtlmowModel.BaseClasses.KeuzelijstField import KeuzelijstField
|
|
22
23
|
from otlmow_model.OtlmowModel.BaseClasses.OTLObject import dynamic_create_instance_from_uri, OTLObject, \
|
|
23
|
-
get_attribute_by_name
|
|
24
|
+
get_attribute_by_name, dynamic_create_type_from_uri
|
|
25
|
+
from otlmow_model.OtlmowModel.Helpers.GenericHelper import get_ns_and_name_from_uri
|
|
26
|
+
from otlmow_model.OtlmowModel.Helpers.RelationCreator import create_betrokkenerelation, create_relation
|
|
24
27
|
from otlmow_model.OtlmowModel.Helpers.generated_lists import get_hardcoded_relation_dict
|
|
25
|
-
from otlmow_modelbuilder.HelperFunctions import get_ns_and_name_from_uri
|
|
26
28
|
from otlmow_modelbuilder.OSLOCollector import OSLOCollector
|
|
27
29
|
from otlmow_modelbuilder.SQLDataClasses.OSLOClass import OSLOClass
|
|
28
30
|
|
|
@@ -184,7 +186,7 @@ class SubsetTemplateCreator:
|
|
|
184
186
|
|
|
185
187
|
while True:
|
|
186
188
|
for oslo_class in [cl for cl in filtered_class_list if cl.abstract == 0]:
|
|
187
|
-
if
|
|
189
|
+
if oslo_class.objectUri in relation_dict:
|
|
188
190
|
continue
|
|
189
191
|
|
|
190
192
|
for _ in range(amount_objects_to_create):
|
|
@@ -194,12 +196,18 @@ class SubsetTemplateCreator:
|
|
|
194
196
|
if otl_object is not None:
|
|
195
197
|
otl_objects.append(otl_object)
|
|
196
198
|
created = len(otl_objects)
|
|
197
|
-
unique_ids = len({obj.assetId.identificator if
|
|
199
|
+
unique_ids = len({obj.assetId.identificator if obj.typeURI != 'http://purl.org/dc/terms/Agent' else obj.agentId.identificator
|
|
198
200
|
for obj in otl_objects})
|
|
199
201
|
if created == unique_ids:
|
|
200
202
|
break
|
|
201
203
|
otl_objects = []
|
|
202
204
|
|
|
205
|
+
if not ignore_relations:
|
|
206
|
+
non_relations_class_uris = [cl.objectUri for cl in filtered_class_list
|
|
207
|
+
if cl.abstract == 0 and cl.objectUri not in relation_dict]
|
|
208
|
+
cls.append_relations_to_objects(otl_objects=otl_objects, collector=collector,
|
|
209
|
+
class_uris_filter=non_relations_class_uris, model_directory=model_directory)
|
|
210
|
+
|
|
203
211
|
return otl_objects
|
|
204
212
|
|
|
205
213
|
@classmethod
|
|
@@ -222,7 +230,7 @@ class SubsetTemplateCreator:
|
|
|
222
230
|
|
|
223
231
|
for oslo_class in [cl for cl in filtered_class_list if cl.abstract == 0]:
|
|
224
232
|
await sleep(0)
|
|
225
|
-
if
|
|
233
|
+
if oslo_class.objectUri in relation_dict:
|
|
226
234
|
continue
|
|
227
235
|
|
|
228
236
|
for _ in range(amount_objects_to_create):
|
|
@@ -233,6 +241,12 @@ class SubsetTemplateCreator:
|
|
|
233
241
|
if otl_object is not None:
|
|
234
242
|
otl_objects.append(otl_object)
|
|
235
243
|
|
|
244
|
+
if not ignore_relations:
|
|
245
|
+
non_relations_class_uris = [cl.objectUri for cl in filtered_class_list
|
|
246
|
+
if cl.abstract == 0 and cl.objectUri not in relation_dict]
|
|
247
|
+
cls.append_relations_to_objects(otl_objects=otl_objects, collector=collector,
|
|
248
|
+
class_uris_filter=non_relations_class_uris, model_directory=model_directory)
|
|
249
|
+
|
|
236
250
|
return otl_objects
|
|
237
251
|
|
|
238
252
|
@classmethod
|
|
@@ -249,15 +263,23 @@ class SubsetTemplateCreator:
|
|
|
249
263
|
if filter_attributes_by_subset:
|
|
250
264
|
for attribute_object in collector.find_attributes_by_class(oslo_class):
|
|
251
265
|
attr = get_attribute_by_name(instance, attribute_object.name)
|
|
252
|
-
if attr is
|
|
253
|
-
attr.fill_with_dummy_data()
|
|
254
|
-
else:
|
|
266
|
+
if attr is None:
|
|
255
267
|
logging.warning(f'Attribute {attribute_object.name} not found in class {oslo_class.objectUri}')
|
|
268
|
+
elif attr.naam == 'isActief':
|
|
269
|
+
attr.set_waarde(True)
|
|
270
|
+
else:
|
|
271
|
+
attr.fill_with_dummy_data()
|
|
256
272
|
else:
|
|
257
273
|
for attr in instance:
|
|
258
|
-
if attr.naam
|
|
274
|
+
if attr.naam == 'isActief':
|
|
275
|
+
attr.set_waarde(True)
|
|
276
|
+
elif attr.naam != 'geometry':
|
|
259
277
|
attr.fill_with_dummy_data()
|
|
278
|
+
|
|
260
279
|
with contextlib.suppress(AttributeError):
|
|
280
|
+
assetId_attr = get_attribute_by_name(instance, 'assetId')
|
|
281
|
+
if assetId_attr is not None:
|
|
282
|
+
assetId_attr.fill_with_dummy_data()
|
|
261
283
|
if add_geometry:
|
|
262
284
|
geo_attr = get_attribute_by_name(instance, 'geometry')
|
|
263
285
|
if geo_attr is not None:
|
|
@@ -304,7 +326,10 @@ class SubsetTemplateCreator:
|
|
|
304
326
|
if split_per_type:
|
|
305
327
|
for type_uri, typed_instances in classes_dict.items():
|
|
306
328
|
ns, name = get_ns_and_name_from_uri(type_uri)
|
|
307
|
-
|
|
329
|
+
ns_name = f'{ns}_{name}'
|
|
330
|
+
if name == 'Agent':
|
|
331
|
+
ns_name = 'Agent'
|
|
332
|
+
class_file_path = file_path.parent / f'{file_path.stem}_{ns_name}.csv'
|
|
308
333
|
cls.alter_csv_file(add_attribute_info=add_attribute_info, add_deprecated=add_deprecated,
|
|
309
334
|
dummy_data_rows=dummy_data_rows, instances=typed_instances, file_path=class_file_path)
|
|
310
335
|
else:
|
|
@@ -319,7 +344,10 @@ class SubsetTemplateCreator:
|
|
|
319
344
|
for type_uri, typed_instances in classes_dict.items():
|
|
320
345
|
await sleep(0)
|
|
321
346
|
ns, name = get_ns_and_name_from_uri(type_uri)
|
|
322
|
-
|
|
347
|
+
ns_name = f'{ns}_{name}'
|
|
348
|
+
if name == 'Agent':
|
|
349
|
+
ns_name = 'Agent'
|
|
350
|
+
class_file_path = file_path.parent / f'{file_path.stem}_{ns_name}.csv'
|
|
323
351
|
cls.alter_csv_file(add_attribute_info=add_attribute_info,
|
|
324
352
|
dummy_data_rows=dummy_data_rows, instances=typed_instances, add_deprecated=add_deprecated,
|
|
325
353
|
file_path=class_file_path)
|
|
@@ -354,7 +382,14 @@ class SubsetTemplateCreator:
|
|
|
354
382
|
deprecated_attributes_row.append('')
|
|
355
383
|
continue
|
|
356
384
|
|
|
357
|
-
|
|
385
|
+
try:
|
|
386
|
+
attribute = DotnotationHelper.get_attribute_by_dotnotation(instance, header)
|
|
387
|
+
except AttributeError:
|
|
388
|
+
if add_attribute_info:
|
|
389
|
+
collected_attribute_info_row.append('')
|
|
390
|
+
if add_deprecated:
|
|
391
|
+
deprecated_attributes_row.append('')
|
|
392
|
+
continue
|
|
358
393
|
|
|
359
394
|
if add_attribute_info:
|
|
360
395
|
collected_attribute_info_row.append(attribute.definition)
|
|
@@ -362,7 +397,7 @@ class SubsetTemplateCreator:
|
|
|
362
397
|
if add_deprecated:
|
|
363
398
|
deprecated_attributes_row.append('DEPRECATED' if attribute.deprecated_version else '')
|
|
364
399
|
|
|
365
|
-
with open(file_path, 'w') as file:
|
|
400
|
+
with open(file_path, 'w', newline='', encoding='utf-8') as file:
|
|
366
401
|
csv_writer = csv.writer(file, delimiter=';', quotechar=quote_char, quoting=csv.QUOTE_MINIMAL)
|
|
367
402
|
if add_attribute_info:
|
|
368
403
|
csv_writer.writerow(collected_attribute_info_row)
|
|
@@ -397,7 +432,11 @@ class SubsetTemplateCreator:
|
|
|
397
432
|
instances: [OTLObject], sheet: Worksheet, add_deprecated: bool, workbook: Workbook,
|
|
398
433
|
dummy_data_rows: int):
|
|
399
434
|
type_uri = cls.get_uri_from_sheet_name(sheet.title)
|
|
400
|
-
instance = next(x for x in instances if x.typeURI == type_uri)
|
|
435
|
+
instance = next((x for x in instances if x.typeURI == type_uri), None)
|
|
436
|
+
if instance is None:
|
|
437
|
+
instance = next((x for x in instances if x.typeURI.startswith(type_uri)), None)
|
|
438
|
+
if instance is None:
|
|
439
|
+
raise UnknownExcelError(f'When creating a template, no instance could be created for {type_uri}')
|
|
401
440
|
|
|
402
441
|
boolean_validation = DataValidation(type="list", formula1='"TRUE,FALSE,"', allow_blank=True)
|
|
403
442
|
sheet.add_data_validation(boolean_validation)
|
|
@@ -610,3 +649,28 @@ class SubsetTemplateCreator:
|
|
|
610
649
|
raise ValueError('Sheet title does not contain a #')
|
|
611
650
|
class_ns, class_name = title.split('#', maxsplit=1)
|
|
612
651
|
return short_to_long_ns.get(class_ns, class_ns) + class_name
|
|
652
|
+
|
|
653
|
+
@classmethod
|
|
654
|
+
def append_relations_to_objects(cls, otl_objects: [OTLObject], collector: OSLOCollector, class_uris_filter: [str],
|
|
655
|
+
model_directory: Path):
|
|
656
|
+
class_dict = defaultdict(list)
|
|
657
|
+
for instance in otl_objects:
|
|
658
|
+
class_dict[instance.typeURI].append(instance)
|
|
659
|
+
|
|
660
|
+
for class_uri in class_uris_filter:
|
|
661
|
+
for relation in collector.find_all_concrete_relations(objectUri=class_uri):
|
|
662
|
+
if class_uri != relation.bron_uri:
|
|
663
|
+
continue
|
|
664
|
+
for i, bron_instance in enumerate(class_dict[relation.bron_uri]):
|
|
665
|
+
doel_instance = class_dict[relation.doel_uri][i]
|
|
666
|
+
if relation.objectUri == 'https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#HeeftBetrokkene':
|
|
667
|
+
relation_instance = create_betrokkenerelation(rol='toezichter', source=bron_instance,
|
|
668
|
+
target=doel_instance, model_directory=model_directory)
|
|
669
|
+
else:
|
|
670
|
+
if relation.richting == 'Unspecified' and bron_instance.assetId.identificator > doel_instance.assetId.identificator:
|
|
671
|
+
continue
|
|
672
|
+
relation_type = dynamic_create_type_from_uri(class_uri=relation.objectUri, model_directory=model_directory)
|
|
673
|
+
relation_instance = create_relation(relation_type=relation_type, source=bron_instance,
|
|
674
|
+
target=doel_instance, model_directory=model_directory)
|
|
675
|
+
|
|
676
|
+
otl_objects.append(relation_instance)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: otlmow_template
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3
|
|
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
|
|
@@ -697,7 +697,7 @@ Classifier: Topic :: Software Development :: Quality Assurance
|
|
|
697
697
|
Requires-Python: >=3.9
|
|
698
698
|
Description-Content-Type: text/markdown
|
|
699
699
|
License-File: LICENSE
|
|
700
|
-
Requires-Dist: otlmow-converter>=1.
|
|
700
|
+
Requires-Dist: otlmow-converter>=1.14
|
|
701
701
|
Requires-Dist: otlmow-modelbuilder>=0.27
|
|
702
702
|
Provides-Extra: test
|
|
703
703
|
Requires-Dist: pytest; extra == "test"
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "otlmow_template"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.3"
|
|
8
8
|
authors = [{name = "David Vlaminck", email = "david.vlaminck@mow.vlaanderen.be"},
|
|
9
9
|
{name = "Jasper Berton", email = "jasperberton1@telenet.be"},]
|
|
10
10
|
readme = "README.md"
|
|
@@ -29,7 +29,7 @@ classifiers = [
|
|
|
29
29
|
]
|
|
30
30
|
requires-python = ">=3.9"
|
|
31
31
|
dependencies = [
|
|
32
|
-
'otlmow-converter >= 1.
|
|
32
|
+
'otlmow-converter >= 1.14',
|
|
33
33
|
'otlmow-modelbuilder >= 0.27'
|
|
34
34
|
]
|
|
35
35
|
|
|
File without changes
|
|
File without changes
|
{otlmow_template-1.2 → otlmow_template-1.3}/otlmow_template/Exceptions/MissingTypeUriException.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|