Class: Ikku::Node

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(node) ⇒ Node

Returns a new instance of Node.

Parameters:

  • node (Natto::MeCabNode)


11
12
13
# File 'lib/ikku/node.rb', line 11

def initialize(node)
  @node = node
end

Instance Method Details

#analyzable?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/ikku/node.rb', line 15

def analyzable?
  !bos? && !eos?
end

#bos?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ikku/node.rb', line 19

def bos?
  stat == STAT_ID_FOR_BOS
end

#conjugation1Object



23
24
25
# File 'lib/ikku/node.rb', line 23

def conjugation1
  feature[4]
end

#conjugation2Object



27
28
29
# File 'lib/ikku/node.rb', line 27

def conjugation2
  feature[5]
end

#element_of_ikku?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ikku/node.rb', line 35

def element_of_ikku?
  normal?
end

#eos?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ikku/node.rb', line 31

def eos?
  stat == STAT_ID_FOR_EOS
end

#featureObject



39
40
41
# File 'lib/ikku/node.rb', line 39

def feature
  @feature ||= CSV.parse(@node.feature)[0]
end

#first_of_ikku?Boolean

Returns:

  • (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

Returns:

  • (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

#inspectObject



67
68
69
# File 'lib/ikku/node.rb', line 67

def inspect
  to_s.inspect
end

#last_of_ikku?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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 == "動詞" && conjugation2 == "仮定形"
    false
  else
    true
  end
end

#last_of_phrase?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/ikku/node.rb', line 86

def last_of_phrase?
  type != "接頭詞"
end

#normal?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/ikku/node.rb', line 90

def normal?
  stat == STAT_ID_FOR_NORMAL
end

#pronunciationObject



94
95
96
# File 'lib/ikku/node.rb', line 94

def pronunciation
  feature[8]
end

#pronunciation_lengthObject



98
99
100
101
102
103
104
105
106
# File 'lib/ikku/node.rb', line 98

def pronunciation_length
  @pronunciation_length ||= begin
    if pronunciation
      pronunciation_mora.length
    else
      0
    end
  end
end

#pronunciation_moraObject



108
109
110
111
112
# File 'lib/ikku/node.rb', line 108

def pronunciation_mora
  if pronunciation
    pronunciation.tr("ぁ-ゔ","ァ-ヴ").gsub(/[^アイウエオカ-モヤユヨラ-ロワヲンヴー]/, "")
  end
end

#root_formObject



114
115
116
# File 'lib/ikku/node.rb', line 114

def root_form
  feature[6]
end

#statObject



118
119
120
# File 'lib/ikku/node.rb', line 118

def stat
  @node.stat
end

#subtype1Object



122
123
124
# File 'lib/ikku/node.rb', line 122

def subtype1
  feature[1]
end

#subtype2Object



126
127
128
# File 'lib/ikku/node.rb', line 126

def subtype2
  feature[2]
end

#subtype3Object



130
131
132
# File 'lib/ikku/node.rb', line 130

def subtype3
  feature[3]
end

#surfaceObject



134
135
136
# File 'lib/ikku/node.rb', line 134

def surface
  @node.surface
end

#to_sObject



138
139
140
# File 'lib/ikku/node.rb', line 138

def to_s
  surface
end

#typeObject



142
143
144
# File 'lib/ikku/node.rb', line 142

def type
  feature[0]
end