我已经开始研究一个项目,该项目需要自然语言处理并在R中使用支持向量机(SVM)构建模型(我被要求在R中执行它,尽管我知道Python在这方面更加发达)。
我找到了一篇文章here(包:NLP
,OpenNLP
,rJava
,RWeka
)。但是,本文重点介绍如何提取关键词(例如,地点,名称......)。
但是由于我想构建一个SVM模型,我想生成一个包含所有标记的Term Document Matrix。由于注释的类不适用于tm
包,因此无法使其正常工作。
示例:
testset <- c("From month 2 the AST and total bilirubine were not measured.", "16:OTHER - COMMENT REQUIRED IN COMMENT COLUMN;07/02/2004/GENOTYPING;SF- genotyping consent not offered until T4.", "M6 is 13 days out of the visit window")
word_ann <- Maxent_Word_Token_Annotator()
sent_ann <- Maxent_Sent_Token_Annotator()
test_annotations <- annotate(testset, list(sent_ann, word_ann))
test_doc <- AnnotatedPlainTextDocument(testset, test_annotations)
sents(test_doc)
[[1]]
[1] "From" "month" "2" "the" "AST" "and" "total"
[8] "bilirubine" "were" "not" "measured" "."
[[2]]
[1] "16:OTHER" "-"
[3] "COMMENT" "REQUIRED"
[5] "IN" "COMMENT"
[7] "COLUMN;07/02/2004/GENOTYPING;SF-" "genotyping"
[9] "consent" "not"
[11] "offered" "until"
[13] "T4" "."
[[3]]
[1] "M6" "is" "13" "days" "out" "of" "the" "visit" "window"
sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tm_0.6-2 openxlsx_3.0.0 magrittr_1.5 RWeka_0.4-28 openNLP_0.2-6 NLP_0.1-9
[7] rJava_0.9-8
loaded via a namespace (and not attached):
[1] openNLPdata_1.5.3-2 parallel_3.3.0 tools_3.3.0 Rcpp_0.12.5 slam_0.1-34
[6] grid_3.3.0 knitr_1.13 RWekajars_3.9.0-1
现在我不知道如何从这里生成TDM ...... 有人可以就此给我一些建议吗?