标签: text-analysis

Python降序的wordcount

我正在使用此代码计算文本文件中单词出现的频率:

#!/usr/bin/python
file=open("out1.txt","r+")
wordcount={}
for word in file.read().split():
    if word not in wordcount:
        wordcount[word] = 1
    else:
        wordcount[word] += 1
for k,v in wordcount.items():
    print k, v
Run Code Online (Sandbox Code Playgroud)

如何按频率编号的降序打印输出?

python frequency text-analysis word-count

1
推荐指数
1
解决办法
3323
查看次数

在Python中使用nltk模块拆分单词

我正在尝试找到一种使用nltk模块在Python中拆分单词的方法。考虑到我拥有的原始数据(例如带符号词的列表),我不确定如何达到我的目标

['usingvariousmolecularbiology', 'techniques', 'toproduce', 'genotypes', 'following', 'standardoperatingprocedures', '.', 'Operateandmaintainautomatedequipment', '.', 'Updatesampletrackingsystemsandprocess', 'documentation', 'toallowaccurate', 'monitoring', 'andrapid', 'progression', 'ofcasework']
Run Code Online (Sandbox Code Playgroud)

如您所见,许多单词被粘在一起(即“ to”和“ produce”被粘在一个字符串“ toproduce”中)。这是从PDF文件中抓取数据的一种人工产物,我想找到一种使用python中的nltk模块将卡住的单词拆分(即,将“ toproduce”拆分为两个单词:“ to”和“ produce”的方法);将“ standardoperatingprocedures”分为三个词:“ standard”,“ operating”,“ procedures”)。

感谢您的帮助!

python text-processing text-analysis nltk python-textprocessing

1
推荐指数
1
解决办法
1293
查看次数

R错误:inherits(x,c("DocumentTermMatrix","TermDocumentMatrix"))不是TRUE

我正在使用以下代码创建文档术语矩阵.我创建矩阵没有问题,但当我尝试删除稀疏术语或查找常用术语时,我收到错误.

text<- c("Since I love to travel, this is what I rely on every time.", 
         "I got this card for the no international transaction fee", 
         "I got this card mainly for the flight perks",
         "Very good card, easy application process",
         "The customer service is outstanding!") 

library(tm)
corpus<- Corpus(VectorSource(text))
corpus<- tm_map(corpus, content_transformer(tolower))
corpus<- tm_map(corpus, removePunctuation)
corpus<- tm_map(corpus, removeWords, stopwords("english"))
corpus<- tm_map(corpus, stripWhitespace)

dtm<- as.matrix(DocumentTermMatrix(corpus))
Run Code Online (Sandbox Code Playgroud)

结果如下:

Docs    application card    customer    easy    every ... etc.
1       0           0       0           1       0
2       0 …
Run Code Online (Sandbox Code Playgroud)

nlp r text-analysis tm

0
推荐指数
1
解决办法
1373
查看次数

分析成人内容识别文本的正确方法是什么?

我想过滤掉推文中的成人内容(或任何文本).

对于垃圾邮件检测,我们有数据集可以检查特定文本是垃圾邮件还是火腿.

对于成人内容,我找到了我想要使用的数据集(下面提取):

arrBad = [
'acrotomophilia',
'anal',
'anilingus',
'anus',
.
. etc.
.
'zoophilia']
Run Code Online (Sandbox Code Playgroud)

如何使用该数据集过滤文本实例?

python text-analysis nltk text-classification

-3
推荐指数
1
解决办法
1246
查看次数