Class: HiwaiKaeuta::Inference::Pattern::Node
- Defined in:
- lib/hiwai_kaeuta/inference/pattern/node.rb
Constant Summary collapse
- HIWAI_WORDS =
HiwaiKaeuta::Inference::HIWAI_WORDS
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(node) ⇒ Node
constructor
A new instance of Node.
- #subst ⇒ Object
Constructor Details
#initialize(node) ⇒ Node
Returns a new instance of Node.
11 12 13 |
# File 'lib/hiwai_kaeuta/inference/pattern/node.rb', line 11 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
9 10 11 |
# File 'lib/hiwai_kaeuta/inference/pattern/node.rb', line 9 def node @node end |
Class Method Details
.get_all(nodes) ⇒ Object
5 6 7 |
# File 'lib/hiwai_kaeuta/inference/pattern/node.rb', line 5 def self.get_all(nodes) nodes.map { |x| new(x) } end |
Instance Method Details
#subst ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hiwai_kaeuta/inference/pattern/node.rb', line 15 def subst return nil unless node.is_noun? read = node.reading can = HIWAI_WORDS.reject { |wr, ww| wr.length != read.length } .group_by { |wr, ww| score = 0 wr.split('').each_with_index { |c, index| score += (c == read[index] ? 1 : 0) } score }.max_by { |k, v| k } return nil if can.nil? || can[0] == 0 HiwaiKaeuta::SubstSet.new(1).tap do |subst| subst.push(HiwaiKaeuta::Subst.new(node.index, can[1][0][1])) end end |