otlmow-template 1.3__py3-none-any.whl → 1.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.
- otlmow_template/SubsetTemplateCreator.py +88 -31
- {otlmow_template-1.3.dist-info → otlmow_template-1.4.dist-info}/METADATA +1 -1
- otlmow_template-1.4.dist-info/RECORD +7 -0
- otlmow_template-1.3.dist-info/RECORD +0 -7
- {otlmow_template-1.3.dist-info → otlmow_template-1.4.dist-info}/WHEEL +0 -0
- {otlmow_template-1.3.dist-info → otlmow_template-1.4.dist-info}/licenses/LICENSE +0 -0
- {otlmow_template-1.3.dist-info → otlmow_template-1.4.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import concurrent
|
|
1
3
|
import contextlib
|
|
2
4
|
import csv
|
|
3
5
|
import logging
|
|
4
6
|
import os
|
|
5
|
-
import shutil
|
|
6
|
-
import tempfile
|
|
7
7
|
from asyncio import sleep
|
|
8
8
|
from collections import defaultdict
|
|
9
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed, ALL_COMPLETED
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
|
|
11
12
|
from openpyxl.reader.excel import load_workbook
|
|
@@ -169,6 +170,34 @@ class SubsetTemplateCreator:
|
|
|
169
170
|
split_per_type=split_per_type, file_path=template_file_path, dummy_data_rows=dummy_data_rows,
|
|
170
171
|
instances=objects, add_deprecated=add_deprecated, add_attribute_info=add_attribute_info)
|
|
171
172
|
|
|
173
|
+
|
|
174
|
+
@classmethod
|
|
175
|
+
def create_x_objects(cls, oslo_class, add_geometry, collector, filter_attributes_by_subset, model_directory,
|
|
176
|
+
amount_objects_to_create):
|
|
177
|
+
if oslo_class.objectUri in cls.relation_dict:
|
|
178
|
+
return []
|
|
179
|
+
|
|
180
|
+
otl_objects = []
|
|
181
|
+
for _ in range(amount_objects_to_create):
|
|
182
|
+
otl_object = cls.generate_object_from_oslo_class(
|
|
183
|
+
oslo_class=oslo_class, add_geometry=add_geometry, collector=collector,
|
|
184
|
+
filter_attributes_by_subset=filter_attributes_by_subset, model_directory=model_directory)
|
|
185
|
+
if otl_object is not None:
|
|
186
|
+
otl_objects.append(otl_object)
|
|
187
|
+
return otl_objects
|
|
188
|
+
|
|
189
|
+
@classmethod
|
|
190
|
+
def get_number_of_cpus(cls) -> int:
|
|
191
|
+
import multiprocessing
|
|
192
|
+
cpu_count = multiprocessing.cpu_count()
|
|
193
|
+
if cpu_count is None or cpu_count == 0:
|
|
194
|
+
import os
|
|
195
|
+
cpu_count = os.cpu_count()
|
|
196
|
+
if cpu_count is None or cpu_count == 0:
|
|
197
|
+
cpu_count = 8
|
|
198
|
+
return cpu_count
|
|
199
|
+
|
|
200
|
+
|
|
172
201
|
@classmethod
|
|
173
202
|
def generate_objects_for_template(
|
|
174
203
|
cls, subset_path: Path, class_uris_filter: [str], filter_attributes_by_subset: bool,
|
|
@@ -179,22 +208,27 @@ class SubsetTemplateCreator:
|
|
|
179
208
|
"""
|
|
180
209
|
collector = cls._load_collector_from_subset_path(subset_path=subset_path)
|
|
181
210
|
filtered_class_list = cls.filters_classes_by_subset(collector=collector, class_uris_filter=class_uris_filter)
|
|
182
|
-
relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
|
|
211
|
+
cls.relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
|
|
183
212
|
|
|
184
213
|
amount_objects_to_create = max(1, dummy_data_rows)
|
|
185
214
|
otl_objects = []
|
|
186
215
|
|
|
187
216
|
while True:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
217
|
+
with ThreadPoolExecutor(max_workers=cls.get_number_of_cpus()) as executor:
|
|
218
|
+
futures = [
|
|
219
|
+
executor.submit(cls.create_x_objects, oslo_class, add_geometry, collector,
|
|
220
|
+
filter_attributes_by_subset, model_directory, amount_objects_to_create)
|
|
221
|
+
for oslo_class in [cl for cl in filtered_class_list if cl.abstract == 0]
|
|
222
|
+
]
|
|
223
|
+
while futures:
|
|
224
|
+
done, not_done = concurrent.futures.wait(futures, return_when=ALL_COMPLETED, timeout=60)
|
|
225
|
+
for future in as_completed(done):
|
|
226
|
+
otl_objects.extend(future.result())
|
|
227
|
+
futures = not_done
|
|
228
|
+
print(f'when using multiprocessing: {len(done)} done, {len(not_done)} not done')
|
|
229
|
+
if len(not_done) > 0:
|
|
230
|
+
print('restarting the loop with the not done ones')
|
|
191
231
|
|
|
192
|
-
for _ in range(amount_objects_to_create):
|
|
193
|
-
otl_object = cls.generate_object_from_oslo_class(
|
|
194
|
-
oslo_class=oslo_class, add_geometry=add_geometry, collector=collector,
|
|
195
|
-
filter_attributes_by_subset=filter_attributes_by_subset, model_directory=model_directory)
|
|
196
|
-
if otl_object is not None:
|
|
197
|
-
otl_objects.append(otl_object)
|
|
198
232
|
created = len(otl_objects)
|
|
199
233
|
unique_ids = len({obj.assetId.identificator if obj.typeURI != 'http://purl.org/dc/terms/Agent' else obj.agentId.identificator
|
|
200
234
|
for obj in otl_objects})
|
|
@@ -204,12 +238,30 @@ class SubsetTemplateCreator:
|
|
|
204
238
|
|
|
205
239
|
if not ignore_relations:
|
|
206
240
|
non_relations_class_uris = [cl.objectUri for cl in filtered_class_list
|
|
207
|
-
if cl.abstract == 0 and cl.objectUri not in relation_dict]
|
|
241
|
+
if cl.abstract == 0 and cl.objectUri not in cls.relation_dict]
|
|
208
242
|
cls.append_relations_to_objects(otl_objects=otl_objects, collector=collector,
|
|
209
243
|
class_uris_filter=non_relations_class_uris, model_directory=model_directory)
|
|
210
244
|
|
|
211
245
|
return otl_objects
|
|
212
246
|
|
|
247
|
+
@classmethod
|
|
248
|
+
async def create_x_objects_async(cls, oslo_class, add_geometry, collector, filter_attributes_by_subset,
|
|
249
|
+
model_directory,
|
|
250
|
+
amount_objects_to_create):
|
|
251
|
+
if oslo_class.objectUri in cls.relation_dict:
|
|
252
|
+
return []
|
|
253
|
+
|
|
254
|
+
otl_objects = []
|
|
255
|
+
for _ in range(amount_objects_to_create):
|
|
256
|
+
await sleep(0)
|
|
257
|
+
otl_object = cls.generate_object_from_oslo_class(
|
|
258
|
+
oslo_class=oslo_class, add_geometry=add_geometry, collector=collector,
|
|
259
|
+
filter_attributes_by_subset=filter_attributes_by_subset, model_directory=model_directory)
|
|
260
|
+
if otl_object is not None:
|
|
261
|
+
otl_objects.append(otl_object)
|
|
262
|
+
return otl_objects
|
|
263
|
+
|
|
264
|
+
|
|
213
265
|
@classmethod
|
|
214
266
|
async def generate_objects_for_template_async(
|
|
215
267
|
cls, subset_path: Path, class_uris_filter: [str], filter_attributes_by_subset: bool,
|
|
@@ -223,27 +275,31 @@ class SubsetTemplateCreator:
|
|
|
223
275
|
await sleep(0)
|
|
224
276
|
filtered_class_list = cls.filters_classes_by_subset(collector=collector, class_uris_filter=class_uris_filter)
|
|
225
277
|
await sleep(0)
|
|
226
|
-
relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
|
|
278
|
+
cls.relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
|
|
227
279
|
|
|
228
280
|
amount_objects_to_create = max(1, dummy_data_rows)
|
|
229
281
|
otl_objects = []
|
|
230
282
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
283
|
+
while True:
|
|
284
|
+
tasks = [
|
|
285
|
+
cls.create_x_objects_async(oslo_class, add_geometry, collector,
|
|
286
|
+
filter_attributes_by_subset, model_directory, amount_objects_to_create)
|
|
287
|
+
for oslo_class in [cl for cl in filtered_class_list if cl.abstract == 0]
|
|
288
|
+
]
|
|
289
|
+
results = await asyncio.gather(*tasks)
|
|
290
|
+
otl_objects.extend([item for sublist in results for item in sublist])
|
|
235
291
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
292
|
+
created = len(otl_objects)
|
|
293
|
+
unique_ids = len({
|
|
294
|
+
obj.assetId.identificator if obj.typeURI != 'http://purl.org/dc/terms/Agent' else obj.agentId.identificator
|
|
295
|
+
for obj in otl_objects})
|
|
296
|
+
if created == unique_ids:
|
|
297
|
+
break
|
|
298
|
+
otl_objects = []
|
|
243
299
|
|
|
244
300
|
if not ignore_relations:
|
|
245
301
|
non_relations_class_uris = [cl.objectUri for cl in filtered_class_list
|
|
246
|
-
if cl.abstract == 0 and cl.objectUri not in relation_dict]
|
|
302
|
+
if cl.abstract == 0 and cl.objectUri not in cls.relation_dict]
|
|
247
303
|
cls.append_relations_to_objects(otl_objects=otl_objects, collector=collector,
|
|
248
304
|
class_uris_filter=non_relations_class_uris, model_directory=model_directory)
|
|
249
305
|
|
|
@@ -500,13 +556,14 @@ class SubsetTemplateCreator:
|
|
|
500
556
|
cell.fill = PatternFill(start_color="FF7276", end_color="FF7276", fill_type="solid")
|
|
501
557
|
|
|
502
558
|
@classmethod
|
|
503
|
-
def add_attribute_info_to_sheet(cls, collected_attribute_info, sheet):
|
|
559
|
+
def add_attribute_info_to_sheet(cls, collected_attribute_info: list[str], sheet: Worksheet):
|
|
504
560
|
sheet.insert_rows(idx=1)
|
|
561
|
+
fill = PatternFill(start_color="808080", fill_type="solid")
|
|
562
|
+
alignment = Alignment(wrapText=True, vertical='top')
|
|
505
563
|
for index, attr_info in enumerate(collected_attribute_info, start=1):
|
|
506
|
-
cell = sheet.cell(row=1, column=index)
|
|
507
|
-
cell.
|
|
508
|
-
cell.
|
|
509
|
-
cell.fill = PatternFill(start_color="808080", end_color="808080", fill_type="solid")
|
|
564
|
+
cell = sheet.cell(row=1, column=index, value=attr_info)
|
|
565
|
+
cell.alignment = alignment
|
|
566
|
+
cell.fill = fill
|
|
510
567
|
|
|
511
568
|
@classmethod
|
|
512
569
|
def generate_choice_list_in_excel(cls, attribute, choice_list_dict, column, row_nr, sheet: Worksheet,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
otlmow_template/SubsetTemplateCreator.py,sha256=iZD2kjhOnymQ9tgqU6zq2ZCD8KVIT232mbrxTSR4fQ8,35845
|
|
2
|
+
otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
|
|
3
|
+
otlmow_template-1.4.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
|
|
4
|
+
otlmow_template-1.4.dist-info/METADATA,sha256=MqaUUEubb-DhKErKteUljO6Z3lxjGlaJoDL4a0cam-k,44220
|
|
5
|
+
otlmow_template-1.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
6
|
+
otlmow_template-1.4.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
|
|
7
|
+
otlmow_template-1.4.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
otlmow_template/SubsetTemplateCreator.py,sha256=SNXGHR5zMTSTs_xzWWDZ_183oV-D46SN6PQ-EPMikKs,33360
|
|
2
|
-
otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
|
|
3
|
-
otlmow_template-1.3.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
|
|
4
|
-
otlmow_template-1.3.dist-info/METADATA,sha256=BzvQ3dSl1uof3tLpGWJt6sHHAxEp0PAwv0Bz8iC50Pc,44220
|
|
5
|
-
otlmow_template-1.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
6
|
-
otlmow_template-1.3.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
|
|
7
|
-
otlmow_template-1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|