@@ -64,10 +64,12 @@ def __init__(self, schema_file_path: str, root_path: str, instances: Optional[di
6464 schema_file_path [len (root_path ) + 1 :].replace (".schema.omi.json" , "" ).split ("/" )
6565 )
6666 self .version = _relative_path_without_extension [0 ]
67+ self .template_name = "src/module_template.py.txt"
6768 if self .version in ["v3.0" , "v2.0" , "v1.0" ]:
68- self .template_name = "src/module_template_old.py.txt "
69+ self .context_vocab = "https://openminds.ebrains.eu/vocab/ "
6970 else :
70- self .template_name = "src/module_template.py.txt"
71+ self .context_vocab = "https://openminds.om-i.org/props/"
72+
7173 self .relative_path_without_extension = [
7274 generate_python_name (part ) for part in _relative_path_without_extension [1 :]
7375 ]
@@ -86,7 +88,7 @@ def _version_module(self):
8688 def _target_file_without_extension (self ) -> str :
8789 return os .path .join (self ._version_module , "/" .join (self .relative_path_without_extension ))
8890
89- def translate (self , embedded = None , class_module_dict = None ):
91+ def translate (self , embedded = None , class_to_module_map = None ):
9092 def get_type (property ):
9193 type_map = {
9294 "string" : "str" ,
@@ -104,8 +106,8 @@ def get_type(property):
104106 types = []
105107 for item in property ["_linkedTypes" ]:
106108 openminds_module_from_type , class_name = item .split ("/" )[- 2 :]
107- if isinstance (class_module_dict ,dict ) and (class_name in class_module_dict ):
108- openminds_module = generate_python_name (class_module_dict [class_name ])
109+ if isinstance (class_to_module_map ,dict ) and (class_name in class_to_module_map ):
110+ openminds_module = generate_python_name (class_to_module_map [class_name ])
109111 else :
110112 openminds_module = generate_python_name (openminds_module_from_type )
111113 types .append (f"openminds.{ self ._version_module } .{ openminds_module } .{ class_name } " )
@@ -116,8 +118,8 @@ def get_type(property):
116118 types = []
117119 for item in property ["_embeddedTypes" ]:
118120 openminds_module_from_type , class_name = item .split ("/" )[- 2 :]
119- if isinstance (class_module_dict ,dict ) and (class_name in class_module_dict ):
120- openminds_module = generate_python_name (class_module_dict [class_name ])
121+ if isinstance (class_to_module_map ,dict ) and (class_name in class_to_module_map ):
122+ openminds_module = generate_python_name (class_to_module_map [class_name ])
121123 else :
122124 openminds_module = generate_python_name (openminds_module_from_type )
123125 types .append (f"openminds.{ self ._version_module } .{ openminds_module } .{ class_name } " )
@@ -210,6 +212,7 @@ def filter_instance(instance):
210212 "class_name" : class_name ,
211213 "openminds_type" : openminds_type ,
212214 "schema_version" : self .version ,
215+ "context_vocab" : self .context_vocab ,
213216 "properties" : properties ,
214217 "additional_methods" : "" ,
215218 "instances" : instances
@@ -242,11 +245,11 @@ def filter_instance(instance):
242245 if extra_imports :
243246 self .context ["preamble" ] = "\n " .join (sorted (extra_imports ))
244247
245- def build (self , embedded = None , class_module_dict = None ):
248+ def build (self , embedded = None , class_to_module_map = None ):
246249 target_file_path = os .path .join ("target" , "openminds" , f"{ self ._target_file_without_extension ()} .py" )
247250 os .makedirs (os .path .dirname (target_file_path ), exist_ok = True )
248251
249- self .translate (embedded = embedded , class_module_dict = class_module_dict )
252+ self .translate (embedded = embedded , class_to_module_map = class_to_module_map )
250253
251254 with open (target_file_path , "w" ) as target_file :
252255 contents = self .env .get_template (self .template_name ).render (self .context )
0 commit comments