File size: 1,130 Bytes
d916065
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""

Test Aline algorithm for aligning phonetic sequences

"""
from nltk.metrics import aline


def test_aline():
    result = aline.align("θin", "tenwis")
    expected = [[("θ", "t"), ("i", "e"), ("n", "n")]]

    assert result == expected

    result = aline.align("jo", "ʒə")
    expected = [[("j", "ʒ"), ("o", "ə")]]

    assert result == expected

    result = aline.align("pematesiweni", "pematesewen")
    expected = [
        [
            ("p", "p"),
            ("e", "e"),
            ("m", "m"),
            ("a", "a"),
            ("t", "t"),
            ("e", "e"),
            ("s", "s"),
            ("i", "e"),
            ("w", "w"),
            ("e", "e"),
            ("n", "n"),
        ]
    ]

    assert result == expected

    result = aline.align("tuwθ", "dentis")
    expected = [[("t", "t"), ("u", "i"), ("w", "-"), ("θ", "s")]]

    assert result == expected


def test_aline_delta():
    """

    Test aline for computing the difference between two segments

    """
    assert aline.delta("p", "q") == 20.0
    assert aline.delta("a", "A") == 0.0