句読点が含まれていない文字列「/」を置き換えることを目指します。特定の句読点が含まれていない文字列を置換するR
sentence = 'I/NP to/INF this/NP like/CON that/NP Peter wow er ! is'
'/ UN' でそれらをタグ付けする必要があるので、これらの要素は、 '/' で立ち往生していない[ピーターは、すごい、!、えー、あります]。
これは、私はしかし、残念ながら、私は何を得たことは、以下のこの結果であり、この
seg = unlist(strsplit(sentence, '[[:space:]]+'))
segment = seg[!grepl('\\/',seg)]
replace = gsub('(\\S+)','\\1/UN',segment)
library(stringr)
mgsub <- function(pattern, replacement, x, ...) {
if (length(pattern)!=length(replacement)) {
stop("pattern and replacement do not have the same length.")
}
result <- x
for (i in 1:length(pattern)) {
result <- gsub(pattern[i], replacement[i], result, ...)
}
result
}
mgsub(segment, replace, sentence)
のために試してみたものです。
[1] "I/NP to/INF this/UN/NP like/CON that/NP Peter/UN/UN wow/UN er/UN !/UN is/UN"
これは私が達成することを目指すものです: - sentence
が、コードはそれらのすべてを得ることができますので、より多くの可能な例を考えてみ
[1] "I/NP to/INF this/NP like/CON that/NP Peter/UN wow/UN er/UN !/UN is/UN"
はサンプルで立ち往生されないようにしてください。
好奇心をそらしてどのようにPOSタグを生成していますか?私は、OpenNLPがあなたの残り物をタグ付けしていると仮定します... –