1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
tagPOS <- function(x, ...) {
s <- as.String(x)
word_token_annotator <- Maxent_Word_Token_Annotator()
a2 <- Annotation(1L, "sentence", 1L, nchar(s))
a2 <- annotate(s, word_token_annotator, a2)
a3 <- annotate(s, Maxent_POS_Tag_Annotator(), a2)
a3w <- a3[a3$type == "word"]
POStags <- unlist(lapply(a3w$features, `[[`, "POS"))
POStagged <- paste(sprintf("%s/%s", s[a3w], POStags), collapse = " ")
list(POStagged = POStagged, POStags = POStags)}
length(phrase)
for (indice in 3:length(phrase)){
test <- data.frame(tagPOS(phrase[indice]))
b <- test$POStagged
a <- data.frame(test$POStags)
splt <- str_split(b[1],"/")
for (p in 1:nrow(a)){
if (a[p,]=="NN"){
q = p-1
while (a[q,]!="JJ"){
q <- q-1
}
print(str_sub(splt[[1]][q],4))
print(str_sub(splt[[1]][p],4))
}
}
} |
Partager