5

wordnet パッケージを使用して単語の反意語を取得しようとしています。これは、他の単語では実際には得られないエラーを返しながら、一部の単語では機能します。関数は基本的に、関数にカプセル化されたパッケージ ドキュメントの使用例にすぎません。

# The function:

antonyms <- function(x){
  filter <- getTermFilter("ExactMatchFilter", x, TRUE)
  terms <- getIndexTerms("ADJECTIVE", 5, filter)
  synsets <- getSynsets(terms[[1]])
  related <- getRelatedSynsets(synsets[[1]], "!")
  sapply(related, getWord)
}

# Some words work while others return an error:

> antonyms("happy")
[1] "unhappy"
> antonyms("great")
Error in .jcall(l, "Ljava/util/Iterator;", "iterator") : 
  RcallMethod: invalid object parameter

# The Error is caused by the "related" step. 

ここでの私の目標は、パッケージが提供する類義語関数のように、単語のベクトルをラップして、それらの反意語を出力として取得できる関数を用意することです。

アイデアをありがとう:)

編集: 私はオンです: OSX 10.8.5、wordnet パッケージ (R) wordnet_0.1-9 および wordnet 3.0_3 (macports を介したシステム全体)、rJava 0.9-4、R バージョン 3.0.1 (2013-05-16 )。

4

1 に答える 1