kanjika 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +1 -0
- data/Rakefile +10 -0
- data/lib/kanjika/conjugator/base.rb +37 -0
- data/lib/kanjika/conjugator/masu.rb +98 -0
- data/lib/kanjika/version.rb +5 -0
- data/lib/kanjika.rb +8 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5933c4951beaa76d390caee5d14c5cdc30189a0a20d3e23b95cc24cdcd3dafbb
|
4
|
+
data.tar.gz: 8c78647b1deea01d0859a7a7d8b859209541500f3396db76287ee6df33d4f653
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ecba5c868fbdcb7ae9d8df62b72612e508e8b2bef44a6082636d1db64aa8781573582f62c35515407ef7e3255574aa9a2deb1664976f5f7399cdfd0f8277c46
|
7
|
+
data.tar.gz: b574b11985a78e125a3b811f8fa1d73663c416f49a2402bdbc9bfd90c0a3c32b3efcff49ab19fed316ab4ec19e66723fd9dba8957f5309a0e17036230c772d0c
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# kanjika_gem
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Kanjika
|
2
|
+
module Conjugator
|
3
|
+
class Base
|
4
|
+
U_ENDINGS = "うくぐすずつづぬふぶむゆる"
|
5
|
+
E_ENDINGS = "えけげせぜてでねへべめれ"
|
6
|
+
I_ENDINGS = "いきぎしじちぢにひびみり"
|
7
|
+
# Ichidan verbs (る-verbs)
|
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
|
+
}
|
17
|
+
GODAN = "五段"
|
18
|
+
ICHIDAN = "一段"
|
19
|
+
SURU = "カ変"
|
20
|
+
KURU = "サ変"
|
21
|
+
|
22
|
+
def self.conjugate(verb)
|
23
|
+
new(verb).conjugate
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :verb
|
27
|
+
|
28
|
+
def initialize(verb)
|
29
|
+
@verb = verb
|
30
|
+
end
|
31
|
+
|
32
|
+
def conjugate
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Kanjika
|
4
|
+
module Conjugator
|
5
|
+
class Masu < Base
|
6
|
+
GODAN_ENDINGS = {
|
7
|
+
"う" => "い", # e.g., 会う → 会います
|
8
|
+
"く" => "き", # e.g., 書く → 書きます
|
9
|
+
"ぐ" => "ぎ", # e.g., 泳ぐ → 泳ぎます
|
10
|
+
"す" => "し", # e.g., 話す → 話します
|
11
|
+
"つ" => "ち", # e.g., 持つ → 持ちます
|
12
|
+
"ぬ" => "に", # e.g., 死ぬ → 死にます
|
13
|
+
"ぶ" => "び", # e.g., 飛ぶ → 飛びます
|
14
|
+
"む" => "み", # e.g., 読む → 読みます
|
15
|
+
"る" => "り" # e.g., 切る → 切ります
|
16
|
+
}
|
17
|
+
|
18
|
+
CONJUGATION_RULES = {
|
19
|
+
ichidan: ->(stem) { stem + "ます" },
|
20
|
+
godan: ->(stem, last_char) { stem + GODAN_ENDINGS[last_char] + "ます" },
|
21
|
+
irregular: ->(verb) { IRREGULAR_MASU_FORMS[verb] }
|
22
|
+
}
|
23
|
+
|
24
|
+
def conjugate
|
25
|
+
Ve.in(:ja).words(verb).flat_map do |word|
|
26
|
+
word.tokens.map { |token| conjugate_token(word, token) }.join
|
27
|
+
end.join
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def conjugate_token(word, token)
|
33
|
+
if word.part_of_speech.name == "verb"
|
34
|
+
conjugate_verb(token)
|
35
|
+
else
|
36
|
+
conjugate_others(token)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def conjugate_verb(token)
|
41
|
+
verb_type = determine_verb_type(token)
|
42
|
+
apply_conjugation_rule(verb_type)
|
43
|
+
end
|
44
|
+
|
45
|
+
def determine_verb_type(token)
|
46
|
+
return :ichidan if ichidan?(token)
|
47
|
+
return :godan if godan?(token)
|
48
|
+
:irregular if irregular?(token)
|
49
|
+
end
|
50
|
+
|
51
|
+
def apply_conjugation_rule(verb_type)
|
52
|
+
rule = CONJUGATION_RULES[verb_type]
|
53
|
+
case verb_type
|
54
|
+
when :ichidan
|
55
|
+
rule.call(stem)
|
56
|
+
when :godan
|
57
|
+
rule.call(stem, verb[-1])
|
58
|
+
when :irregular
|
59
|
+
rule.call(verb)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def conjugate_others(token)
|
64
|
+
return verb + "します" if verb.kanji?
|
65
|
+
|
66
|
+
if ending_in_e_or_i?
|
67
|
+
CONJUGATION_RULES[:ichidan].call(stem)
|
68
|
+
elsif godan_ending?
|
69
|
+
CONJUGATION_RULES[:godan].call(stem, verb[-1])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def ichidan?(token)
|
74
|
+
token[:inflection_type].match?(ICHIDAN)
|
75
|
+
end
|
76
|
+
|
77
|
+
def godan?(token)
|
78
|
+
token[:inflection_type].match?(GODAN)
|
79
|
+
end
|
80
|
+
|
81
|
+
def irregular?(token)
|
82
|
+
token[:inflection_type].match?(SURU) || token[:inflection_type].match?(KURU)
|
83
|
+
end
|
84
|
+
|
85
|
+
def ending_in_e_or_i?
|
86
|
+
E_ENDINGS.include?(verb[-2]) || I_ENDINGS.include?(verb[-2])
|
87
|
+
end
|
88
|
+
|
89
|
+
def godan_ending?
|
90
|
+
GODAN_ENDINGS.key?(verb[-1])
|
91
|
+
end
|
92
|
+
|
93
|
+
def stem
|
94
|
+
verb.chop
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/kanjika.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kanjika
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fagner Pereira Rosa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ve
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mojinizer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.2
|
41
|
+
description: japanese language tools
|
42
|
+
email:
|
43
|
+
- fagnerfpr@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/kanjika.rb
|
51
|
+
- lib/kanjika/conjugator/base.rb
|
52
|
+
- lib/kanjika/conjugator/masu.rb
|
53
|
+
- lib/kanjika/version.rb
|
54
|
+
homepage: https://github.com/fagnerpereira/kanjika_gem
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata:
|
58
|
+
homepage_uri: https://github.com/fagnerpereira/kanjika_gem
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 3.0.0
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.5.11
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Usefull tools to work with japanese language
|
78
|
+
test_files: []
|