文件分词以及提取关键词

本文介绍了一个使用Python进行歌词分析的过程,包括文件分词、剔除非歌词信息、应用TF-IDF进行关键词提取。作者注意到TF-IDF在歌词分析中的局限性,如特殊分词导致的异常结果,并分享了具体的算法实现。最后,生成了包含所有歌手分词后歌词的concat文件夹。
摘要由CSDN通过智能技术生成

首先我的原始数据是这样的,关于爬虫请看http://blog.csdn.net/jemila/article/details/61196863

我的数据链接:http://pan.baidu.com/s/1hskNlEO 密码:dxv5


加载以下模块

import os
import jieba
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
from langconv import *


from langconv import *加载这个模块是为了简繁转换

加载停止词

f=open(r'C:/Users/user/Desktop/stopword.txt')
stopwords = f.readlines()
stopwords = [i.replace("\n","").decode("gbk") for i in stopwords]

定义一个分词函数

def sent2word(sentence):
    """
    Segment a sentence to words
    Delete stopwords
    """
    segList = jieba.cut(sentence)
    segResult = []
    for w in segList:
        segResult.append(w)
    newSent = []
    for word in segResult:
        if word in stopwords:
            # print "stopword: %s" % word
            continue
        else:
            newSent.append(Converter('zh-hans').convert(word.decode('utf-8')))


    return newSent

定义一个新建文件夹函数

def mkdir(path):
    # 引入模块
    import os
 
    # 去除首位空格
    path&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值