Skip to content

Commit 0c24262

Browse files
committed
fix(transformers): remaining bugs
1 parent 642cbee commit 0c24262

2 files changed

Lines changed: 33 additions & 27 deletions

File tree

src/ontoweaver/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ def __init__(self,
654654
self.declare_types = Declare()
655655

656656

657+
657658
def get_transformer(self):
658659
return self
659660

src/ontoweaver/transformer.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ def import_from_path(file_path):
6565
# See https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
6666
module_name = pathlib.Path(file_path).stem
6767
spec = importlib.util.spec_from_file_location(module_name, file_path)
68+
assert spec
6869
module = importlib.util.module_from_spec(spec)
6970
sys.modules[module_name] = module
7071
spec.loader.exec_module(module)
7172
return module
7273

74+
7375
def register_all(module_path):
7476
for mpath in module_path:
7577
logger.info(f"Look for transformers in `{mpath}`")
@@ -303,7 +305,7 @@ def __call__(self, row, i):
303305
str: The concatenated string from the cell values.
304306
"""
305307
if not self.columns:
306-
self.error(f"No column declared for the {type(self).__name__} transformer, did you forgot to add a `columns` keyword?", section="cat.call", exception = exceptions.TransformerInputError)
308+
self.error(f"No column declared for the {type(self).__name__} transformer, did you forgot to add a `columns` keyword?", section=f"{type(self).__name__}.call", exception = exceptions.TransformerInputError)
307309

308310
for item in super().__call__(row, i):
309311
yield item
@@ -350,11 +352,10 @@ def __init__(self,
350352
raise_errors: if True, the caller is asking for raising exceptions when an error occurs
351353
"""
352354

353-
format_string = kwargs.get("format_string", None)
354-
if not format_string: # Neither empty string nor None.
355-
self.error(f"The `format_string` parameter of the `{self.__name__}` transformer cannot be an empty string.")
356-
self.format_string = format_string
357-
self.value_maker = self.ValueMaker(raise_errors=raise_errors, format_string=self.format_string)
355+
self.value_maker = self.ValueMaker(
356+
raise_errors=raise_errors,
357+
format_string=format_string
358+
)
358359

359360
super().__init__(properties_of,
360361
self.value_maker,
@@ -367,6 +368,10 @@ def __init__(self,
367368
**kwargs
368369
)
369370

371+
if not format_string: # Neither empty string nor None.
372+
self.error(f"The `format_string` parameter of the `{type(self).__name__}` transformer cannot be an empty string.")
373+
374+
370375

371376
class rowIndex(base.Transformer):
372377
"""Transformer subclass used for the simple mapping of nodes with row index values as id."""
@@ -732,27 +737,27 @@ def __init__(self,
732737
lrg = loader.LoadOWLGraph()
733738

734739
# Since we cannot expand kwargs, let's recover what we have inside.
735-
translations = kwargs.get("translations", None)
736-
translations_file = kwargs.get("translations_file", None)
737-
translate_from = kwargs.get("translate_from", None)
738-
translate_to = kwargs.get("translate_to", None)
740+
self.translations = kwargs.get("translations", None)
741+
self.translations_file = kwargs.get("translations_file", None)
742+
self.translate_from = kwargs.get("translate_from", None)
743+
self.translate_to = kwargs.get("translate_to", None)
739744

740-
if translations and translations_file:
741-
self.error(f"Cannot have both `translations` (=`{translations}`) and `translations_file` (=`{translations_file}`) defined in a {type(self).__name__} transformer.", section="translate", exception = exceptions.TransformerInterfaceError)
745+
if self.translations and self.translations_file:
746+
self.error(f"Cannot have both `translations` (=`{self.translations}`) and `translations_file` (=`{self.translations_file}`) defined in a {type(self).__name__} transformer.", section="translate", exception = exceptions.TransformerInterfaceError)
742747

743-
if translations:
744-
self.translate = translations
748+
if self.translations:
749+
self.translate = self.translations
745750
logger.debug(f"\t\t\tManual translations: `{self.translate}`")
746-
elif translations_file:
747-
logger.debug(f"\t\t\tGet translations from file: `{translations_file}`")
748-
if not translate_from:
749-
self.error(f"No translation source column declared for the `{type(self).__name__}` transformer using translations_file=`{translations_file}`, did you forget to add a `translate_from` keyword?", section="translate.init", exception = exceptions.TransformerInterfaceError)
750-
if not translate_to:
751-
self.error(f"No translation target column declared for the `{type(self).__name__}` transformer using translations_file=`{translations_file}`, did you forget to add a `translate_to` keyword?", section="translate.init", exception = exceptions.TransformerInterfaceError)
751+
elif self.translations_file:
752+
logger.debug(f"\t\t\tGet translations from file: `{self.translations_file}`")
753+
if not self.translate_from:
754+
self.error(f"No translation source column declared for the `{type(self).__name__}` transformer using translations_file=`{self.translations_file}`, did you forget to add a `translate_from` keyword?", section="translate.init", exception = exceptions.TransformerInterfaceError)
755+
if not self.translate_to:
756+
self.error(f"No translation target column declared for the `{type(self).__name__}` transformer using translations_file=`{self.translations_file}`, did you forget to add a `translate_to` keyword?", section="translate.init", exception = exceptions.TransformerInterfaceError)
752757
else:
753-
self.translations_file = translations_file
754-
self.translate_from = translate_from
755-
self.translate_to = translate_to
758+
# self.translations_file = translations_file
759+
# self.translate_from = translate_from
760+
# self.translate_to = translate_to
756761

757762
# Possible arguments from the `translate` section.
758763
mapping_args = ["translations", "translations_file", "translate_from", "translate_to"]
@@ -809,9 +814,9 @@ def __init__(self,
809814
self.error("No translation found, did you forget the `translations` keyword?", section="translate.init", exception = exceptions.TransformerInterfaceError)
810815

811816
self.value_maker = self.ValueMaker(
812-
self.translate,
813-
self.translate_from,
814-
self.translate_to,
817+
self.translate,
818+
self.translate_from,
819+
self.translate_to,
815820
raise_errors=raise_errors
816821
)
817822

@@ -1191,4 +1196,4 @@ def __call__(self, row, i):
11911196
for val in self.translate.value_maker(["translate_column"], pseudorow, i):
11921197
logging.debug(f"VAL {val}")
11931198
value, edge_type, node_type, reverse_edge = self.create(val, row)
1194-
yield value, edge_type, node_type, reverse_edge
1199+
yield value, edge_type, node_type, reverse_edge

0 commit comments

Comments
 (0)