from typing import List, Tuple import pytest from sziszapangma.core.wer.wer_soft_calculator import WerSoftCalculator from sziszapangma.core.wer.word import Word from tests.file_stored_embedding_transformer import \ FileStoredEmbeddingTransformer 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'] 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