arabic_conjugator 0.0.1

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.
Files changed (64) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +27 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +8 -0
  6. data/Rakefile +1 -0
  7. data/arabic_conjugator.gemspec +20 -0
  8. data/lib/arabic_conjugator.rb +43 -0
  9. data/lib/arabic_conjugator/base.rb +70 -0
  10. data/lib/arabic_conjugator/factories/base_factory.rb +74 -0
  11. data/lib/arabic_conjugator/factories/tense_factory.rb +20 -0
  12. data/lib/arabic_conjugator/factories/type_factory.rb +59 -0
  13. data/lib/arabic_conjugator/form.rb +10 -0
  14. data/lib/arabic_conjugator/form_II_hollow_defective.rb +6 -0
  15. data/lib/arabic_conjugator/form_I_defective.rb +5 -0
  16. data/lib/arabic_conjugator/form_I_defective_past.rb +12 -0
  17. data/lib/arabic_conjugator/form_I_defective_present.rb +9 -0
  18. data/lib/arabic_conjugator/form_I_hamzated_past.rb +16 -0
  19. data/lib/arabic_conjugator/form_I_hamzated_present.rb +16 -0
  20. data/lib/arabic_conjugator/form_I_hollow_past.rb +5 -0
  21. data/lib/arabic_conjugator/form_I_hollow_present.rb +6 -0
  22. data/lib/arabic_conjugator/form_VIII_hamzated.rb +5 -0
  23. data/lib/arabic_conjugator/form_VIII_hollow.rb +5 -0
  24. data/lib/arabic_conjugator/past_bases/form_III_past_base.rb +42 -0
  25. data/lib/arabic_conjugator/past_bases/form_II_past_base.rb +36 -0
  26. data/lib/arabic_conjugator/past_bases/form_IV_past_base.rb +46 -0
  27. data/lib/arabic_conjugator/past_bases/form_I_past_base.rb +57 -0
  28. data/lib/arabic_conjugator/past_bases/form_VIII_past_base.rb +78 -0
  29. data/lib/arabic_conjugator/past_bases/form_VII_past_base.rb +26 -0
  30. data/lib/arabic_conjugator/past_bases/form_VI_past_base.rb +32 -0
  31. data/lib/arabic_conjugator/past_bases/form_V_past_base.rb +35 -0
  32. data/lib/arabic_conjugator/past_bases/form_X_past_base.rb +40 -0
  33. data/lib/arabic_conjugator/past_tense.rb +12 -0
  34. data/lib/arabic_conjugator/present_bases/form_III_present_base.rb +30 -0
  35. data/lib/arabic_conjugator/present_bases/form_II_present_base.rb +34 -0
  36. data/lib/arabic_conjugator/present_bases/form_IV_present_base.rb +48 -0
  37. data/lib/arabic_conjugator/present_bases/form_I_present_base.rb +54 -0
  38. data/lib/arabic_conjugator/present_bases/form_VIII_present_base.rb +67 -0
  39. data/lib/arabic_conjugator/present_bases/form_VII_present_base.rb +31 -0
  40. data/lib/arabic_conjugator/present_bases/form_VI_present_base.rb +47 -0
  41. data/lib/arabic_conjugator/present_bases/form_V_present_base.rb +30 -0
  42. data/lib/arabic_conjugator/present_bases/form_X_present_base.rb +30 -0
  43. data/lib/arabic_conjugator/present_tense.rb +12 -0
  44. data/lib/arabic_conjugator/version.rb +3 -0
  45. data/spec/past_tense/formIII_past_spec.rb +75 -0
  46. data/spec/past_tense/formII_past_spec.rb +108 -0
  47. data/spec/past_tense/formIV_past_spec.rb +122 -0
  48. data/spec/past_tense/formI_past_spec.rb +160 -0
  49. data/spec/past_tense/formVIII_past_spec.rb +135 -0
  50. data/spec/past_tense/formVII_past_spec.rb +60 -0
  51. data/spec/past_tense/formVI_past_spec.rb +70 -0
  52. data/spec/past_tense/formV_past_spec.rb +77 -0
  53. data/spec/past_tense/formX_past_spec.rb +78 -0
  54. data/spec/present_tense/formIII_present_spec.rb +80 -0
  55. data/spec/present_tense/formII_present_spec.rb +102 -0
  56. data/spec/present_tense/formIV_present_spec.rb +107 -0
  57. data/spec/present_tense/formI_present_spec.rb +143 -0
  58. data/spec/present_tense/formVIII_present_spec.rb +126 -0
  59. data/spec/present_tense/formVII_present_spec.rb +50 -0
  60. data/spec/present_tense/formVI_present_spec.rb +75 -0
  61. data/spec/present_tense/formV_present_spec.rb +87 -0
  62. data/spec/present_tense/formX_present_spec.rb +68 -0
  63. data/spec/spec_helper.rb +5 -0
  64. metadata +166 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjAxMDZiNDU0NmE0YjBmN2U0N2NkYTEzM2QwZDYxNTkyMTE5OWMwNw==
