【发布时间】:2018-05-29 10:42:59
【问题描述】:
这是我的示例文本:
text = "First sentence. This is a second sentence. I like pets e.g. cats or birds."
我有一个按句子分割文本的功能
library(stringi)
split_by_sentence <- function (text) {
# split based on periods, exclams or question marks
result <- unlist(strsplit(text, "\\.\\s|\\?|!") )
result <- stri_trim_both(result)
result <- result [nchar (result) > 0]
if (length (result) == 0)
result <- ""
return (result)
}
实际上是由标点符号分割的。这是输出:
> split_by_sentence(text)
[1] "First sentence" "This is a second sentence" "I like pets e.g" "cats or birds."
是否有可能排除“例如”之类的特殊模式?
【问题讨论】:
-
谢谢,但您的解决方案删除了“例如”。我想保留这个。