Skip to content
Snippets Groups Projects
test_soft_wer.py 1.04 KiB
Newer Older
from typing import List, Tuple

import pytest

from sziszapangma.core.wer.wer_soft_calculator import WerSoftCalculator
Marcin Wątroba's avatar
Marcin Wątroba committed
from sziszapangma.core.wer.word import Word
from tests.file_stored_embedding_transformer import \
    FileStoredEmbeddingTransformer


Marcin Wątroba's avatar
Marcin Wątroba committed
def string_list_to_words(strings: List[str]) -> List[Word]:
    return [Word.from_string(it) for it in strings]


def get_sample_data() -> Tuple[List[Word], List[Word]]:
    reference = ['ala', 'ma', 'dobrego', 'wielkiego', 'psa', 'rasowego']
    hypothesis = ['alana', 'rego', 'kruchego', 'psa', 'rasowego']
Marcin Wątroba's avatar
Marcin Wątroba committed
    return string_list_to_words(reference), string_list_to_words(hypothesis)


def get_calculator() -> WerSoftCalculator:
    return WerSoftCalculator(
        FileStoredEmbeddingTransformer('tests/embeddings_pl.json'))


def test_classic_calculate_wer_value():
    """Sample test for core calculate."""
    reference, hypothesis = get_sample_data()
    wer_result = get_calculator().calculate_wer(reference, hypothesis)
    print(wer_result[0])
    assert pytest.approx(wer_result[0]) == 0.50186761