0
從tm對象移動到koRpus對象時出現問題。 我必須用tm工具規範一個語料庫,用koRpus推理結果並返回到tm來對結果進行分類。 爲了做到這一點,我必須將tm對象轉換爲R數據框,然後將其轉換爲excel文件,然後轉換爲txt文件,最後轉換爲koRpus對象。 這是代碼:從tm對象移動到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([email protected]$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' 我真的很感激任何幫助或反饋。
順便說一句,有沒有人知道如何問一個VCorpus內的哪個文件包含特定的令牌? 我通常會將語料庫轉換爲數據框來識別文檔。有沒有辦法做到這一點在tm?