在R中从文本中提取关键词

3

我希望从R中的文本中提取与保险服务相关的关键词。我创建了关键词列表,并使用了qdap库中的常见函数。

   bag <- bag_o_words(corpus) 
   b <- common(bag,keywords,overlap="all")

但是结果只是出现频率大于1的常见词语。 我还使用了RKEA库。

keywords <- c("directasia", "directasia.com", "Frank", "frank", "OCBC", "NTUC",
              "NTUC Income", "Frank by OCBC", "customer service", "atm",
              "insurance", "claim", "agent", "premium", "policy", "customer care",
              "customer", "draft", "account", "credit", "savings","debit","ivr",
              "offer", "transacation", "banking", "website", "mobile", "i-safe",
               "customer", "demat", "network", "phone", "interest", "loan",
               "transfer", "deposit",  "otp", "rewards", "redemption")
   tmpdir <- tempfile()
   dir.create(tmpdir)
   model <- file.path(tmpdir, "crudeModel")
   createModel(corpus,keywords,model)
   extractKeywords(corpus, model)

然而,我遇到了以下错误:

createModel(corpus, keywords, model) 中的错误:文档数量和关键字不匹配

并且

.jcall(ke, "V", "extractKeyphrases", .jcall(ke,Ljava/util/Hashtable;", 中的错误:java.io.FileNotFoundException: C:\Users\Bitanshu\AppData\Local\Temp\RtmpEHu9uA\file14c4160f41c2\crudeModel(系统找不到指定的文件)

我认为第二个错误是因为“createModel”没有成功。
有人能提出如何纠正这个问题或另一种方法吗? 文本数据已从Twitter中提取。
2个回答

2
你可以尝试使用quanteda软件包。我建议使用GitHub版本而不是CRAN版本,因为就在两天前我改进了kwic()函数。例如:
> require(quanteda)
> kwic(inaugTexts, "asia")
                                           contextPre keyword                       contextPost
 [1841-Harrison, 8599]        or Egypt and the lesser    Asia would furnish the larger dividend
     [1909-Taft, 1872]     our shores from Europe and    Asia of course reduces the necessity  
 [1925-Coolidge, 2215] differences in both Europe and    Asia . But there is a                 
[1953-Eisenhower, 325]           the earth. Masses of    Asia have awakened to strike off      
    [2013-Obama, 1514] We will support democracy from    Asia to Africa, from the   

你使用的是哪个版本的R?因为我遇到了这个错误:在安装包时出现警告: “quantedata”包不可用(适用于R版本3.2.0)。 - Bitanshu Das
3.2.2是最新的R版本,也是CRAN版本的quanteda所构建的版本。但正如我的回答中所述,为了充分利用kwic()函数,我建议使用以下命令从源代码安装最新的GitHub版本的quanteda:devtools::install_github("kbenoit/quanteda")。请参见https://github.com/kbenoit/quanteda。 - Ken Benoit

0

即使您不打算使用所有部分,也需要在createModel中使用以下格式,并提及它们:

createModel(corpus,keywords, model, voc = "none", vocformat = "")


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接