Class: Ikku::Node
- Inherits:
-
Object
- Object
- Ikku::Node
- Defined in:
- lib/ikku/node.rb
Constant Summary collapse
- STAT_ID_FOR_NORMAL =
0
- STAT_ID_FOR_UNKNOWN =
1
- STAT_ID_FOR_BOS =
2
- STAT_ID_FOR_EOS =
3
Instance Method Summary collapse
- #analyzable? ⇒ Boolean
- #bos? ⇒ Boolean
- #conjugation1 ⇒ Object
- #conjugation2 ⇒ Object
- #element_of_ikku? ⇒ Boolean
- #eos? ⇒ Boolean
- #feature ⇒ Object
- #first_of_ikku? ⇒ Boolean
- #first_of_phrase? ⇒ Boolean
-
#initialize(node) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #last_of_ikku? ⇒ Boolean
- #last_of_phrase? ⇒ Boolean
- #normal? ⇒ Boolean
- #pronunciation ⇒ Object
- #pronunciation_length ⇒ Object
- #pronunciation_mora ⇒ Object
- #root_form ⇒ Object
- #stat ⇒ Object
- #subtype1 ⇒ Object
- #subtype2 ⇒ Object
- #subtype3 ⇒ Object
- #surface ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(node) ⇒ Node
Returns a new instance of Node.
11 12 13 |
# File 'lib/ikku/node.rb', line 11 def initialize(node) @node = node end |
Instance Method Details
#analyzable? ⇒ Boolean
15 16 17 |
# File 'lib/ikku/node.rb', line 15 def analyzable? !bos? && !eos? end |
#conjugation1 ⇒ Object
23 24 25 |
# File 'lib/ikku/node.rb', line 23 def conjugation1 feature[4] end |
#conjugation2 ⇒ Object
27 28 29 |
# File 'lib/ikku/node.rb', line 27 def conjugation2 feature[5] end |
#element_of_ikku? ⇒ Boolean
35 36 37 |
# File 'lib/ikku/node.rb', line 35 def element_of_ikku? normal? end |
#feature ⇒ Object
39 40 41 |
# File 'lib/ikku/node.rb', line 39 def feature @feature ||= CSV.parse(@node.feature)[0] end |
#first_of_ikku? ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ikku/node.rb', line 43 def first_of_ikku? case when !first_of_phrase? false when type == "記号" && !["括弧開", "括弧閉"].include?(subtype1) false else true end end |
#first_of_phrase? ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ikku/node.rb', line 54 def first_of_phrase? case when ["助詞", "助動詞"].include?(type) false when ["非自立", "接尾"].include?(subtype1) false when subtype1 == "自立" && ["する", "できる"].include?(root_form) false else true end end |
#inspect ⇒ Object
67 68 69 |
# File 'lib/ikku/node.rb', line 67 def inspect to_s.inspect end |
#last_of_ikku? ⇒ Boolean
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ikku/node.rb', line 71 def last_of_ikku? case when ["名詞接続", "格助詞", "係助詞", "連体化", "接続助詞", "並立助詞", "副詞化", "数接続", "連体詞"].include?(type) false when conjugation2 == "連用タ接続" false when conjugation1 == "サ変・スル" && conjugation2 == "連用形" false when type == "動詞" && ["仮定形", "未然形"].include?(conjugation2) false when type == "名詞" && subtype1 == "非自立" && pronunciation == "ン" false else true end end |
#last_of_phrase? ⇒ Boolean
88 89 90 |
# File 'lib/ikku/node.rb', line 88 def last_of_phrase? type != "接頭詞" end |
#normal? ⇒ Boolean
92 93 94 |
# File 'lib/ikku/node.rb', line 92 def normal? stat == STAT_ID_FOR_NORMAL end |
#pronunciation ⇒ Object
96 97 98 |
# File 'lib/ikku/node.rb', line 96 def pronunciation feature[8] end |
#pronunciation_length ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/ikku/node.rb', line 100 def pronunciation_length @pronunciation_length ||= begin if pronunciation pronunciation_mora.length else 0 end end end |
#pronunciation_mora ⇒ Object
110 111 112 113 114 |
# File 'lib/ikku/node.rb', line 110 def pronunciation_mora if pronunciation pronunciation.tr("ぁ-ゔ","ァ-ヴ").gsub(/[^アイウエオカ-モヤユヨラ-ロワヲンヴー]/, "") end end |
#root_form ⇒ Object
116 117 118 |
# File 'lib/ikku/node.rb', line 116 def root_form feature[6] end |
#stat ⇒ Object
120 121 122 |
# File 'lib/ikku/node.rb', line 120 def stat @node.stat end |
#subtype1 ⇒ Object
124 125 126 |
# File 'lib/ikku/node.rb', line 124 def subtype1 feature[1] end |
#subtype2 ⇒ Object
128 129 130 |
# File 'lib/ikku/node.rb', line 128 def subtype2 feature[2] end |
#subtype3 ⇒ Object
132 133 134 |
# File 'lib/ikku/node.rb', line 132 def subtype3 feature[3] end |
#surface ⇒ Object
136 137 138 |
# File 'lib/ikku/node.rb', line 136 def surface @node.surface end |
#to_s ⇒ Object
140 141 142 |
# File 'lib/ikku/node.rb', line 140 def to_s surface end |
#type ⇒ Object
144 145 146 |
# File 'lib/ikku/node.rb', line 144 def type feature[0] end |