示例#1
0
def slackReq():
    global lsa_summ
    if "spacy" in SUMMS:
        if not lsa_summ:
            lsa_summ = lsa.LsaSummarizer()
    req_data = request.form
    req = {
        'channel_id': req_data.getlist('channel_id'),
        'channel_name': maybe_get(req_data, 'channel_name', default=''),
        'user_id': maybe_get(req_data, 'user_id', default=''),
        'user_name': maybe_get(req_data, 'user_name', default=''),
        'params': maybe_get(req_data, 'text', default=''),
        'summ': lsa_summ
    }
    if "gensim" in SUMMS and "gensim" in req['params'].split():
        req['summ'] = None
    return (SlackRouter().get_summary(**req))
示例#2
0
 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
示例#3
0
from flask import Flask, jsonify, request
import requests
import json
import os
from config import *
from ts_config import SUMMS
from slack_summary import SlackRouter
app = Flask(__name__)
from utils import maybe_get
global lsa_summ
lsa_summ = None
if "spacy" in SUMMS:
    import lsa
    import spacy.en
    import spacy
    lsa_summ = lsa.LsaSummarizer()


@app.route("/slack", methods=['POST'])
def slackReq():
    global lsa_summ
    if "spacy" in SUMMS:
        if not lsa_summ:
            lsa_summ = lsa.LsaSummarizer()
    req_data = request.form
    req = {
        'channel_id': req_data.getlist('channel_id'),
        'channel_name': maybe_get(req_data, 'channel_name', default=''),
        'user_id': maybe_get(req_data, 'user_id', default=''),
        'user_name': maybe_get(req_data, 'user_name', default=''),
        'params': maybe_get(req_data, 'text', default=''),
示例#4
0
class TestSummarize(unittest.TestCase):

    test_msgs = test_json_msgs
    summ = SpacyTsSummarizer()
    summ.set_summarizer(lsa.LsaSummarizer())

    @given(lists(elements=sampled_from(test_json_msgs), min_size=3),
           integers(min_value=1, max_value=20),
           settings=hs.Settings(timeout=1000))
    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)
        }
        #TestSummarize.summ.set_interval()
        TestSummarize.summ.set_channel('elasticsearch')
        sumry = TestSummarize.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),
           settings=hs.Settings(timeout=1000))
    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)
        }
        #TestSummarize.summ.set_interval(asd)
        TestSummarize.summ.set_channel('elasticsearch')
        sumry = TestSummarize.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),
           settings=hs.Settings(timeout=1000))
    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)
        }
        #TestSummarize.summ.set_interval()
        TestSummarize.summ.set_channel(channel)
        sumry = TestSummarize.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),
           settings=hs.Settings(timeout=1000))
    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)
        }
        #TestSummarize.summ.set_interval()
        TestSummarize.summ.set_channel('elasticsearch')
        sumry = TestSummarize.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),
           settings=hs.Settings(timeout=1000))
    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)
        }
        #TestSummarize.summ.set_interval()
        TestSummarize.summ.set_channel('elasticsearch')
        sumry = TestSummarize.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),
           settings=hs.Settings(timeout=1000))
    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):]
        TestSummarize.summ.set_channel(channel)
        logger.info("Input is segment is %s", samp)
        asd = {
            'hours': hours,
            'size': 3,
            'txt': u'Summary for first {} hours:\n'.format(hours)
        }
        sumry = TestSummarize.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)