大きな(n = 500,000)のコーパスを分析したい。私は、will be fasterよりtm_map()
より、tm
より、quanteda
を使用しています。私はdfm()
で自動化された方法を使用する代わりに、段階的に進めたいと思っています。私はこれに理由があります:あるケースでは、ストップワードを削除する前にトークン化したくないので、多くの無駄なバイグラムが発生し、別の言語では言語固有の手順でテキストを前処理する必要があります。量子化を使ってdfmをステップバイステップで作成する
私はこのシーケンスに実装されたい:句読点と数字
2を削除)
1)無用のトークンを避けるために、トークン化する前にストップワード(すなわち削除)
3)ユニグラムとバイグラム
4を使用してトークン化)DFMを作成
私の試み:
> library(quanteda)
> packageVersion("quanteda")
[1] ‘0.9.8’
> text <- ie2010Corpus$documents$texts
> text.corpus <- quanteda:::corpus(text, docnames=rownames(ie2010Corpus$documents))
> class(text.corpus)
[1] "corpus" "list"
> stopw <- c("a","the", "all", "some")
> TextNoStop <- removeFeatures(text.corpus, features = stopw)
# Error in UseMethod("selectFeatures") :
# no applicable method for 'selectFeatures' applied to an object of class "c('corpus', 'list')"
# This is how I would theoretically continue:
> token <- tokenize(TextNoStop, removePunct=TRUE, removeNumbers=TRUE)
> token2 <- ngrams(token,c(1,2))
ボーナス質問 quanteda
でスパーストークンを削除するにはどうすればよいですか? (。すなわちtm
でremoveSparseTerms()
の同等
UPDATE ケンの答え@の光で、ここquanteda
で段階的に進めるためのコードは次のとおりです。
library(quanteda)
packageVersion("quanteda")
[1] ‘0.9.8’
1)カスタムを削除します句読点と数字。例えば。 ie2010コーパスの "\ n"に気付く
text.corpus <- ie2010Corpus
texts(text.corpus)[1] # Use texts() to extrapolate text
# 2010_BUDGET_01_Brian_Lenihan_FF
# "When I presented the supplementary budget to this House last April, I said we
# could work our way through this period of severe economic distress. Today, I
# can report that notwithstanding the difficulties of the past eight months, we
# are now on the road to economic recovery.\nIt is
texts(text.corpus)[1] <- gsub("\\s"," ",text.corpus[1]) # remove all spaces (incl \n, \t, \r...)
texts(text.corpus)[1]
2010_BUDGET_01_Brian_Lenihan_FF
# "When I presented the supplementary budget to this House last April, I said we
# could work our way through this period of severe economic distress. Today, I
# can report that notwithstanding the difficulties of the past eight months, we
# are now on the road to economic recovery. It is of e
なぜ前処理をしたいのかという理由にさらに注意してください。私の現在のコーパスはイタリア語で、アポストロフィを持つ言葉に関連する記事がある言語です。したがって、ストレートdfm()
は、不正確なトークン化につながる可能性があります。 例えば:
broken.tokens <- dfm(corpus(c("L'abile presidente Renzi. Un'abile mossa di Berlusconi"), removePunct=TRUE))
同じ単語のための2つの分離されたトークンを生成する(「L'abile」「un'abile」と)、それ故にここでgsub()
と追加の工程の必要性。
2)quanteda
では、トークン化前のテキストでストップワードを直接削除することはできません。前の例では、誤解を招くバイグラムを生成しないように、 "l"と "un"を削除する必要があります。これはtm
とtm_map(..., removeWords)
で処理できます。
3)トークン化
token <- tokenize(text.corpus[1], removePunct=TRUE, removeNumbers=TRUE, ngrams = 1:2)
4)DFMを作成します。
dfm <- dfm(token)
5)
dfm <- trim(dfm, minCount = 5)
答えを書き留めるには、 'texts()'関数を使って 'quanteda'で段階的に進めることができます: – 000andy8484