diff --git a/src/morphodict/phrase_translate/fst.py b/src/morphodict/phrase_translate/fst.py index 195d48463..4d7bbdf02 100644 --- a/src/morphodict/phrase_translate/fst.py +++ b/src/morphodict/phrase_translate/fst.py @@ -1,15 +1,8 @@ import foma from functools import cache -import logging from morphodict.utils.shared_res_dir import shared_fst_dir -from morphodict.analysis import RichAnalysis -from morphodict.phrase_translate.source_tag_map import ( - noun_wordform_to_phrase, - verb_wordform_to_phrase, -) -logger = logging.getLogger(__name__) @cache def eng_noun_entry_to_inflected_phrase_fst(): @@ -75,27 +68,6 @@ def source_phrase_analyses(query): r.decode("UTF-8") for r in eng_phrase_to_crk_features_fst()[query] ] -def inflect_target_language_phrase(analysis, lemma_definition): - if isinstance(analysis, tuple): - analysis = RichAnalysis(analysis) - cree_wordform_tag_list = analysis.prefix_tags + analysis.suffix_tags - - if "+N" in cree_wordform_tag_list: - tags_for_phrase = noun_wordform_to_phrase.map_tags(cree_wordform_tag_list) - tagged_phrase = f"{''.join(tags_for_phrase)} {lemma_definition}" - logger.debug("tagged_phrase = %s\n", tagged_phrase) - phrase = inflect_target_noun_phrase(tagged_phrase) - logger.debug("phrase = %s\n", phrase) - return phrase.strip() - - elif "+V" in cree_wordform_tag_list: - tags_for_phrase = verb_wordform_to_phrase.map_tags(cree_wordform_tag_list) - tagged_phrase = f"{''.join(tags_for_phrase)} {lemma_definition}" - logger.debug("tagged_phrase = %s\n", tagged_phrase) - phrase = inflect_target_verb_phrase(tagged_phrase) - logger.debug("phrase = %s\n", phrase) - return phrase.strip() - def fst_analyses(text): def decode_foma_results(fst, query): diff --git a/src/morphodict/phrase_translate/test_inflect_target_phrase.py b/src/morphodict/phrase_translate/test_inflect_target_phrase.py index 7f3b060fd..659c29557 100644 --- a/src/morphodict/phrase_translate/test_inflect_target_phrase.py +++ b/src/morphodict/phrase_translate/test_inflect_target_phrase.py @@ -1,6 +1,6 @@ import pytest -from morphodict.phrase_translate.fst import inflect_target_language_phrase +from morphodict.phrase_translate.to_target import inflect_target_language_phrase ARBITRARY_DEFINITION = "s/he sees s.o." diff --git a/src/morphodict/phrase_translate/to_source/translate.py b/src/morphodict/phrase_translate/to_source/translate.py index c6329b73e..c6b8c4aa6 100755 --- a/src/morphodict/phrase_translate/to_source/translate.py +++ b/src/morphodict/phrase_translate/to_source/translate.py @@ -19,7 +19,8 @@ import django from morphodict.phrase_translate.definition_cleanup import cleanup_target_definition_for_translation -from morphodict.phrase_translate.fst import inflect_target_language_phrase, FomaLookupNotFoundException, FomaLookupMultipleFoundException +from morphodict.phrase_translate.to_target import inflect_target_language_phrase +from morphodict.phrase_translate.fst import FomaLookupNotFoundException, FomaLookupMultipleFoundException from morphodict.analysis.tag_map import UnknownTagError if typing.TYPE_CHECKING: diff --git a/src/morphodict/phrase_translate/to_target/__init__.py b/src/morphodict/phrase_translate/to_target/__init__.py index e69de29bb..4b738e431 100644 --- a/src/morphodict/phrase_translate/to_target/__init__.py +++ b/src/morphodict/phrase_translate/to_target/__init__.py @@ -0,0 +1,36 @@ +import logging + +from morphodict.analysis import RichAnalysis +from morphodict.phrase_translate.source_tag_map import ( + noun_wordform_to_phrase, + verb_wordform_to_phrase, +) +from morphodict.phrase_translate.fst import ( + inflect_target_noun_phrase, + inflect_target_verb_phrase +) + + +logger = logging.getLogger(__name__) + + +def inflect_target_language_phrase(analysis, lemma_definition): + if isinstance(analysis, tuple): + analysis = RichAnalysis(analysis) + cree_wordform_tag_list = analysis.prefix_tags + analysis.suffix_tags + + if "+N" in cree_wordform_tag_list: + tags_for_phrase = noun_wordform_to_phrase.map_tags(cree_wordform_tag_list) + tagged_phrase = f"{''.join(tags_for_phrase)} {lemma_definition}" + logger.debug("tagged_phrase = %s\n", tagged_phrase) + phrase = inflect_target_noun_phrase(tagged_phrase) + logger.debug("phrase = %s\n", phrase) + return phrase.strip() + + elif "+V" in cree_wordform_tag_list: + tags_for_phrase = verb_wordform_to_phrase.map_tags(cree_wordform_tag_list) + tagged_phrase = f"{''.join(tags_for_phrase)} {lemma_definition}" + logger.debug("tagged_phrase = %s\n", tagged_phrase) + phrase = inflect_target_verb_phrase(tagged_phrase) + logger.debug("phrase = %s\n", phrase) + return phrase.strip() \ No newline at end of file