开始使用免费开始使用

TM 回顾(I)

在课程 Text Mining: Bag of Words 中,您学习了语料库(corpus)是一组文本,并了解了若干用于预处理文本的函数。这里简要回顾一下:创建并清洗语料库的一种方式如下。尽管这是另一门课程,情感分析属于文本挖掘的一部分,因此复习会很有帮助。

在本练习中,我们已用常见的预处理函数构建了一个自定义的 clean_corpus() 函数,便于直接应用。

clean_corpus() 接收 VCorpus() 的输出并应用清洗函数。例如:

processed_corpus <- clean_corpus(my_corpus)

本练习是课程的一部分

R 中的情感分析

查看课程

练习说明

您的 R 会话中已提供一个文本向量 tm_define(包含两个短文档)以及函数 clean_corpus()

  • VectorSource() 应用于 tm_define,创建名为 tm_vector 的对象。
  • tm_vector 使用 VCorpus() 创建 tm_corpus
  • 使用 content() 查看 tm_corpus 中第 1 篇文档的内容。
    • 语料库中的文档通过列表语法访问,请使用双中括号,例如 [[1]]
  • tm_corpus 使用自定义函数 clean_corpus() 清洗文本。将新对象命名为 tm_clean
  • 再次查看新对象 tm_clean 的第 1 篇文档,比较应用 clean_corpus() 前后的变化。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# clean_corpus(), tm_define are pre-defined
clean_corpus
tm_define

# Create a VectorSource
tm_vector <- ___

# Apply VCorpus
tm_corpus <- ___

# Examine the first document's contents
___(___[[___]])

# Clean the text
tm_clean <- ___

# Reexamine the contents of the first doc
___
编辑并运行代码