Search code examples
ruby-on-railsrubywordnet

Is there a way to get definition using WordNet?


I'm using Wordnet Ruby gem with WordNet wordnet-defaultdb in a Rails application. I want to get the first definition of a word.

lex = WordNet::Lexicon.new
synset = lex[:language]

It returns a Synset object:

#<WordNet::Synset:0x7fe75205e3f8 {105650820} 'language, speech' (noun): [noun.cognition] the mental faculty or power of vocal communication>

My goal is to get the part after colon (without [noun.cognition] like this:

#<WordNet::Synset:0x7fe75205e3f8 {105650820} 'language, speech' (noun): [noun.cognition] the mental faculty or power of vocal communication>

Is there any proper way of doing that rather than parsing a string?


Solution

  • Use the definition method on synset:

    > 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"