2

「 say say say make made 」を含むファイル「check_text.txt」があります。「say say say make make」を取得するためにステミングを実行したいと思います。stemDocument次のようにパッケージで使用しようとしましtmたが、「sais say make made」しか取得しません。過去時制の単語のステミングを実行する方法はありますか? 現実世界の自然言語処理でそうする必要がありますか? ありがとう!

filename = 'check_text.txt'
con <- file(filename, "rb")
text_data <- readLines(con,skipNul = TRUE)
close(con)
text_VS <- VectorSource(text_data)
text_corpus <- VCorpus(text_VS)
text_corpus <- tm_map(text_corpus, stemDocument, language = "english")
as.data.frame(text_corpus)$text

編集:私もパッケージで試しwordStemましたSnowballC

> library(SnowballC)
> wordStem(c("said", "say", "says", "make", "made"))
[1] "said" "sai"  "sai"  "make" "made"
4

1 に答える 1

4

パッケージに英語の不規則動詞のデータセットがあれば、この作業は簡単です。そのようなデータを含むパッケージを知らないだけなので、スクレイピングによって独自のデータベースを作成することにしました。このウェブサイトがすべての不規則な単語を網羅しているかどうかはわかりません。必要に応じて、より良い Web サイトを検索して、独自のデータベースを作成します。データベースを取得したら、タスクに取り組むことができます。

まず、stemDocument()現在のフォームを -s で使用してクリーンアップしました。次に、過去形words(ie, past) を集め、過去形の不定形(ie, ) を集め、過去形inf1の順序を で特定しましたtemp。さらに、過去形の位置をtemp. 最後に、土形を不定形に置き換えました。過去分詞についても同じ手順を繰り返しました。

library(tm)
library(rvest)
library(dplyr)
library(splitstackshape)


### Create a database
x <- read_html("http://www.englishpage.com/irregularverbs/irregularverbs.html")

x %>%
html_table(header = TRUE) %>%
bind_rows %>%
rename(Past = `Simple Past`, PP = `Past Participle`) %>%
filter(!Infinitive %in% LETTERS) %>%
cSplit(splitCols = c("Past", "PP"),
       sep = " / ", direction = "long") %>%
filter(complete.cases(.)) %>%
mutate_each(funs(gsub(pattern = "\\s\\(.*\\)$|\\s\\[\\?\\]",
                      replacement = "",
                      x = .))) -> mydic

### Work on the task

words <- c("said", "drawn", "say", "says", "make", "made", "done")

### says to say
temp <- stemDocument(words)

### past forms become present form
### Collect past forms
past <- mydic$Past[which(mydic$Past %in% temp)]

### Collect infinitive forms of past forms
inf1 <- mydic$Infinitive[which(mydic$Past %in% temp)]

### Identify the order of past forms in temp
ind <- match(temp, past)
ind <- ind[is.na(ind) == FALSE]

### Where are the past forms in temp?
position <- which(temp %in% past)

temp[position] <- inf1[ind]

### Check
temp
#[1] "say"   "drawn" "say"   "say"   "make"  "make"  "done" 


### PP forms to infinitive forms (same as past forms)

pp <- mydic$PP[which(mydic$PP %in% temp)]
inf2 <- mydic$Infinitive[which(mydic$PP %in% temp)]
ind <- match(temp, pp)
ind <- ind[is.na(ind) == FALSE]
position <- which(temp %in% pp)
temp[position] <- inf2[ind]

### Check
temp
#[1] "say"  "draw" "say"  "say"  "make" "make" "do" 
于 2016-03-26T10:14:24.100 に答える