File size: 1,182 Bytes
32942d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import unittest

from shruti_coreml.score import edit_distance, score_paired, words


class ScoreTests(unittest.TestCase):
    def test_nfc_lowercase_punctuation_and_numbers(self):
        self.assertEqual(words(" E\u0301CO, 200! चालीस। "), ["éco", "200", "चालीस"])

    def test_token_insert_delete_and_replace(self):
        self.assertEqual(edit_distance(["a", "b", "c"], ["a", "d", "e", "f"]), 3)
        self.assertEqual(edit_distance(["a"], []), 1)
        self.assertEqual(edit_distance([], ["a", "b"]), 2)

    def test_weighting_and_pairing(self):
        rows = [
            {"reference": "one two", "baseline": {"text": "one"}, "coreml": {"text": "one two"}},
            {"reference": "three", "baseline": {"text": "three"}, "coreml": {"text": "three"}},
        ]
        scored = score_paired(rows)
        self.assertAlmostEqual(scored["difference_wer_points"], -100 / 3)
        self.assertEqual(scored["exact_text_matches"], 1)

    def test_silence_counts_words(self):
        scored = score_paired([{"reference": "", "baseline": {"text": ""}, "coreml": {"text": "one two"}}])
        self.assertEqual(scored["coreml_words_on_silence"], 2)