forked from yask123/Summarize-it
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_hypothesis_summarizer.py
160 lines (141 loc) · 6.75 KB
/
test_hypothesis_summarizer.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import unittest
import json
import io
from ts_summarizer import (TextRankTsSummarizer)
from interval_summarizer import (IntervalSpec, TsSummarizer,
ts_to_time)
from datetime import datetime
import logging
import sys
import config
from ts_config import DEBUG
from hypothesis import given
from hypothesis.strategies import (sampled_from, lists, just, integers)
import glob
import random
logger = logging.getLogger()
logger.level = logging.DEBUG if DEBUG else logging.INFO
test_json_msgs = json.load(io.open("./test-events.json", encoding='utf-8'))['messages']
test_json_msgs_c2 = json.load(io.open("./data/test-events-elastic.json", encoding='utf-8'))['messages']
test_json_msgs_c3 = []
def read_dir(fdir):
coll = []
for jfile in glob.glob('./data/slack-logs-2/{}/*.json'.format(fdir)):
coll += json.load(io.open(jfile, encoding='utf-8'))
return coll
test_json_msgs_c3 = [(fdir, read_dir(fdir)) for fdir in ['api-test', 'calypso', 'games', 'happiness', 'hg', 'jetpack', 'jetpackfuel', 'livechat', 'tickets', 'vip']]
print len(test_json_msgs_c3)
class TestSummarize(unittest.TestCase):
test_msgs = test_json_msgs
@given(
lists(elements=sampled_from(test_json_msgs), min_size=3),
integers(min_value=1, max_value=20)
)
def test_text_rank_summarization_ds1_days(self, smp_msgs, days):
"""Generate something for N day interval"""
logger.info("Input is %s", smp_msgs)
asd = {'days': days, 'size' : 3, 'txt' : u'Summary for first {} days:\n'.format(days)}
summ = TextRankTsSummarizer()
summ.set_channel('elasticsearch')
sumry = summ.summarize(smp_msgs, range_spec=asd)
logger.debug("Summary is %s", sumry)
# Length of summary is at least 1 and no greater than 3
self.assertTrue(len(sumry) >= 1)
self.assertTrue(len(sumry) <= 3)
# Length of summary is less than or equal to the original length
self.assertTrue(len(sumry) <= len(smp_msgs))
# Each message in the summary must correspond to a message
@given(
lists(elements=sampled_from(test_json_msgs_c2), min_size=12),
integers(min_value=1, max_value=20)
)
def test_text_rank_summarization_ds2_days(self, smp_msgs, days):
"""Generate something for N day interval"""
logger.info("Input is %s", smp_msgs)
asd = {'days': days, 'size' : 3, 'txt' : u'Summary for first {} days:\n'.format(days)}
summ = TextRankTsSummarizer()
summ.set_channel('elasticsearch')
sumry = summ.summarize(smp_msgs, range_spec=asd)
logger.debug("Summary is %s", sumry)
# Length of summary is at least 1 and no greater than 3
self.assertTrue(len(sumry) >= 1)
self.assertTrue(len(sumry) <= 3)
# Length of summary is less than or equal to the original length
self.assertTrue(len(sumry) <= len(smp_msgs))
# Each message in the summary must correspond to a message
@given(
integers(min_value=1, max_value=1000),
integers(min_value=1, max_value=20)
)
def test_text_rank_summarization_ds3_days(self, sampsize, days):
"""Generate something for N day interval"""
channel, ssamp = random.choice(test_json_msgs_c3)
samp = ssamp[random.randint(1,len(ssamp)-2):]
logger.info("Input is segment is %s", samp)
asd = {'days': days, 'size' : 3, 'txt' : u'Summary for first {} days:\n'.format(days)}
summ = TextRankTsSummarizer()
summ.set_channel(channel)
sumry = summ.summarize(samp, range_spec=asd)
logger.debug("Summary is %s", sumry)
# Length of summary is at least 1 and no greater than 3
self.assertTrue(len(sumry) >= 1)
self.assertTrue(len(sumry) <= 3)
# Length of summary is less than or equal to the original length
#self.assertTrue(len(sumry) <= len(samp))
# Each message in the summary must correspond to a message
@given(lists(elements=sampled_from(test_json_msgs), min_size=1),
integers(min_value=1, max_value=24)
)
def test_text_rank_summarization_ds1_hours(self, smp_msgs, hours):
"""Generate something for N hour intervals"""
logger.info("Input is %s", smp_msgs)
asd = {'hours': hours, 'size' : 3, 'txt' : u'Summary for first {} hours:\n'.format(hours)}
summ = TextRankTsSummarizer()
summ.set_channel('elasticsearch')
sumry = summ.summarize(smp_msgs, range_spec=asd)
logger.debug("Summary is %s", sumry)
# Length of summary is at least 1 and no greater than 3
self.assertTrue(len(sumry) >= 1)
self.assertTrue(len(sumry) <= 3)
# Length of summary is less than or equal to the original length
self.assertTrue(len(sumry) <= len(smp_msgs))
# Each message in the summary must correspond to a message
@given(lists(elements=sampled_from(test_json_msgs_c2), min_size=1),
integers(min_value=1, max_value=24)
)
def test_text_rank_summarization_ds2_hours(self, smp_msgs, hours):
"""Generate something for N hour intervals"""
logger.info("Input is %s", smp_msgs)
asd = {'hours': hours, 'size' : 3, 'txt' : u'Summary for first {} hours:\n'.format(hours)}
summ = TextRankTsSummarizer()
summ.set_channel('elasticsearch')
sumry = summ.summarize(smp_msgs, range_spec=asd)
logger.debug("Summary is %s", sumry)
# Length of summary is at least 1 and no greater than 3
self.assertTrue(len(sumry) >= 1)
self.assertTrue(len(sumry) <= 3)
# Length of summary is less than or equal to the original length
self.assertTrue(len(sumry) <= len(smp_msgs))
# Each message in the summary must correspond to a message
@given(
integers(min_value=2, max_value=1000),
integers(min_value=1, max_value=24)
)
def test_text_rank_summarization_ds3_hours(self, sampsize, hours):
"""Generate something for N hour intervals"""
channel, ssamp = random.choice(test_json_msgs_c3)
samp = ssamp[random.randint(1,len(ssamp)-2):]
logger.info("Input is segment is %s", samp)
asd = {'hours': hours, 'size' : 3, 'txt' : u'Summary for first {} hours:\n'.format(hours)}
summ = TextRankTsSummarizer()
summ.set_channel(channel)
sumry = summ.summarize(samp, range_spec=asd)
logger.debug("Summary is %s", sumry)
# Length of summary is at least 1 and no greater than 3
self.assertTrue(len(sumry) >= 1)
self.assertTrue(len(sumry) <= 3)
# Length of summary is less than or equal to the original length
#self.assertTrue(len(sumry) <= len(samp))
# Each message in the summary must correspond to a message
if __name__ == '__main__':
unittest.main()