Skip to content

Commit

Permalink
Merge pull request #436 from sillsdev/eflomal_warning
Browse files Browse the repository at this point in the history
Move eflomal checks inside of eflomal.py
  • Loading branch information
mshannon-sil authored Jul 3, 2024
2 parents 949dd42 + 62a4d84 commit a1955a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 2 additions & 8 deletions silnlp/alignment/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from ..common.environment import SIL_NLP_ENV
from ..common.flatcat_stemmer import FlatCatStemmer
from ..common.null_stemmer import NullStemmer
from ..common.packages_utils import is_eflomal_available
from ..common.snowball_stemmer import SnowballStemmer
from ..common.stemmer import Stemmer
from ..common.utils import merge_dict
Expand All @@ -24,10 +23,7 @@
Ibm4DotnetMachineAligner,
ParatextDotnetMachineAligner,
)

if is_eflomal_available():
from .eflomal import EflomalAligner

from .eflomal import EflomalAligner
from .fast_align import FastAlign
from .giza_aligner import HmmGizaAligner, Ibm1GizaAligner, Ibm2GizaAligner, Ibm3GizaAligner, Ibm4GizaAligner
from .machine_aligner import (
Expand Down Expand Up @@ -67,11 +63,9 @@
"clear3_fa": (ClearAligner, "Clear-3-FA"),
"clear3_hmm": (ClearAligner, "Clear-3-HMM"),
"clab_fast_align": (FastAlign, "clab-FastAlign"),
"eflomal": (EflomalAligner, "Eflomal"),
}

if is_eflomal_available():
ALIGNERS["eflomal"] = (EflomalAligner, "Eflomal")

STEMMERS: Dict[str, Type[Stemmer]] = {
"snowball": SnowballStemmer,
"wordnet": WordNetStemmer,
Expand Down
8 changes: 7 additions & 1 deletion silnlp/alignment/eflomal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@
from tempfile import TemporaryDirectory
from typing import IO, Iterable

from eflomal import read_text, write_text
from machine.corpora import AlignedWordPair
from machine.translation import SymmetrizationHeuristic, WordAlignmentMatrix

from ..common.corpus import load_corpus
from ..common.packages_utils import is_eflomal_available
from .aligner import Aligner
from .lexicon import Lexicon
from .tools import execute_atools, execute_eflomal, is_atools_available

if is_eflomal_available():
from eflomal import read_text, write_text

LOGGER = logging.getLogger(__name__)


class EflomalAligner(Aligner):
def __init__(self, model_dir: Path) -> None:
if not is_eflomal_available():
raise RuntimeError("eflomal is not installed.")

super().__init__("eflomal", model_dir)

def train(self, src_file_path: Path, trg_file_path: Path) -> None:
Expand Down

0 comments on commit a1955a7

Please sign in to comment.