我正在尝试启动一个情绪分析项目,我将使用停用词方法.我做了一些研究,我发现nltk有停用词,但是当我执行命令时出现错误.
我所做的是以下内容,以便了解nltk使用的单词(就像你在http://www.nltk.org/book/ch02.html第 4.1节中找到的那样):
from nltk.corpus import stopwords
stopwords.words('english')
Run Code Online (Sandbox Code Playgroud)
但当我按下回车时,我获得了
---------------------------------------------------------------------------
LookupError Traceback (most recent call last)
<ipython-input-6-ff9cd17f22b2> in <module>()
----> 1 stopwords.words('english')
C:\Users\Usuario\Anaconda\lib\site-packages\nltk\corpus\util.pyc in __getattr__(self, attr)
66
67 def __getattr__(self, attr):
---> 68 self.__load()
69 # This looks circular, but its not, since __load() changes our
70 # __class__ to something new:
C:\Users\Usuario\Anaconda\lib\site-packages\nltk\corpus\util.pyc in __load(self)
54 except LookupError, e:
55 try: root = nltk.data.find('corpora/%s' % zip_name)
---> 56 except LookupError: raise e
57
58 # Load the corpus.
LookupError: …Run Code Online (Sandbox Code Playgroud) 我正在玩NLTK来做一个关于情绪分析的任务.我使用的是Python 2.7.NLTK 3.0和NUMPY 1.9.1版本.
这是代码:
__author__ = 'karan'
import nltk
import re
import sys
def main():
print("Start");
# getting the stop words
stopWords = open("english.txt","r");
stop_word = stopWords.read().split();
AllStopWrd = []
for wd in stop_word:
AllStopWrd.append(wd);
print("stop words-> ",AllStopWrd);
# sample and also cleaning it
tweet1= 'Love, my new toyí ½í¸í ½í¸#iPhone6. Its good http://t.co/sHY1cab7sx'
print("old tweet-> ",tweet1)
tweet1 = tweet1.lower()
tweet1 = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)"," ",tweet1).split())
print(tweet1);
tw = tweet1.split()
print(tw)
#tokenize
sentences = nltk.word_tokenize(tweet1)
print("tokenized ->", sentences)
#remove …Run Code Online (Sandbox Code Playgroud) 我的项目使用NLTK.如何列出项目的语料库和模型要求,以便自动安装?我不想点击nltk.download()GUI,逐个安装软件包.
还有,任何方法来冻结相同的要求列表(如pip freeze)?
我想在python中使用wordnet lemmatizer并且我已经知道默认的pos标签是NOUN并且它没有为动词输出正确的引理,除非明确指定了pos标签作为VERB.
我的问题是,准确执行上述词形还原的最佳镜头是什么?
我做了pos标记使用nltk.pos_tag,我迷失了将树库pos标签集成到wordnet兼容的pos标签.请帮忙
from nltk.stem.wordnet import WordNetLemmatizer
lmtzr = WordNetLemmatizer()
tagged = nltk.pos_tag(tokens)
Run Code Online (Sandbox Code Playgroud)
我得到NN,JJ,VB,RB的输出标签.如何将这些更改为wordnet兼容标签?
我还需要nltk.pos_tag()使用带标记的语料库进行训练,还是可以直接在我的数据上进行评估?
我有以下代码
import nltk, os, json, csv, string, cPickle
from scipy.stats import scoreatpercentile
lmtzr = nltk.stem.wordnet.WordNetLemmatizer()
def sanitize(wordList):
answer = [word.translate(None, string.punctuation) for word in wordList]
answer = [lmtzr.lemmatize(word.lower()) for word in answer]
return answer
words = []
for filename in json_list:
words.extend([sanitize(nltk.word_tokenize(' '.join([tweet['text']
for tweet in json.load(open(filename,READ))])))])
Run Code Online (Sandbox Code Playgroud)
我写的时候,我在一个单独的testing.py文件中测试过2-4行
import nltk, os, json, csv, string, cPickle
from scipy.stats import scoreatpercentile
wordList= ['\'the', 'the', '"the']
print wordList
wordList2 = [word.translate(None, string.punctuation) for word in wordList]
print wordList2
answer = [lmtzr.lemmatize(word.lower()) for word …Run Code Online (Sandbox Code Playgroud) 我正在使用nltk,所以我想创建自己的自定义文本,就像nltk.books上的默认文本一样.但是,我刚刚接受了这样的方法
my_text = ['This', 'is', 'my', 'text']
Run Code Online (Sandbox Code Playgroud)
我想发现任何方式输入我的"文本":
my_text = "This is my text, this is a nice way to input text."
Run Code Online (Sandbox Code Playgroud)
哪种方法,python或者nltk允许我这样做.更重要的是,我怎么能低估标点符号呢?
关于如何保存训练有素的分类器,我有点困惑.就像在每次我想要使用它时重新训练分类器显然是非常糟糕和缓慢的,我如何保存它并在需要时再次加载它?代码如下,提前感谢您的帮助.我正在使用Python和NLTK朴素贝叶斯分类器.
classifier = nltk.NaiveBayesClassifier.train(training_set)
# look inside the classifier train method in the source code of the NLTK library
def train(labeled_featuresets, estimator=nltk.probability.ELEProbDist):
# Create the P(label) distribution
label_probdist = estimator(label_freqdist)
# Create the P(fval|label, fname) distribution
feature_probdist = {}
return NaiveBayesClassifier(label_probdist, feature_probdist)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用NLTK从我的文本中提取命名实体.我发现NLTK NER对我的目的不是很准确,我想添加一些我自己的标签.我一直在努力寻找培养自己的NER的方法,但我似乎无法找到合适的资源.我有几个关于NLTK的问题 -
我真的很感谢这方面的帮助
我很好奇是否存在通过使用一些权重计算,出现率或其他工具从给定文本生成关键字/标签的算法/方法.
另外,如果您为此指出任何基于Python的解决方案/库,我将不胜感激.
谢谢
我正在尝试使用bs4删除所有的html/javascript,但是,它并没有摆脱javascript.我仍然在那里看到它的文字.我怎么能绕过这个?
我试着用nltk然而,工作正常,clean_html并且clean_url将被删除向前发展.有没有办法使用汤get_text并获得相同的结果?
我试着看看这些其他页面:
BeautifulSoup get_text不会删除所有标记和JavaScript
目前我正在使用nltk已弃用的功能.
编辑
这是一个例子:
import urllib
from bs4 import BeautifulSoup
url = "http://www.cnn.com"
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
print soup.get_text()
Run Code Online (Sandbox Code Playgroud)
我仍然看到CNN的以下内容:
$j(function() {
"use strict";
if ( window.hasOwnProperty('safaripushLib') && window.safaripushLib.checkEnv() ) {
var pushLib = window.safaripushLib,
current = pushLib.currentPermissions();
if (current === "default") {
pushLib.checkPermissions("helloClient", function() {});
}
}
});
/*globals MainLocalObj*/
$j(window).load(function () {
'use strict';
MainLocalObj.init();
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能删除js?
我找到的其他选项是:
https://github.com/aaronsw/html2text
问题html2text在于它有时真的很慢,并且会产生明显的滞后,这是nltk总是非常好的一件事.
nltk ×10
python ×9
nlp ×4
corpus ×1
install ×1
naivebayes ×1
packages ×1
requirements ×1
stop-words ×1
tags ×1
tokenize ×1
typeerror ×1
unicode ×1
wordnet ×1