Class: Treat::Workers::Lexicalizers::Sensers::Wordnet::Synset

Inherits:
Object
  • Object
show all
Defined in:
lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb

Overview

An adaptor for synsets used by the Wordnet gem.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#definitionObject

The definition of the synset.



7
8
9
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 7

def definition
  @definition
end

#examplesObject

The examples in the synset.



9
10
11
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 9

def examples
  @examples
end

#posObject

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

#antonymsObject

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

#glossObject

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

#hypernymsObject

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

#hyponymsObject

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

#synonymsObject



34
35
36
# File 'lib/treat/workers/lexicalizers/sensers/wordnet/synset.rb', line 34

def synonyms
  @original_synset.words
end

#wordsObject

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