【问题标题】:Moving from tm object to koRpus object and vice versa从 tm 对象移动到 koRpus 对象,反之亦然
【发布时间】:2017-02-16 10:07:19
【问题描述】:

我从 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 中做到这一点?

【问题讨论】:

    标签: r text-mining tm korpus


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-12-09
      • 1970-01-01
      • 2011-06-24
      • 2023-03-29
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 2015-03-05
      相关资源
      最近更新 更多