Ejemplo n.º 1
0
def main():
    t = normal.zh2hans(text)
    sents = normal.get_sentences(t)
    doc = []
    for sent in sents:
        words = seg.seg(sent)
        words = normal.filter_stop(words)
        doc.append(words)
    rank = textrank.TextRank(doc)
    rank.solve()
    for index in rank.top_index(5):
        print(sents[index])
    keyword_rank = textrank.KeywordTextRank(doc)
    keyword_rank.solve()
    for w in keyword_rank.top_index(5):
        print(w)
Ejemplo n.º 2
0
def parse_keyword(text):
    t = normal.zh2hans(text.decode("UTF-8"))
    sents = normal.get_sentences(t)
    doc = []
    for sent in sents:
        words = seg.seg(sent)
        words = normal.filter_stop(words)
        doc.append(words)
    
    keywords = []
    keyword_rank = textrank.KeywordTextRank(doc)
    keyword_rank.solve()
    for w in keyword_rank.top_index(5):
        keywords.append(w)
    
    return keywords
Ejemplo n.º 3
0
def query_xym():
    offset = request.values['offset']
    pagesize = request.values['pageSize']

    resp = XymTripModel.query.offset(offset).limit(pagesize)
    t = normal.zh2hans(
        "随着智能手机和平板电脑的普及,相机也变得无处不在,而且分享照片也越来越简单。MOOC的明星教授说,把45分钟的讲座变成10分钟一段的视频让他们被迫“升级课程”。不是每个老师都能通过这种方式吸引一批学生,但是他们可以参考这个经验,为课堂制作自己的视频,例如实地考察录像。让整个班都出去跑一趟可能不可行,但利用视频和照片,可以把考察点“带”到课室中来。利用智能手机耳机上配备的话筒,还可以为视频配上讲解,从而高效地用多个视频介绍完一个知识点。"
    )
    sents = normal.get_sentences(t)
    doc = []
    for sent in sents:
        words = seg.seg(sent)
    words = normal.filter_stop(words)
    doc.append(words)
    rank = textrank.TextRank(doc)
    rank.solve()
    for index in rank.top_index(5):
        print(sents[index])
    keyword_rank = textrank.KeywordTextRank(doc)
    keyword_rank.solve()
    for w in keyword_rank.top_index(5):
        print(w)
    return "\'..."
Ejemplo n.º 4
0
def getJson(fold, filename):
    result = {}
    try:
        count = 0
        cotent = u''
        title = ''
        time = ''
        abstract = ''
        path = fold + '/' + filename
        # ========================================
        #    读取文件的时间、标题、内容
        # ========================================
        for line in open(path, 'r'):
            if (count == 0):
                title = line
                count += 1
                # print (title)
                continue
            if (count == 1):
                time = line
                count += 1
                # print (time)
                continue
            if (count > 1):
                count += 1
                cotent += line
                # print (line)

        # ========================================
        #      生成摘要
        # =======================================

        t = normal.zh2hans(cotent)
        sents = normal.get_sentences(t)
        doc = []
        for sent in sents:
            words = seg.seg(sent)
            words = normal.filter_stop(words)
            doc.append(words)
        rank = textrank.TextRank(doc)
        rank.solve()
        for index in rank.top_index(5):
            abstract = abstract + sents[index] + ' '
        keyword_rank = textrank.KeywordTextRank(doc)
        keyword_rank.solve()
        word0 = {}
        word1 = {}
        word2 = {}
        word3 = {}
        word4 = {}
        wordcount = 0
        for w in keyword_rank.top_index(5):
            if wordcount == 0:
                word0["word"] = w
                word0["frequency"] = float(cotent.count(w)) / float(
                    len(cotent))

            if wordcount == 1:
                word1["word"] = w
                word1["frequency"] = float(cotent.count(w)) / float(
                    len(cotent))
            if wordcount == 2:
                word2["word"] = w
                word2["frequency"] = float(cotent.count(w)) / float(
                    len(cotent))
            if wordcount == 3:
                word3["word"] = w
                word3["frequency"] = float(cotent.count(w)) / float(
                    len(cotent))
            if wordcount == 4:
                word4["word"] = w
                word4["frequency"] = float(cotent.count(w)) / float(
                    len(cotent))
            wordcount += 1

        s = SnowNLP(cotent)
        score = (s.sentiments - 0.5) * 2  # -1-1规范化

        keywords = [word0, word1, word2, word3, word4]
        result["code"] = 0
        result["message"] = "sucess"
    except IOError:
        result["code"] = 1
        result["message"] = "wrong format"
        return result

    result["tilte"] = title.strip()
    result["time"] = time.strip()
    result['abstract'] = abstract
    result['sentiment'] = score
    result["keywords"] = keywords

    return result
Ejemplo n.º 5
0
6.用好你的相机
随着智能手机和平板电脑的普及,相机也变得无处不在,而且分享照片也越来越简单。MOOC的明星教授说,把45分钟的讲座变成10分钟一段的视频让他们被迫“升级课程”。不是每个老师都能通过这种方式吸引一批学生,但是他们可以参考这个经验,为课堂制作自己的视频,例如实地考察录像。让整个班都出去跑一趟可能不可行,但利用视频和照片,可以把考察点“带”到课室中来。利用智能手机耳机上配备的话筒,还可以为视频配上讲解,从而高效地用多个视频介绍完一个知识点。

将MOOC应用到传统课堂教学
随着大规模网络公开课的发展,教师可以考虑把在线教育的方法应用到自己的课堂教学中。MOOC的课程制作涉及比较复杂的技术,但使用这些课程几乎不费吹灰之力,而且成本也远远不及课程制作。没有加入edX或Coursera的大部分学校可以进行更多自创内容的尝试,就像自出版一样,这也是许多cMOOC的尝试。教师也可以向自己的目标努力。通过打开课堂,建立网络社区和制作教学视频,可以让更多的教师和学生享受到MOOC的投入带来的收益。
'''


from snownlp import normal
from snownlp import seg
from snownlp.summary import textrank


if __name__ == '__main__':
    t = normal.zh2hans(text)
    sents = normal.get_sentences(t)
    doc = []
    for sent in sents:
        words = seg.seg(sent)
        words = normal.filter_stop(words)
        doc.append(words)
    rank = textrank.TextRank(doc)
    rank.solve()
    for index in rank.top_index(5):
        print(sents[index])
    keyword_rank = textrank.KeywordTextRank(doc)
    keyword_rank.solve()
    for w in keyword_rank.top_index(5):
        print(w)