我在Rails应用程序中使用Wordnet 红宝石和WordNet wordnet-defaultdb。我想得到一个词的第一个定义。
lex = WordNet::Lexicon.new
synset = lex[:language]它返回一个Synset对象:
#<WordNet::Synset:0x7fe75205e3f8 {105650820} 'language, speech' (noun): [noun.cognition] the mental faculty or power of vocal communication>
我的目标是在冒号之后获得这个部分(没有像这样的noun.cognition:
#<WordNet::Synset:0x7fe75205e3f8 {105650820} 'language, speech' (noun): [noun.cognition] the mental faculty or power of vocal communication>
有什么正确的方法来做这个,而不是解析一个字符串?
发布于 2014-08-14 11:49:00
使用同步集的定义方法:
> lex = WordNet::Lexicon.new
=> #<WordNet::Lexicon:0x7f84d44308b8 sqlite:/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/wordnet-defaultdb-1.0.1/data/wordnet-defaultdb/wordnet30.sqlite>
> synset = lex[:language]
=> #<WordNet::Synset:0x7f84d4369768 {105650820} 'language, speech' (noun): [noun.cognition] the mental faculty or power of vocal communication>
> synset.definition
=> "the mental faculty or power of vocal communication"https://stackoverflow.com/questions/25305772
复制相似问题