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

Returns:

  • (Boolean)


88
89
90
# File 'lib/ikku/node.rb', line 88

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

#normal?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/ikku/node.rb', line 92

def normal?
  stat == STAT_ID_FOR_NORMAL
end

#pronunciationObject



96
97
98
# File 'lib/ikku/node.rb', line 96

def pronunciation
  feature[8]
end

#pronunciation_lengthObject



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_moraObject



110
111
112
113
114
# File 'lib/ikku/node.rb', line 110

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

#root_formObject



116
117
118
# File 'lib/ikku/node.rb', line 116

def root_form
  feature[6]
end

#statObject



120
121
122
# File 'lib/ikku/node.rb', line 120

def stat
  @node.stat
end

#subtype1Object



124
125
126
# File 'lib/ikku/node.rb', line 124

def subtype1
  feature[1]
end

#subtype2Object



128
129
130
# File 'lib/ikku/node.rb', line 128

def subtype2
  feature[2]
end

#subtype3Object



132
133
134
# File 'lib/ikku/node.rb', line 132

def subtype3
  feature[3]
end

#surfaceObject



136
137
138
# File 'lib/ikku/node.rb', line 136

def surface
  @node.surface
end

#to_sObject



140
141
142
# File 'lib/ikku/node.rb', line 140

def to_s
  surface
end

#typeObject



144
145
146
# File 'lib/ikku/node.rb', line 144

def type
  feature[0]
end