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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5933c4951beaa76d390caee5d14c5cdc30189a0a20d3e23b95cc24cdcd3dafbb
4
- data.tar.gz: 8c78647b1deea01d0859a7a7d8b859209541500f3396db76287ee6df33d4f653
3
+ metadata.gz: fa679e44c9d5ed7de37e317757b5fb18cef5eec4ba9968cb85c8f095884053ab
4
+ data.tar.gz: 5c53eb52988ccb2cf743b98a782aef36a33e119f502dfef62a7368c8ec13e981
5
5
  SHA512:
6
- metadata.gz: 6ecba5c868fbdcb7ae9d8df62b72612e508e8b2bef44a6082636d1db64aa8781573582f62c35515407ef7e3255574aa9a2deb1664976f5f7399cdfd0f8277c46
7
- data.tar.gz: b574b11985a78e125a3b811f8fa1d73663c416f49a2402bdbc9bfd90c0a3c32b3efcff49ab19fed316ab4ec19e66723fd9dba8957f5309a0e17036230c772d0c
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
- # 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
- }
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
- "う" => "い", # 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., 切る → 切ります
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) { IRREGULAR_MASU_FORMS[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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanjika
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/kanjika.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require_relative "kanjika/version"
2
+ require_relative "kanjika/conjugator/base"
2
3
  require_relative "kanjika/conjugator/masu"
4
+ require_relative "kanjika/conjugator/te"
3
5
  require "ve"
4
6
  require "mojinizer"
5
7
 
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.0
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: