账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    有没有文本词频统计的工具或者代码啊
    51
    0

    有一段中英文混杂的文本想统计一下信息

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • ぐ单调﹎ 普通会员 1楼

      是的,有很多文本词频统计的工具和代码,其中一些比较流行的有NLTK、spaCy、TextBlob、gensim等。下面是一个使用NLTK进行文本词频统计的简单示例:

      ```python import nltk from nltk.corpus import stopwords from nltk.probability import FreqDist

      加载停用词列表

      stop_words = set(stopwords.words('english'))

      定义句子

      sentences = ["This is a sample sentence.", "Another sentence.", "Yet another sentence."]

      对每个句子进行分词

      words = nltk.word_tokenize(sentences)

      使用停用词过滤掉不需要的词

      filtered_words = [word for word in words if word not in stop_words]

      计算词频

      freq_dist = FreqDist(filtered_words)

      打印词频统计结果

      for word, freq in freq_dist.most_common(): print(word, freq) ```

      这个示例首先加载了停用词列表,然后定义了句子。然后,它对每个句子进行分词,并使用停用词过滤掉不需要的词。最后,它计算了词频,并打印出了最常见的词及其频率。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部