5
+ data.tar.gz: !binary |-
6
+ OTgxZThhMjMwYjZkYTljNzgxNWI0MmNkZWQ0YzRmMjFlMWFlMzlhNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NzJiN2JiYjFmMWNlOTRlNDBlMzc2NzQzNzdlYWU5OTdjNTFhY2ZhNzcxNzNj
10
+ ZjA5MmEwMDJiZmY0MGJjOTVkZjVlN2FmYjFjZmVlZmEwNDAxNTc4NjFhMTI5
11
+ OTU5ZGNkODA3NmY0Yjk1ODk0NjRkODYwMmE5MGFlY2I5N2I3NDU=
12
+ data.tar.gz: !binary |-
13
+ ZTdiMzBjMTgyNGY0MWEwOTFlYjZkMmE2Njc1NWQxZjJmOTQzZjg3MzE5ZTU5
14
+ ZmE0NTk3MDllN2NjZGQyYjc1YzE0ZjRlZTk4ZDZmMWM2M2VlMDE5MGUyOWY5
15
+ ZDVlNWJmNTA3MDZiNTE0OTBjNjhkODk4N2U4NTBiZDdjOTJiM2M=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in arabic_conjugator.gemspec
4
+ gemspec
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ arabic_conjugator (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.1.1)
11
+ rspec (2.14.1)
12
+ rspec-core (~> 2.14.0)
13
+ rspec-expectations (~> 2.14.0)
14
+ rspec-mocks (~> 2.14.0)
15
+ rspec-core (2.14.8)
16
+ rspec-expectations (2.14.5)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.14.6)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ arabic_conjugator!
25
+ bundler (~> 1.5)
26
+ rake
27
+ rspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ Arabic-Conjugator
2
+ =================
3
+
4
+ Conjugates MSA verbs given three root letters, verb form, tense, and pronoun
5
+
6
+ Verb.new({root1: "ك", root2: "ت" , root3: "ب", form: 2, tense: "present", pronoun: :he}).conjugate
7
+
8
+ #=> "يكتّب"
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'arabic_conjugator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "arabic_conjugator"
8
+ spec.version = ArabicConjugator::VERSION
9
+ spec.authors = ["Anne Willborn"]
10
+ spec.email = ["awillborn@gmail.com"]
11
+ spec.summary = %q{Conjugate MSA verbs}
12
+ spec.homepage = ""
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+ spec.add_development_dependency "bundler", "~> 1.5"
18
+ spec.add_development_dependency "rake"
19
+ spec.add_development_dependency "rspec"
20
+ end
@@ -0,0 +1,43 @@
1
+ #coding: UTF-8
2
+
3
+ require_relative 'arabic_conjugator/version'
4
+ require_relative 'arabic_conjugator/factories/type_factory'
5
+ require_relative 'arabic_conjugator/factories/base_factory'
6
+ require_relative 'arabic_conjugator/factories/tense_factory'
7
+ require_relative 'arabic_conjugator/past_tense'
8
+ require_relative 'arabic_conjugator/present_tense'
9
+
10
+ class Verb
11
+ attr_reader :root1, :root2, :root3, :tense, :types, :form, :base, :opts, :pronoun
12
+
13
+ def initialize(opts)
14
+ @opts = opts
15
+ @root1 = opts[:root1]
16
+ @root2 = opts[:root2]
17
+ @root3 = opts[:root3]
18
+ @pronoun = opts[:pronoun]
19
+ @tense = opts[:tense]
20
+ @form = opts[:form]
21
+ @types = find_types
22
+ @base = find_base
23
+ end
24
+
25
+ def find_types
26
+ TypeFactory.new(@root1, @root2, @root3, @form).load_types
27
+ end
28
+
29
+ def find_base
30
+ BaseFactory.new(self).load_base
31
+ end
32
+
33
+ def find_tense
34
+ TenseFactory.new(self).create_tense
35
+ end
36
+
37
+ def conjugate
38
+ @tense = find_tense
39
+ @tense.conjugate
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ PAST_AFFIXES = { :I => "ت", :you_m => "ت", :you_f => "ت", :she => "ت" , :he =>'', :we => "نا", :you_pl => "تم", :they => "وا" }
4
+ PRESENT_AFFIXES = { :I => ["أ", ''], :you_m => ["ت", ''], :you_f => ["ت", "ين"], :he => ["ي", ""], :she => ["ت", ""], :we => ["ن", ''], :you_pl => ["ت", "ون"], :they => ["ي", "ون"] }
5
+
6
+ class Base
7
+
8
+ def initialize(verb)
9
+ @types = verb.types[0]
10
+ @root1 = verb.root1
11
+ @root2 = verb.root2
12
+ @root3 = verb.root3
13
+ @pronoun = verb.pronoun
14
+ adjust_first_radical if @root1 == "ء"
15
+ adjust_second_radical if @root2 == "ء"
16
+ adjust_third_radical if @root3 == "ء"
17
+ end
18
+
19
+ def regular_base
20
+ if @root3 == "أ" && @pronoun == :they
21
+ @base[0...-1] + "ؤ"
22
+ else
23
+ @base
24
+ end
25
+ end
26
+
27
+ def defective_base
28
+ @base = @base[0...-1]
29
+ if @pronoun == :he
30
+ @base + "ى"
31
+ elsif [:she, :they].include?(@pronoun)
32
+ @base
33
+ else
34
+ @base + "ي"
35
+ end
36
+ end
37
+
38
+ def assimilated_base
39
+ @base
40
+ end
41
+
42
+ def hollow_base
43
+ if @root3 == "أ" && @pronoun == :they
44
+ @base[0...-1] + "ؤ"
45
+ else
46
+ @base
47
+ end
48
+ end
49
+
50
+ def doubled_base
51
+ if [:he, :she, :they].include?(@pronoun)
52
+ @base[0...-1] + "ّ"
53
+ else
54
+ @base
55
+ end
56
+ end
57
+
58
+ def assimilated_defective_base
59
+ defective_base
60
+ end
61
+
62
+ def hollow_defective_base
63
+ defective_base
64
+ end
65
+
66
+ def adjust_first_radical
67
+ @root1 = "أ"
68
+ end
69
+
70
+ end
@@ -0,0 +1,74 @@
1
+ require_relative '../past_bases/form_I_past_base'
2
+ require_relative '../past_bases/form_II_past_base'
3
+ require_relative '../past_bases/form_III_past_base'
4
+ require_relative '../past_bases/form_IV_past_base'
5
+ require_relative '../past_bases/form_V_past_base'
6
+ require_relative '../past_bases/form_VI_past_base'
7
+ require_relative '../past_bases/form_VII_past_base'
8
+ require_relative '../past_bases/form_VIII_past_base'
9
+ require_relative '../past_bases/form_X_past_base'
10
+ require_relative '../present_bases/form_I_present_base'
11
+ require_relative '../present_bases/form_II_present_base'
12
+ require_relative '../present_bases/form_III_present_base'
13
+ require_relative '../present_bases/form_IV_present_base'
14
+ require_relative '../present_bases/form_V_present_base'
15
+ require_relative '../present_bases/form_VI_present_base'
16
+ require_relative '../present_bases/form_VII_present_base'
17
+ require_relative '../present_bases/form_VIII_present_base'
18
+ require_relative '../present_bases/form_X_present_base'
19
+
20
+
21
+ class BaseFactory
22
+ FORM_MAPPING = {
23
+ "1past" => FormIPastBase,
24
+ "2past" => FormIIPastBase,
25
+ "3past" => FormIIIPastBase,
26
+ "4past" => FormIVPastBase,
27
+ "5past" => FormVPastBase,
28
+ "6past" => FormVIPastBase,
29
+ "7past" => FormVIIPastBase,
30
+ "8past" => FormVIIIPastBase,
31
+ "10past" => FormXPastBase,
32
+ "1present" => FormIPresentBase,
33
+ "2present" => FormIIPresentBase,
34
+ "3present" => FormIIIPresentBase,
35
+ "4present" => FormIVPresentBase,
36
+ "5present" => FormVPresentBase,
37
+ "6present" => FormVIPresentBase,
38
+ "7present" => FormVIIPresentBase,
39
+ "8present" => FormVIIIPresentBase,
40
+ "10present" => FormXPresentBase
41
+ }
42
+
43
+ def initialize(verb)
44
+ @verb = verb
45
+ @form_name = verb.form
46
+ @tense = verb.opts[:tense]
47
+ @types = verb.types[0]
48
+ end
49
+
50
+ def load_base
51
+ form = FORM_MAPPING[@form_name.concat(@tense)].new(@verb)
52
+ case @types
53
+ when "assimilated defective"
54
+ form.assimilated_defective_base
55
+ when "hollow defective"
56
+ form.hollow_defective_base
57
+ when "assimilated"
58
+ form.assimilated_base
59
+ when "defective"
60
+ form.defective_base
61
+ when "hollow"
62
+ form.hollow_base
63
+ when "doubled"
64
+ form.doubled_base
65
+ when "regular"
66
+ form.regular_base
67
+ when "assimilated_taa"
68
+ form.assimilated_taa_base
69
+ when "morphed_taa"
70
+ form.morphed_taa_base
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,20 @@
1
+ require_relative '../past_tense'
2
+ require_relative '../present_tense'
3
+
4
+
5
+ class TenseFactory
6
+ MAPPING = {
7
+ "past" => Past,
8
+ "present" => Present
9
+ }
10
+
11
+ def initialize(verb)
12
+ @verb = verb
13
+ @tense = verb.opts[:tense]
14
+ end
15
+
16
+ def create_tense
17
+ MAPPING[@tense].new(@verb)
18
+ end
19
+
20
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ class TypeFactory
4
+ attr_reader :type
5
+
6
+ def initialize(root1, root2, root3, form)
7
+ @root1 = root1
8
+ @root2 = root2
9
+ @root3 = root3
10
+ @form = form
11
+ end
12
+
13
+ def load_types
14
+ types = []
15
+ types << "assimilated defective" if assimilated_defective?
16
+ types << "hollow defective" if hollow_defective?
17
+ types << "defective" if defective?
18
+ types << "hollow" if hollow?
19
+ types << "doubled" if doubled?
20
+ types << "assimilated" if assimilated?
21
+ types << "assimilated_taa" if assimilated_taa?
22
+ types << "morphed_taa" if morphed_taa?
23
+ types << "regular" if types.empty?
24
+ types
25
+ end
26
+
27
+ def assimilated_defective?
28
+ (@root1 == "و" || @root1 == "ي") && (@root3 == "و" || @root3 == "ي")
29
+ end
30
+
31
+ def hollow_defective?
32
+ (@root2 == "و" || @root2 == "ي") && (@root3 == "و" || @root3 == "ي")
33
+ end
34
+
35
+ def hollow?
36
+ @root2 == "و" || @root2 == "ي"
37
+ end
38
+
39
+ def defective?
40
+ @root3 == "و" || @root3 == "ي"
41
+ end
42
+
43
+ def doubled?
44
+ @root2 == @root3
45
+ end
46
+
47
+ def assimilated?
48
+ @root1 == "و" || @root1 == "ي"
49
+ end
50
+
51
+ def assimilated_taa?
52
+ @form == "8" && ["ت", "ث", "د", "ط", "ظ"].include?(@root1)
53
+ end
54
+
55
+ def morphed_taa?
56
+ @form == "8" && ["ذ", "ز", "ص", "ض"].include?(@root1)
57
+ end
58
+
59
+ end
@@ -0,0 +1,10 @@
1
+ class Form
2
+ attr_reader :base, :root1, :root2, :root3
3
+
4
+ def initialize(root1, root2, root3)
5
+ @root1 = root1
6
+ @root2 = root2
7
+ @root3 = root3
8
+ end
9
+
10
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ FORM_II_HOLLOW_DEFECTIVE = {
4
+ "سوي" => "ى",
5
+ "حيي" => "ا"
6
+ }
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ FORM_I_DEFECTIVE_PAST = {
4
+ "نسي" => "ي"
5
+ }
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ FORM_I_DEFECTIVE_PAST = {
4
+ "نسي" => "ي",
5
+ "ولي" => "ي",
6
+ "سوي" => "ي",
7
+ "حيي" => "ي",
8
+ "رضي" => "ي",
9
+ "قوي" => "ي",
10
+ "بقي" => "ي",
11
+ "رضو" => "ى"
12
+ }
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ FORM_I_DEFECTIVE_PRESENT = {
4
+ "سعي" => "ى",
5
+ "نسي" => "ى",
6
+ "حيي" => "ا",
7
+ "سوي" => "ى",
8
+ "ري" => "ى"
9
+ }
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ FORM_I_HAMZATED_PAST = {
4
+ "بدء" => "أ",
5
+ "سءل" => "أ",
6
+ "رءس" => "أ",
7
+ "بءس" => "ئ",
8
+ "رءي" => "أ",
9
+ "قرء" => "أ",
10
+ "جرء" => "ؤ",
11
+ "جيء" => "ئ",
12
+ "لءم" => "أ",
13
+ "بطء" => "ؤ",
14
+ "برء" => "ئ",
15
+ "رءي" => "أ"
16
+ }