Class: CharDet::JapaneseContextAnalysis
- Inherits:
-
Object
- Object
- CharDet::JapaneseContextAnalysis
show all
- Defined in:
- lib/rchardet/jpcntx.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of JapaneseContextAnalysis.
123
124
125
|
# File 'lib/rchardet/jpcntx.rb', line 123
def initialize
reset()
end
|
Instance Method Details
#feed(aBuf, aLen) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/rchardet/jpcntx.rb', line 135
def feed(aBuf, aLen)
return if @done
i = @needToSkipCharNum
while i < aLen
order, charLen = get_order(aBuf[i, 2])
i += charLen
if i > aLen
@needToSkipCharNum = i - aLen
@lastCharOrder = -1
else
if (order != -1) and (@lastCharOrder != -1)
@totalRel += 1
if @totalRel > MAX_REL_THRESHOLD
@done = true
break
end
@relSample[JP2_CHAR_CONTEXT[@lastCharOrder][order]] += 1
end
@lastCharOrder = order
end
end
end
|
#get_confidence ⇒ Object
169
170
171
172
173
174
175
176
|
# File 'lib/rchardet/jpcntx.rb', line 169
def get_confidence
if @totalRel > MINIMUM_DATA_THRESHOLD
return (@totalRel - @relSample[0]) / @totalRel
else
return DONT_KNOW
end
end
|
#get_order(aStr) ⇒ Object
178
179
180
|
# File 'lib/rchardet/jpcntx.rb', line 178
def get_order(aStr)
return -1, 1
end
|
#got_enough_data ⇒ Object
165
166
167
|
# File 'lib/rchardet/jpcntx.rb', line 165
def got_enough_data
return @totalRel > ENOUGH_REL_THRESHOLD
end
|
#reset ⇒ Object
127
128
129
130
131
132
133
|
# File 'lib/rchardet/jpcntx.rb', line 127
def reset
@totalRel = 0 @relSample = [0] * NUM_OF_CATEGORY @needToSkipCharNum = 0 @lastCharOrder = -1 @done = false end
|