나는 특정 구두점을 포함하지 않는 문자열 ('/')을 대체하려고합니다.특정 구두점이 포함되지 않은 문자열 바꾸기 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)
위해 노력했습니다 것입니다. sentence
하지만 코드가 그들 모두를 얻을 수 있도록 더 많은 수의 예를 고려 -
[1] "I/NP to/INF this/NP like/CON that/NP Peter/UN wow/UN er/UN !/UN is/UN"
하십시오 시료와 붙어하지 않습니다
[1] "I/NP to/INF this/UN/NP like/CON that/NP Peter/UN/UN wow/UN er/UN !/UN is/UN"
이 내가 달성하는 것을 목표로하는 것이다.
호기심에 서서 어떻게 POS 태그를 생성하고 있습니까? 나는 예를 들어 OpenNLP가 당신의 남은 음식에 꼬리표를 붙이고 있다고 가정 할 것이다 ... –