>自然语言处理(NLP)是人类语言的自动或半自动处理。 NLP与语言学密切相关,并与认知科学,心理学,生理学和数学的研究有联系。特别是在计算机科学领域中,NLP与编译器技术,形式语言理论,人类计算机互动,机器学习和定理证明有关。这个Quora问题显示了NLP。
的不同优点,在本教程中,我将带您浏览一个有趣的NLP平台,称为自然语言工具包(NLTK)。在我们查看如何使用此平台之前,让我首先告诉您NLTK是什么。
"Python is a very high-level programming language. Python is interpreted."<br>
word_tokenize()
from nltk.tokenize import word_tokenize
text = "Python is a very high-level programming language. Python is interpreted."<br>print(word_tokenize(text))
['Python', 'is', 'a', 'very', 'high-level', 'programming', 'language', '.', 'Python', 'is', 'interpreted', '.']<br>
方法中。
from nltk.corpus import stopwords<br>print(set(stopwords.words('English')))<br>>请考虑以下文本。
from nltk.corpus import stopwords<br>print(set(stopwords.words('german')))<br>方法来tokenize。输出:
from nltk.corpus import stopwords<br>from nltk.tokenize import word_tokenize<br><br>text = 'In this tutorial, I\'m learning NLTK. It is an interesting platform.'<br>stop_words = set(stopwords.words('english'))<br>words = word_tokenize(text)<br><br>new_sentence = []<br><br>for word in words:<br> if word not in stop_words:<br> new_sentence.append(word)<br><br>print(new_sentence)<br>您可以从输出中看到,标点符号也被认为是单词。它们。以下内容:
word_tokenize()
word_tokenize()函数是:<code> word_tokenize()<blockquote>将字符串引用以拆分标点符号,而不是</blockquote>
<h3>>搜索</h3> <p>假设我们有以下文本文件(从dropbox下载文本文件)。我们想查找(搜索)单词<code>language
。我们可以简单地使用NLTK平台进行以下操作:
"Python is a very high-level programming language. Python is interpreted."<br>
在这种情况下,您将获得以下输出:
请注意,除了某些上下文中,concordance()
language
还返回单词nltk.Text
的每一次出现。 Before that, as shown in the script above, we tokenize the read file and then convert it into an
from nltk.tokenize import word_tokenize
text = "Python is a very high-level programming language. Python is interpreted."<br>print(word_tokenize(text))
: 。我只在本教程中划过表面。如果您想更深入地将NLTK用于不同的NLP任务,则可以参考NLTK的随附书:使用Python的自然语言处理。 > >该帖子已通过Esther Vaati的贡献进行了更新。 Esther是Envato Tuts的软件开发人员和作者。chcp 65001
What I simply did to solve this issue is to run this command in my console before running the program:如Wikipedia中所述: Gutenberg compus
Project Gutenberg(PG)是一项志愿者,是为了数字化和归档文化作品而努力,以“鼓励电子书的创建和分布”。它是由迈克尔·哈特(Michael S. Hart)于1971年成立的,是最古老的数字图书馆。其集合中的大多数项目都是公共领域书籍的全文。该项目试图以持久的开放格式使它们尽可能免费,几乎可以在任何计算机上使用。截至2015年10月3日,Gutenberg项目在其收藏中达到了50,000件物品。
>上面脚本的输出将如下:['Python', 'is', 'a', 'very', 'high-level', 'programming', 'language', '.', 'Python', 'is', 'interpreted', '.']<br>
如果我们想找到文本文件的单词数正如我们在本教程中所看到的那样,
bryant-stories.txt
from nltk.corpus import stopwords<br>print(set(stopwords.words('English')))<br>
>>
以上是引入自然语言工具包(NLTK)的详细内容。更多信息请关注PHP中文网其他相关文章!