はきちんとテキストマイニングパッケージWIH可能なアプローチである: (その依存関係を確認...-
library(tidytext) # install.packages("tidytext")
library(tidyr) # install.packages("tidyr")
library(dplyr) # install.packages("dplyr")
dd <- data.frame(
text = c("hello how are you doing thank
you for helping me with this
problem","junk","junk"), stringsAsFactors = F)
私は言葉の地平線についてのごパラメータscope
として言及。あなたのコメントについて
scope=3
dd %>%
unnest_tokens(ngram, text, token = "ngrams", n = 1+scope) %>%
separate(ngram, paste("word",1:(scope+1),sep=""), sep = " ") %>%
filter(word1 %in% c("how")) %>% apply(.,1,paste, collapse= " ")
[1] "how are you doing"
:簡単な関数に以下のコードをオンにする:あなたは、文字列で終わるしたい場合
scope=2
dd %>%
unnest_tokens(ngram, text, token = "ngrams", n = 1+scope) %>%
separate(ngram, paste("word",1:(scope+1),sep=""), sep = " ") %>%
filter(word1 %in% c("how","me"))
# A tibble: 2 × 3
word1 word2 word3
<chr> <chr> <chr>
1 how are you
2 me with this
、あなたがngramsをバック崩壊する必要があり、例えばCF、この第二の例: チャンク(文字列)ごとにチャンク(文字列)を処理する場合は、このグループを明示的に処理する必要があります。本当に
scope=2
subsets <-
dd %>%
mutate(id=1:length(text)) %>%
split(., .$id)
unlist(lapply(subsets, function(dd) {
dd %>%
unnest_tokens(ngram, text, token = "ngrams", n = 1+scope) %>%
separate(ngram, paste("word",1:(scope+1),sep=""), sep = " ") %>%
filter(word1 %in% c("how","problem")) %>%
apply(.,1,FUN=function(vec) paste(vec[-1],collapse=" "))
}))
1
"how are you"
正規表現の第一人者ないが、これはあなたを助けるかもしれない:ここで は、例えば方法ですhttps://regex101.com/r/95g7yT/1 – digEmAll
何があなたの場合は、結果として見ることを期待します'' how '''と '' ''と '' N = 3のように2つの用語を指定しますか?また、2つの用語の間の距離が3ワード未満であれば、「hello」と「are」を選んだのと同じですか? –
1 - "how"または "with"とN = 3の2つの用語を使用して、 "この問題でどうやってやっているの?" 2番目の単語「with」の結果は、文字列の最後まで単語を保持するだけです。 2 - 用語が「こんにちは」と「ある」の場合、可能な場合は「こんにちはお元気できていますか? – BEMR