-
Notifications
You must be signed in to change notification settings - Fork 12
/
segmentation_test.py
120 lines (102 loc) · 3.68 KB
/
segmentation_test.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'''
Tests segmentation similarity (S).
.. moduleauthor:: Chris Fournier <chris.m.fournier@gmail.com>
'''
import unittest
from decimal import Decimal
from .segmentation import segmentation_similarity
from ..util import SegmentationMetricError
from ..data.samples import (HEARST_1997_STARGAZER, HYPOTHESIS_STARGAZER,
MULTIPLE_BOUNDARY_TYPES, KAZANTSEVA2012_G5)
class TestSegmentation(unittest.TestCase):
'''
Test.
'''
def test_fn(self):
'''
Test false negative.
'''
value = segmentation_similarity([2, 3, 6], [5, 6])
self.assertEqual(Decimal('0.9'), value)
def test_fp(self):
'''
Test false negative.
'''
value = segmentation_similarity([2, 3, 6], [2, 3, 3, 3])
self.assertEqual(Decimal('0.9'), value)
def test_near_miss(self):
'''
Test near miss.
'''
value = segmentation_similarity([2, 3, 6], [2, 2, 7])
self.assertEqual(Decimal('0.95'), value)
def test_one_minus(self):
'''
Test one minus.
'''
value = segmentation_similarity([2, 3, 6], [2, 2, 7], one_minus=True)
self.assertEqual(Decimal('0.05'), value)
def test_clustered_fps(self):
'''
Test near miss.
'''
value = segmentation_similarity([2, 3, 6], [1, 1, 3, 1, 5])
self.assertEqual(Decimal('0.8'), value)
def test_parts(self):
'''
Test false negative.
'''
numerator, denominator = segmentation_similarity([2, 3, 6], [5, 6],
return_parts=True)
self.assertEqual(Decimal('9'), numerator)
self.assertEqual(Decimal('10'), denominator)
def test_format_exception(self):
'''
Test false negative.
'''
a = [2, 3, 6]
b = [2, 2, 7]
self.assertRaises(SegmentationMetricError, segmentation_similarity,
a, b, boundary_format=None)
def test_mass_exception(self):
'''
Test false negative.
'''
a = [2, 2, 7]
b = [2, 2, 8]
self.assertRaises(SegmentationMetricError, segmentation_similarity,
a, b)
def test_s_datasets(self):
'''
Test S upon two datasets.
'''
hypothesis = HYPOTHESIS_STARGAZER
reference = HEARST_1997_STARGAZER
value = segmentation_similarity(hypothesis, reference)
self.assertAlmostEquals(float(value['stargazer,h1,1']), 0.85)
self.assertAlmostEquals(float(value['stargazer,h2,1']), 0.725)
self.assertAlmostEquals(float(value['stargazer,h1,2']), 0.8)
self.assertAlmostEquals(float(value['stargazer,h2,2']), 0.7)
def test_s_datasets_return_parts(self):
'''
Test S upon two datasets and return fnc parts.
'''
hypothesis = HYPOTHESIS_STARGAZER
reference = HEARST_1997_STARGAZER
value = segmentation_similarity(hypothesis, reference, return_parts=True)
self.assertEquals(value['stargazer,h1,1'], (Decimal('17'), 20))
def test_s_datasets_exception(self):
'''
Test S upon two datasets that produces an exception.
'''
hypothesis = MULTIPLE_BOUNDARY_TYPES
reference = HEARST_1997_STARGAZER
self.assertRaises(SegmentationMetricError, segmentation_similarity, hypothesis, reference)
def test_s_datasets_continue(self):
'''
Test S upon two datasets that compares no items.
'''
hypothesis = KAZANTSEVA2012_G5
reference = HEARST_1997_STARGAZER
value = segmentation_similarity(hypothesis, reference)
self.assertEqual(value, {})