Module: RussianWordForms
- Defined in:
- lib/russian_word_forms.rb,
lib/russian_word_forms/rules.rb,
lib/russian_word_forms/version.rb,
lib/russian_word_forms/dictionary.rb
Defined Under Namespace
Classes: Dictionary, Rules
Constant Summary
collapse
- VERSION =
"0.0.2"
Class Method Summary
collapse
Class Method Details
.dictionary ⇒ Object
73
74
75
|
# File 'lib/russian_word_forms.rb', line 73
def self.dictionary
@dictionary
end
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/russian_word_forms.rb', line 34
def self.get_base_form(word)
word=word.mb_chars.upcase.to_s
flags=@dictionary.dictionary[word]
variants=[]
variants<<word if !flags.kind_of?(Array)
@rules.rules.keys.each do |flag|
rules=@rules.rules[flag]
rules.keys.each do |rule|
rules[rule].each do |affix|
left,right=affix.split(",")
if right
left=left[1..-1] if left[0]=='-'
right=right[1..-1] if right[0]=='-'
if word.match(/(#{right})$/)
tmp=word.gsub(/(#{right})$/,left)
variants<< tmp if tmp.match(/(#{rule})$/)
end
else
if word.match(/(#{left})$/)
tmp=word.gsub(/(#{left})$/,"")
variants<<tmp if tmp.match(/(#{rule})$/)
end
end
end
end
end
output=[]
variants.each do |variant|
if !@dictionary.dictionary[variant].kind_of?(Array)&&self.inflect(variant).any? { |w| w==word }
output<<variant
end
end
return output.uniq
end
|
.inflect(word) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/russian_word_forms.rb', line 8
def self.inflect(word)
word=word.mb_chars.upcase.to_s
flags=@dictionary.dictionary[word]
output=[]
output<<word if !flags.kind_of?(Array)
flags=@rules.rules.keys.join if flags.kind_of?(Array)&&flags.empty?
flags.each_char do |flag|
rules=@rules.rules[flag]
rules.keys.each do |rule|
rules[rule].each do |affix|
left,right=affix.split(",")
if right
left=left[1..-1] if left[0]=='-'
right=right[1..-1] if right[0]=='-'
output<<word.gsub(/(#{left})$/,right) if word.match(/(#{rule})$/)
else
output<<word+left if word.match(/(#{rule})$/)
end
end
end
end
output.uniq
end
|
.rules ⇒ Object
69
70
71
|
# File 'lib/russian_word_forms.rb', line 69
def self.rules
@rules
end
|