Class: HiwaiKaeuta::Inference::Pattern::No
- Defined in:
- lib/hiwai_kaeuta/inference/pattern/no.rb
Constant Summary collapse
- PAIRS =
[[[/.*/, 'マンコ'], /^ナカ$/], [[/.*/, 'マンコ'], /^ニオイ$/]]
Instance Attribute Summary collapse
-
#no_node ⇒ Object
readonly
Returns the value of attribute no_node.
-
#post_node ⇒ Object
readonly
Returns the value of attribute post_node.
-
#pre_node ⇒ Object
readonly
Returns the value of attribute pre_node.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(no_node, pre_node, post_node) ⇒ No
constructor
A new instance of No.
- #subst ⇒ Object
Constructor Details
#initialize(no_node, pre_node, post_node) ⇒ No
Returns a new instance of No.
16 17 18 19 20 |
# File 'lib/hiwai_kaeuta/inference/pattern/no.rb', line 16 def initialize(no_node, pre_node, post_node) @no_node = no_node @pre_node = pre_node @post_node = post_node end |
Instance Attribute Details
#no_node ⇒ Object (readonly)
Returns the value of attribute no_node.
14 15 16 |
# File 'lib/hiwai_kaeuta/inference/pattern/no.rb', line 14 def no_node @no_node end |
#post_node ⇒ Object (readonly)
Returns the value of attribute post_node.
14 15 16 |
# File 'lib/hiwai_kaeuta/inference/pattern/no.rb', line 14 def post_node @post_node end |
#pre_node ⇒ Object (readonly)
Returns the value of attribute pre_node.
14 15 16 |
# File 'lib/hiwai_kaeuta/inference/pattern/no.rb', line 14 def pre_node @pre_node end |
Class Method Details
.get_all(nodes) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/hiwai_kaeuta/inference/pattern/no.rb', line 6 def self.get_all(nodes) nodes.select { |node| node.reading == 'ノ' && node.index > 0 && node.index < nodes.length - 1 }.map { |node| new(node, nodes[node.index - 1], nodes[node.index + 1]) } end |
Instance Method Details
#subst ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hiwai_kaeuta/inference/pattern/no.rb', line 22 def subst return nil unless pre_node.is_noun? && post_node.is_noun? can = PAIRS.map { |pre, post| [match(pre, pre_node), match(post, post_node)] }.reject { |pre, post| pre.nil? || post.nil? }.first return nil if can.nil? HiwaiKaeuta::SubstSet.new(2).tap do |subst| subst.push(HiwaiKaeuta::Subst.new(pre_node.index, can[0])) subst.push(HiwaiKaeuta::Subst.new(post_node.index, can[1])) end end |