Skip to content
Snippets Groups Projects
Commit 090cfbf9 authored by zrgt's avatar zrgt
Browse files

Add semantic_ids

parent d621deba
No related branches found
No related tags found
No related merge requests found
Pipeline #283264 passed
import os, sys, inspect import os, sys, inspect
import re
from typing import List from typing import List
import basyx import basyx
...@@ -374,6 +375,44 @@ def create_aas(): ...@@ -374,6 +375,44 @@ def create_aas():
waldweg, waldweg,
zu_faellende_baeume, zu_faellende_baeume,
] ]
def remove_iteration_ending(val: str):
# remove iteration ending like {00}
val = re.sub(r'\{\d+\}$', '', val)
# remove one or more digits at the end
val = re.sub(r'_?\d+$', '', val)
return val
def set_semantic_id(referable: model.SubmodelElement):
# example = "https://admin-shell.io/kwh40/forestml40/Waldweg/0/1/Beschreibung"
if isinstance(referable, model.Submodel):
base = "https://admin-shell.io/kwh40/forestml40"
postfix = f"{referable.id_short}/0/1"
else:
base = referable.parent.semantic_id.key[0].value
postfix = remove_iteration_ending(referable.id_short)
referable.semantic_id = model.GlobalReference(
(basyx.aas.model.Key(model.KeyTypes.GLOBAL_REFERENCE,
f"{base}/{postfix}"),)
)
def set_semantic_id_for_each_in(obj):
set_semantic_id(obj)
try:
iter(obj)
except TypeError as e:
print(e)
return
se_objects = list(obj)
for se in se_objects:
set_semantic_id_for_each_in(se)
for submodel in submodels:
set_semantic_id_for_each_in(submodel)
aas_dz_wald = models.DZWald( aas_dz_wald = models.DZWald(
dzwald_id="https://www.company.com/dz_wald/1", dzwald_id="https://www.company.com/dz_wald/1",
asset=basyx.aas.model.AssetInformation(), asset=basyx.aas.model.AssetInformation(),
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment