開始使用免費開始

TM 複習(I)

Text Mining: Bag of Words 課程中,你學到 corpus 是一組文本,並學過一些前處理文字的函式。快速複習一下,建立並清理 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 中第一個文件的內容。
    • corpus 中的文件以清單語法存取,所以請使用雙中括號,例如 [[1]]
  • 使用自訂函式 clean_corpus() 清理 tm_corpus 的文字。將新物件命名為 tm_clean
  • 再次檢視新物件 tm_clean 的第一個文件,看看套用 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
___
編輯並執行程式碼