0

我从 tm 对象移动到 koRpus 对象时遇到问题。我必须使用 tm 工具对语料库进行规范化,使用 koRpus 对结果进行词形还原,然后返回 tm 对结果进行分类。为此,我必须将 tm 对象转换为 R 数据帧,然后将其转换为 excel 文件,然后转换为 txt 文件,最后转换为 koRpus 对象。这是代码:

#from VCORPUS to DATAFRAME 
dataframeD610P<-data.frame(text=unlist(sapply(Corpus.TotPOS, `[`, "content")), stringsAsFactors=F)

#from DATAFRAME to XLSX 
#library(xlsx)
write.xlsx(dataframeD610P$text, ".\\mycorpus.xlsx")

#open with excel 
#save in csv (UTF-8)

#import in KORPUS and lemmatization with KORPUS/TREETAGGER 

tagged.results <- treetag(".\\mycorpus.csv", treetagger="manual", lang="it", sentc.end = c(".", "!", "?", ";", ":"),
                          TT.options=list(path="C:/TreeTagger", preset="it-utf8", no.unknown=T)) 

然后我需要向后做这一切才能回到 tm. 这是代码:

#from KORPUS to TXT 
write.table(tagged.results@TT.res$lemma, ".\\mycorpusLEMMATIZED.txt")

#open with a text editor and formatting of the text

#from TXT to R
Lemma1.POS<- readLines(".\\mycorpusLEMMATIZEDfrasi.txt", encoding = "UTF-8")

#from R object to DATAFRAME
Lemma2.POS<-as.data.frame(Lemma1.POS, encoding = "UTF-8")

#from DATAFRAME to CORPUS
CorpusPOSlemmaFINAL = Corpus(VectorSource(Lemma2.POS$Lemma1.POS))

有没有更优雅的解决方案可以在不离开 R 的情况下做到这一点?我非常感谢任何帮助或反馈。

顺便说一句,有谁知道如何询问 tm VCorpus 中的哪个文档包含特定令牌?我通常将语料库转换为数据框来识别文档。有没有办法在 tm 中做到这一点?

4

1 回答 1

0

感谢 unDocUMeantIt,可以在这里找到一些答案https://github.com/unDocUMeantIt/koRpus/issues/6

于 2017-02-20T14:13:24.817 回答