2013-08-22 66 views
3

我使用了幾包(webmining,情緒,openNLP)提取有關股票JPM一些句子,但在下面的錯誤運行:[R openNLP找不到功能sentDetect()

Error in eval(expr, envir, enclos) : could not find function "sentDetect"

這裏我使用的代碼以及我確保所有軟件包都已安裝。我檢查了「語料庫」變量,它是「一個包含20個文本文檔的語料庫」。我還使用了「library(help = openNLP)」來列出軟件包「openNLP」中的所有函數,但未在列表中找到「sentDetect」。

library(XML) 
library(tm) 
library(tm.plugin.webmining) 
library(tm.plugin.sentiment) 
library(NLP) 
library(openNLP) 

stock <-"JPM" 
corpus <- WebCorpus(GoogleFinanceSource(stock)) 

sentences <- sentDetect(corpus) 

以下是運行環境。它可能與R 3.0.1版本(對於openNLP來說太新了)或64位Windows系統有關係嗎?

R version 3.0.1 (2013-05-16) -- "Good Sport" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit)

非常感謝。

Weihong

+0

HTTP://www.inside- r.org/packages/cran/openNLP/docs/sentDetect –

回答

3

sentDetect函數已被替換。爲標記化的句子的新方法見?Maxent_Sent_Token_Annotator

require("NLP") 
require("openNLP") 
## Some text. 
s <- paste(c("Pierre Vinken, 61 years old, will join the board as a ", 
      "nonexecutive director Nov. 29.\n", 
      "Mr. Vinken is chairman of Elsevier N.V., ", 
      "the Dutch publishing group."), 
      collapse = "") 
s <- as.String(s) 

sent_token_annotator <- Maxent_Sent_Token_Annotator() 
sent_token_annotator 
a1 <- annotate(s, sent_token_annotator) 
a1 
## Extract sentences. 
s[a1] 
4

嘗試使用 'qdap' 包

library("qdap") 

然後使用功能 'sent_detect'

sent_detect(xyz) 
+1

這對我來說很有用,與使用Maxent_Sent_Token_Annotator的答案不同 –