from typing import List, Tuple import pytest from sziszapangma.core.alignment.alignment_calculator import \ AlignmentCalculator from sziszapangma.core.alignment.alignment_embedding_calculator import \ AlignmentEmbeddingCalculator from sziszapangma.core.alignment.word import Word from sziszapangma.core.wer.wer_calculator import WerCalculator 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_alignment_calculator() -> AlignmentCalculator: return AlignmentEmbeddingCalculator( FileStoredEmbeddingTransformer('tests/embeddings_pl.json')) def test_classic_calculate_wer_value(): """Sample test for core calculate.""" reference, hypothesis = get_sample_data() alignment = get_alignment_calculator().calculate_alignment(reference, hypothesis) wer_result = WerCalculator().calculate_wer(alignment) assert pytest.approx(wer_result) == 0.55879563