Class: WordNet::Lemma
- Inherits:
-
Object
- Object
- WordNet::Lemma
- Defined in:
- lib/wordnet/lemma.rb
Overview
Represents a single word in the WordNet lexicon, which can be used to look up a set of synsets.
Constant Summary collapse
- SPACE =
' '
- @@cache =
{}
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#pointer_symbols ⇒ Object
Returns the value of attribute pointer_symbols.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#synset_offsets ⇒ Object
Returns the value of attribute synset_offsets.
-
#tagsense_count ⇒ Object
Returns the value of attribute tagsense_count.
-
#word ⇒ Object
Returns the value of attribute word.
Class Method Summary collapse
-
.find(word, pos) ⇒ Object
Find a lemma for a given word and pos.
- .find_all(word) ⇒ Object
Instance Method Summary collapse
-
#initialize(lexicon_line, id) ⇒ Lemma
constructor
Create a lemma from a line in an lexicon file.
-
#synsets ⇒ Object
Return a list of synsets for this Lemma.
- #to_s ⇒ Object
Constructor Details
#initialize(lexicon_line, id) ⇒ Lemma
Create a lemma from a line in an lexicon file. You should be creating Lemmas by hand; instead, use the WordNet::Lemma.find and WordNet::Lemma.find_all methods to find the Lemma for a word.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/wordnet/lemma.rb', line 9 def initialize(lexicon_line, id) @id = id line = lexicon_line.split(" ") @word = line.shift @pos = line.shift synset_count = line.shift.to_i @pointer_symbols = line.slice!(0, line.shift.to_i) line.shift # Throw away redundant sense_cnt @tagsense_count = line.shift.to_i @synset_offsets = line.slice!(0, synset_count).map(&:to_i) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/wordnet/lemma.rb', line 5 def id @id end |
#pointer_symbols ⇒ Object
Returns the value of attribute pointer_symbols.
5 6 7 |
# File 'lib/wordnet/lemma.rb', line 5 def pointer_symbols @pointer_symbols end |
#pos ⇒ Object
Returns the value of attribute pos.
5 6 7 |
# File 'lib/wordnet/lemma.rb', line 5 def pos @pos end |
#synset_offsets ⇒ Object
Returns the value of attribute synset_offsets.
5 6 7 |
# File 'lib/wordnet/lemma.rb', line 5 def synset_offsets @synset_offsets end |
#tagsense_count ⇒ Object
Returns the value of attribute tagsense_count.
5 6 7 |
# File 'lib/wordnet/lemma.rb', line 5 def @tagsense_count end |
#word ⇒ Object
Returns the value of attribute word.
5 6 7 |
# File 'lib/wordnet/lemma.rb', line 5 def word @word end |
Class Method Details
.find(word, pos) ⇒ Object
Find a lemma for a given word and pos
41 42 43 44 45 46 |
# File 'lib/wordnet/lemma.rb', line 41 def find(word, pos) cache = @@cache[pos] ||= build_cache(pos) if found = cache[word] Lemma.new(*found) end end |
.find_all(word) ⇒ Object
34 35 36 37 38 |
# File 'lib/wordnet/lemma.rb', line 34 def find_all(word) [:noun, :verb, :adj, :adv].flat_map do |pos| find(word, pos) || [] end end |
Instance Method Details
#synsets ⇒ Object
Return a list of synsets for this Lemma. Each synset represents a different sense, or meaning, of the word.
23 24 25 |
# File 'lib/wordnet/lemma.rb', line 23 def synsets @synset_offsets.map { |offset| Synset.new(@pos, offset) } end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/wordnet/lemma.rb', line 27 def to_s [@word, @pos].join(",") end |