kanjika 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kanjika/conjugator/base.rb +2 -10
- data/lib/kanjika/conjugator/masu.rb +18 -12
- data/lib/kanjika/conjugator/te.rb +102 -0
- data/lib/kanjika/version.rb +1 -1
- data/lib/kanjika.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa679e44c9d5ed7de37e317757b5fb18cef5eec4ba9968cb85c8f095884053ab
|
4
|
+
data.tar.gz: 5c53eb52988ccb2cf743b98a782aef36a33e119f502dfef62a7368c8ec13e981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a1830c2d68b46bc06b00f0abfd3e3f9808beb5a2add244b27b90ca8f32bc0cd986c927b7c53334a1ab1924b90fb8a60bc08f2d1a6cf513846ab485ba5992b99
|
7
|
+
data.tar.gz: 1e8427968b78a45bd37e45f47cbfc1b72a87a04a61adaf7021eb5bd89295a6995d03befe9a4fdb892bb2a7e07c7bb04c269c2bb886079aba70d583c0a9d86610
|
@@ -4,20 +4,12 @@ module Kanjika
|
|
4
4
|
U_ENDINGS = "うくぐすずつづぬふぶむゆる"
|
5
5
|
E_ENDINGS = "えけげせぜてでねへべめれ"
|
6
6
|
I_ENDINGS = "いきぎしじちぢにひびみり"
|
7
|
-
|
8
|
-
ICHIDAN_MASU_FORMS = {
|
9
|
-
"る" => "ます" # e.g., 食べる → 食べます, 見る → 見ます
|
10
|
-
}
|
11
|
-
# Irregular verbs
|
12
|
-
IRREGULAR_MASU_FORMS = {
|
13
|
-
"来る" => "来ます", # e.g., 来る → 来ます (to come)
|
14
|
-
"くる" => "きます", # e.g., くる → きます (to come)
|
15
|
-
"する" => "します" # e.g., する → します (to do)
|
16
|
-
}
|
7
|
+
|
17
8
|
GODAN = "五段"
|
18
9
|
ICHIDAN = "一段"
|
19
10
|
SURU = "カ変"
|
20
11
|
KURU = "サ変"
|
12
|
+
NOUN_VERB = "サ変接続"
|
21
13
|
|
22
14
|
def self.conjugate(verb)
|
23
15
|
new(verb).conjugate
|
@@ -1,24 +1,30 @@
|
|
1
|
-
require_relative "base"
|
2
|
-
|
3
1
|
module Kanjika
|
4
2
|
module Conjugator
|
5
3
|
class Masu < Base
|
6
4
|
GODAN_ENDINGS = {
|
7
|
-
"う" => "い",
|
8
|
-
"く" => "き",
|
9
|
-
"ぐ" => "ぎ",
|
10
|
-
"す" => "し",
|
11
|
-
"つ" => "ち",
|
12
|
-
"ぬ" => "に",
|
13
|
-
"ぶ" => "び",
|
14
|
-
"む" => "み",
|
15
|
-
"る" => "り"
|
5
|
+
"う" => "い",
|
6
|
+
"く" => "き",
|
7
|
+
"ぐ" => "ぎ",
|
8
|
+
"す" => "し",
|
9
|
+
"つ" => "ち",
|
10
|
+
"ぬ" => "に",
|
11
|
+
"ぶ" => "び",
|
12
|
+
"む" => "み",
|
13
|
+
"る" => "り"
|
14
|
+
}
|
15
|
+
ICHIDAN_MASU_FORMS = {
|
16
|
+
"る" => "ます"
|
17
|
+
}
|
18
|
+
IRREGULARS = {
|
19
|
+
"来る" => "来ます",
|
20
|
+
"くる" => "きます",
|
21
|
+
"する" => "します"
|
16
22
|
}
|
17
23
|
|
18
24
|
CONJUGATION_RULES = {
|
19
25
|
ichidan: ->(stem) { stem + "ます" },
|
20
26
|
godan: ->(stem, last_char) { stem + GODAN_ENDINGS[last_char] + "ます" },
|
21
|
-
irregular: ->(verb) {
|
27
|
+
irregular: ->(verb) { IRREGULARS[verb] }
|
22
28
|
}
|
23
29
|
|
24
30
|
def conjugate
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require "pry"
|
2
|
+
module Kanjika
|
3
|
+
module Conjugator
|
4
|
+
class Te < Base
|
5
|
+
GODAN_ENDINGS = {
|
6
|
+
"う" => "って",
|
7
|
+
"く" => "いて",
|
8
|
+
"ぐ" => "いで",
|
9
|
+
"す" => "して",
|
10
|
+
"つ" => "って",
|
11
|
+
"ぬ" => "んで",
|
12
|
+
"ぶ" => "んで",
|
13
|
+
"む" => "んで",
|
14
|
+
"る" => "って"
|
15
|
+
}
|
16
|
+
ICHIDAN_ENDINGS = {
|
17
|
+
"る" => "て"
|
18
|
+
}
|
19
|
+
IRREGULARS = {
|
20
|
+
"来る" => "来て",
|
21
|
+
"くる" => "きて",
|
22
|
+
"する" => "して"
|
23
|
+
}
|
24
|
+
CONJUGATION_RULES = {
|
25
|
+
ichidan: ->(stem, last_char) { stem + ICHIDAN_ENDINGS[last_char] },
|
26
|
+
godan: ->(stem, last_char) { stem + GODAN_ENDINGS[last_char] },
|
27
|
+
irregular: ->(verb) { IRREGULARS[verb] }
|
28
|
+
}
|
29
|
+
|
30
|
+
def conjugate
|
31
|
+
Ve.in(:ja).words(verb).flat_map do |word|
|
32
|
+
word.tokens.map { |token| conjugate_token(word, token) }.join
|
33
|
+
end.join
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def conjugate_token(word, token)
|
39
|
+
if word.part_of_speech.name == "verb"
|
40
|
+
conjugate_verb(token)
|
41
|
+
else
|
42
|
+
conjugate_others(token)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def conjugate_verb(token)
|
47
|
+
verb_type = determine_verb_type(token)
|
48
|
+
apply_conjugation_rule(verb_type)
|
49
|
+
end
|
50
|
+
|
51
|
+
def determine_verb_type(token)
|
52
|
+
return :ichidan if ichidan?(token)
|
53
|
+
return :godan if godan?(token)
|
54
|
+
:irregular if irregular?(token)
|
55
|
+
end
|
56
|
+
|
57
|
+
def apply_conjugation_rule(verb_type)
|
58
|
+
rule = CONJUGATION_RULES[verb_type]
|
59
|
+
case verb_type
|
60
|
+
when :ichidan
|
61
|
+
rule.call(stem, verb[-1])
|
62
|
+
when :godan
|
63
|
+
rule.call(stem, verb[-1])
|
64
|
+
when :irregular
|
65
|
+
rule.call(verb)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def conjugate_others(token)
|
70
|
+
if token[:raw].include?(NOUN_VERB)
|
71
|
+
verb + IRREGULARS["する"]
|
72
|
+
else
|
73
|
+
"invalid verb"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def ichidan?(token)
|
78
|
+
token[:inflection_type].match?(ICHIDAN)
|
79
|
+
end
|
80
|
+
|
81
|
+
def godan?(token)
|
82
|
+
token[:inflection_type].match?(GODAN)
|
83
|
+
end
|
84
|
+
|
85
|
+
def irregular?(token)
|
86
|
+
token[:inflection_type].match?(SURU) || token[:inflection_type].match?(KURU)
|
87
|
+
end
|
88
|
+
|
89
|
+
def ending_in_e_or_i?
|
90
|
+
E_ENDINGS.include?(verb[-2]) || I_ENDINGS.include?(verb[-2])
|
91
|
+
end
|
92
|
+
|
93
|
+
def godan_ending?
|
94
|
+
GODAN_ENDINGS.key?(verb[-1])
|
95
|
+
end
|
96
|
+
|
97
|
+
def stem
|
98
|
+
verb.chop
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/kanjika/version.rb
CHANGED
data/lib/kanjika.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanjika
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fagner Pereira Rosa
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/kanjika.rb
|
51
51
|
- lib/kanjika/conjugator/base.rb
|
52
52
|
- lib/kanjika/conjugator/masu.rb
|
53
|
+
- lib/kanjika/conjugator/te.rb
|
53
54
|
- lib/kanjika/version.rb
|
54
55
|
homepage: https://github.com/fagnerpereira/kanjika_gem
|
55
56
|
licenses:
|