Skip to content

Commit

Permalink
Populated first function of to_target
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Nov 7, 2024
1 parent 52261bf commit 14c9791
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
28 changes: 0 additions & 28 deletions src/morphodict/phrase_translate/fst.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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."

Expand Down
3 changes: 2 additions & 1 deletion src/morphodict/phrase_translate/to_source/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions src/morphodict/phrase_translate/to_target/__init__.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 14c9791

Please sign in to comment.