用R编辑句子开始<s>和结束</s>进行预测

时间:2016-03-22 08:27:58

标签: regex r string tags sentence

我正在构建一个NLP模型来预测R中的下一个单词。所以,对于3个句子语料库:

a<-"i like cheese"

b<-"the dog like cat"

c<-"the cat eat cheese"

我希望它成为:

>a
 "<.s> i like cheese <./s>"

>b
 "<.s> the dog like cat <./s>"

>c
 "<.s> the cat eat cheese <./s>"

有没有比这更简单的方法:

a<-Unlist(strsplit(a, " "))
a[1]<-"<.s>"
a[length(a)]<-"./s>"
a<-paste(a, collapse = " ")
> a 
 "<.s> i like cheese <./s>"

1 个答案:

答案 0 :(得分:0)

您只是连接字符串,所以这应该可以工作:

 a <- paste("<.s>", a, "<./s>")
相关问题