forked from yask123/Summarize-it
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_summarizer.py
75 lines (63 loc) · 2.88 KB
/
test_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
import unittest
import json
import io
import config
from ts_config import SUMMS
from interval_summarizer import (IntervalSpec, TsSummarizer,
ts_to_time)
from datetime import datetime
import logging
import logging.handlers
import sys
from ts_config import DEBUG
if "spacy" in SUMMS:
from sp_summarizer import (SpacyTsSummarizer)
import lsa
if "gensim" in SUMMS:
from ts_summarizer import (TextRankTsSummarizer)
logger = logging.getLogger()
logger.level = logging.DEBUG if DEBUG else logging.INFO
class TestSummarize(unittest.TestCase):
test_msgs = json.load(io.open("./test-events.json", encoding='utf-8'))['messages']
def test_interval_conversion(self):
self.assertTrue(ts_to_time("1441925382.000186") == datetime.utcfromtimestamp(1441925382))
def test_summarizer_tag_display(self):
"""Make sure that the display of the tag is correct"""
logger.info("Running the taggger test")
asd = {'minutes': 60, 'size' : 2, 'txt' : u'Summary for first 60 minutes:\n'}
summ = TsSummarizer()
summ.set_channel("elasticsearch")
summ_msg = summ.tagged_sum(TestSummarize.test_msgs[1])
logger.debug("Test summ msg is %s", summ_msg)
self.assertTrue(summ_msg == "@Thu-Sep-9-2015 18:32:08 <@U0EBEC5T5>: <https://a8c.slack.com/archives/elasticsearch/p1441909928000131|because i imagine the places we link people will vary quite a bit with tests>")
def test_gensim_summarization(self):
"""Pass the intervals to summarizer"""
if "gensim" in SUMMS:
asd = [{'minutes': 60, 'size' : 2, 'txt' : u'Summary for first 60 minutes:\n'}, {'hours':12, 'size' : 1, 'txt' : u'Summary for last 12 hours:\n'}]
summ = None
summ = TextRankTsSummarizer()
summ.set_channel('elasticsearch')
logger.debug("Testing gensim summarizer")
sumry = summ.summarize(TestSummarize.test_msgs, range_spec=asd)
logger.debug("Summary is %s", sumry)
self.assertTrue(len(sumry) > 1)
else:
pass
def test_spacy_summarization(self):
"""Pass the intervals to summarizer"""
if "spacy" in SUMMS:
asd = [{'minutes': 60, 'size' : 2, 'txt' : u'Summary for first 60 minutes:\n'}, {'hours':12, 'size' : 1, 'txt' : u'Summary for last 12 hours:\n'}]
summ = None
lsa_summ = lsa.LsaSummarizer()
summ = SpacyTsSummarizer()
for rs in asd:
summ.set_summarizer(lsa_summ)
summ.set_channel('elasticsearch')
logger.debug("Testing spacy summarizer")
sumry = summ.summarize(TestSummarize.test_msgs, range_spec=rs)
logger.debug("Summary is %s, length %s", sumry, len(sumry))
self.assertTrue(len(sumry) > 1)
else:
pass
if __name__ == '__main__':
unittest.main()