Updated tests regarding the usage of MsdState

This commit is contained in:
2026-05-29 13:54:13 +02:00
parent 9ab9df76f6
commit 4e717ee587
4 changed files with 16 additions and 17 deletions
+6 -7
View File
@@ -287,10 +287,11 @@ class Msd:
if len(states) == 0:
states.add(self.State.UNKNOWN)
if self.expected_state not in states:
error_message = f"Given Msd '{self.code}' is unknown for expected state '{self.expected_state.name}'."
if self.require_valid:
raise MsdException(f"Given msd '{self.codecode}' is '{self.state.name}', but expected state is '{self.expected_state.name}'.")
raise MsdException(error_message)
else:
print(f"[WARN] The Msd '{self.code}' is unknown for expected state '{self.expected_state.name}'.")
print(f"[WARN] {error_message}")
return max(states)
def __str__(self):
@@ -370,12 +371,10 @@ class Converter:
msd(Msd): the JOS MSD to convert
language(str): the language for the Properties object to be generated: "en" (English) or "sl" (Slovene)
lemma(str): the lemma of the word form with the MSD
require_valid_flag(boolean): whether to raise a MsdException or only warn if a non-standard MSD is provided
warn_level_flag(boolean): whether to warn if cannot be sure of level of a property
Returns:
Properties: the result of the conversion of the Msd in the language requested
"""
category_char = msd.code[0].lower()
value_chars = msd.code[1:]
@@ -402,7 +401,7 @@ class Converter:
form_feature_map[feature_name] = feature_value
return Properties(category_name, lexeme_feature_map, form_feature_map, language)
def properties_to_msd(self, properties, language, expected_state=Msd.State.FULL):
def properties_to_msd(self, properties, language, expected_state=Msd.State.FULL, require_valid=False):
"""Convert Properties to Msd.
The language of the generated Msd is specified and can differ from the Properties language.
@@ -434,7 +433,7 @@ class Converter:
msd_code += '-'
i += 1
msd_code += position_map[position]
msd = Msd(msd_code, language, expected_state=expected_state)
msd = Msd(msd_code, language, expected_state=expected_state, require_valid=require_valid)
return msd
def msd_to_ud(self, msd, lemma):
@@ -448,7 +447,7 @@ class Converter:
"""
if msd.state != Msd.State.FULL:
raise MsdException(f"Msd must be full to be converted to UD.")
raise MsdException("Msd must be full to be converted to UD.")
upos_category, *upos_features = self.mte_to_ud_features[msd.code].split()
final_upos = ""