Class: Treat::Workers::Lexicalizers::Sensers::Wordnet::Synset
- Inherits:
-
Object
- Object
- Treat::Workers::Lexicalizers::Sensers::Wordnet::Synset
- Defined in:
- lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb
Overview
An adaptor for synsets used by the Wordnet gem.
Instance Attribute Summary collapse
-
#definition ⇒ Object
The definition of the synset.
-
#examples ⇒ Object
The examples in the synset.
-
#pos ⇒ Object
The POS tag of the word.
Instance Method Summary collapse
-
#antonyms ⇒ Object
The antonym sets of the synset.
-
#gloss ⇒ Object
A gloss (short definition with examples) for the synset.
-
#hypernyms ⇒ Object
The hypernym sets of the synset.
-
#hyponyms ⇒ Object
The hyponym sets of the synset.
-
#initialize(synset) ⇒ Synset
constructor
A new instance of Synset.
-
#method_missing(sym, *args, &block) ⇒ Object
Respond to the missing method event.
- #parse_synset(res) ⇒ Object
- #synonyms ⇒ Object
-
#words ⇒ Object
The words in the synset.
Constructor Details
#initialize(synset) ⇒ Synset
Returns a new instance of Synset.
11 12 13 14 15 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 11 def initialize(synset) @original_synset = synset @pos, @definition, @examples = parse_synset(synset.to_s.split(')')) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Respond to the missing method event.
62 63 64 65 66 67 68 69 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 62 def method_missing(sym, *args, &block) ret = @original_synset.send(sym) if ret.is_a?(Treat::Workers::Lexicalizers::Sensers::Wordnet::Synset) self.new(ret) else ret end end |
Instance Attribute Details
#definition ⇒ Object
The definition of the synset.
7 8 9 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 7 def definition @definition end |
#examples ⇒ Object
The examples in the synset.
9 10 11 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 9 def examples @examples end |
#pos ⇒ Object
The POS tag of the word.
5 6 7 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 5 def pos @pos end |
Instance Method Details
#antonyms ⇒ Object
The antonym sets of the synset.
45 46 47 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 45 def antonyms antonym.collect { |a| a.words } end |
#gloss ⇒ Object
A gloss (short definition with examples) for the synset.
40 41 42 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 40 def gloss @original_synset.gloss end |
#hypernyms ⇒ Object
The hypernym sets of the synset.
50 51 52 53 54 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 50 def hypernyms h = hypernym return [] unless h h.words end |
#hyponyms ⇒ Object
The hyponym sets of the synset.
57 58 59 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 57 def hyponyms hyponym.collect { |h| h.words } end |
#parse_synset(res) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 17 def parse_synset(res) pos = res[0][1..-1].strip res2 = res[1].split('(') res3 = res2[1].split(';') 1.upto(res3.size-1) do |i| res3[i] = res3[i].strip[1..-2] end definition = res3[0] examples = res3[1..-1] return pos, definition, examples end |
#synonyms ⇒ Object
34 35 36 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 34 def synonyms @original_synset.words end |
#words ⇒ Object
The words in the synset.
30 31 32 |
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 30 def words @original_synset.words end |