Class: Daidai::Word
Overview
A conjugated word — the full paradigm for one dictionary-form input.
Forms are reached by name, with optional negative:/polite: modifiers:
word.past #=> Form (plain affirmative)
word.past(polite: true) #=> Form
word.non_past(negative: true) #=> Form
…or through fluent views that read like grammar (and chain):
word.polite.past
word.negative.non_past
word.polite.negative.te
‘word[:past, polite: true]` does the same dynamically, and a Word is Enumerable over all of its forms.
Instance Attribute Summary collapse
-
#forms ⇒ Object
readonly
Returns the value of attribute forms.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Instance Method Summary collapse
-
#[](name, negative: false, polite: false) ⇒ Object
(also: #form)
The primary Form for ‘name` in the given polarity/formality, or nil.
- #affirmative ⇒ Object
-
#conjugations ⇒ Object
The form names present for this word, in table order.
- #each ⇒ Object
-
#initialize(word:, pos:, kind:, forms:) ⇒ Word
constructor
A new instance of Word.
- #inspect ⇒ Object
- #negative ⇒ Object
- #plain ⇒ Object
-
#polite ⇒ Object
Fluent views — a lens with polarity/formality pre-applied.
-
#variants(name, negative: false, polite: false) ⇒ Object
Every accepted variant (all onums) for a form, primary first.
Constructor Details
#initialize(word:, pos:, kind:, forms:) ⇒ Word
Returns a new instance of Word.
68 69 70 71 72 73 74 |
# File 'lib/daidai/word.rb', line 68 def initialize(word:, pos:, kind:, forms:) @word = word @pos = pos @kind = kind @forms = forms @index = forms.group_by { |f| [ f.name, f.negative, f.polite ] } end |
Instance Attribute Details
#forms ⇒ Object (readonly)
Returns the value of attribute forms.
66 67 68 |
# File 'lib/daidai/word.rb', line 66 def forms @forms end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
66 67 68 |
# File 'lib/daidai/word.rb', line 66 def kind @kind end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
66 67 68 |
# File 'lib/daidai/word.rb', line 66 def pos @pos end |
#word ⇒ Object (readonly)
Returns the value of attribute word.
66 67 68 |
# File 'lib/daidai/word.rb', line 66 def word @word end |
Instance Method Details
#[](name, negative: false, polite: false) ⇒ Object Also known as: form
The primary Form for ‘name` in the given polarity/formality, or nil.
77 78 79 |
# File 'lib/daidai/word.rb', line 77 def [](name, negative: false, polite: false) @index[[ name, negative, polite ]]&.min_by(&:onum) end |
#affirmative ⇒ Object
99 |
# File 'lib/daidai/word.rb', line 99 def affirmative = View.new(self, negative: false, polite: false) |
#conjugations ⇒ Object
The form names present for this word, in table order.
90 91 92 93 |
# File 'lib/daidai/word.rb', line 90 def conjugations present = @forms.map(&:name).uniq FORMS.keys.select { |name| present.include?(name) } end |
#each ⇒ Object
87 |
# File 'lib/daidai/word.rb', line 87 def each(&) = @forms.each(&) |
#inspect ⇒ Object
110 |
# File 'lib/daidai/word.rb', line 110 def inspect = "#<Daidai::Word #{word} (#{pos}, #{kind}): #{@forms.size} forms>" |
#negative ⇒ Object
98 |
# File 'lib/daidai/word.rb', line 98 def negative = View.new(self, negative: true, polite: false) |
#plain ⇒ Object
97 |
# File 'lib/daidai/word.rb', line 97 def plain = View.new(self, negative: false, polite: false) |
#polite ⇒ Object
Fluent views — a lens with polarity/formality pre-applied.
96 |
# File 'lib/daidai/word.rb', line 96 def polite = View.new(self, negative: false, polite: true) |
#variants(name, negative: false, polite: false) ⇒ Object
Every accepted variant (all onums) for a form, primary first.
83 84 85 |
# File 'lib/daidai/word.rb', line 83 def variants(name, negative: false, polite: false) (@index[[ name, negative, polite ]] || []).sort_by(&:onum) end |