Skip to content

Commit

Permalink
Added more first-decelension nouns and refactored NounInflector.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronhopper committed Jun 27, 2011
1 parent 0ec1bd6 commit 4e7903c
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 42 deletions.
139 changes: 116 additions & 23 deletions lib/noun_inflector.rb
Expand Up @@ -2,25 +2,86 @@
module NounInflector

def self.inflect(lemma, inflection)
if lemma[-1] == 'ή'
lemma[0..-2] + D1_ENDINGS[inflection]
elsif lemma[-2..-1] == 'ός'
lemma[0..-3] + D2MF_ACCENTED_ENDINGS[inflection]
elsif lemma[-2..-1] == 'όν'
lemma[0..-3] + D2N_ACCENTED_ENDINGS[inflection]
elsif lemma[-2..-1] == 'ος'
stem = lemma[0..-3]
stem = move_oxia_to_last_vowel(stem) if [:gs, :ds, :gp, :dp, :ap].include?(inflection)
stem + D2MF_UNACCENTED_ENDINGS[inflection]
elsif lemma[-2..-1] == 'ον'
stem = lemma[0..-3]
stem = move_oxia_to_last_vowel(stem) if [:gs, :ds, :gp, :dp].include?(inflection)
stem + D2N_UNACCENTED_ENDINGS[inflection]
case lemma
when /[βγδζθκλμνξπστφχψ]α$/ then inflect_d1_alpha_impure_early_accent(lemma, inflection)
when /α$/ then inflect_d1_alpha_pure_early_accent(lemma, inflection)
when /ά$/ then inflect_d1_alpha_pure_final_accent(lemma, inflection)
when /η$/ then inflect_d1_eta_pure_early_accent(lemma, inflection)
when /ή$/ then inflect_d1_eta_pure_final_accent(lemma, inflection)
when /ος$/ then inflect_d2_mf_early_accent(lemma, inflection)
when /ός$/ then inflect_d2_mf_final_accent(lemma, inflection)
when /ον$/ then inflect_d2_n_early_accent(lemma, inflection)
when /όν$/ then inflect_d2_n_final_accent(lemma, inflection)
end
end

private

def self.inflect_d1_alpha_impure_early_accent(lemma, inflection)
stem = lemma[0..-2]
if inflection == :gp
stem = remove_accent(stem)
elsif [:gs, :ds, :dp].include?(inflection)
stem = move_oxia_to_last_vowel(stem)
end
stem + D1X_UNACCENTED_ENDINGS[inflection]
end

def self.inflect_d1_alpha_pure_early_accent(lemma, inflection)
stem = lemma[0..-2]
if inflection == :gp
stem = remove_accent(stem)
elsif [:gs, :ds, :dp, :ap].include?(inflection)
stem = move_oxia_to_last_vowel(stem)
end
stem + D1A_UNACCENTED_ENDINGS[inflection]
end

def self.inflect_d1_alpha_pure_final_accent(lemma, inflection)
lemma[0..-2] + D1A_ACCENTED_ENDINGS[inflection]
end

def self.inflect_d1_eta_pure_early_accent(lemma, inflection)
stem = lemma[0..-2]
if inflection == :np
stem = move_circumflex_to_last_vowel(stem)
elsif inflection == :gp
stem = remove_accent(stem)
end
stem + D1H_UNACCENTED_ENDINGS[inflection]
end

def self.inflect_d1_eta_pure_final_accent(lemma, inflection)
lemma[0..-2] + D1H_ACCENTED_ENDINGS[inflection]
end

def self.inflect_d2_mf_early_accent(lemma, inflection)
stem = lemma[0..-3]
stem = move_oxia_to_last_vowel(stem) if [:gs, :ds, :gp, :dp, :ap].include?(inflection)
stem + D2MF_UNACCENTED_ENDINGS[inflection]
end

def self.inflect_d2_mf_final_accent(lemma, inflection)
lemma[0..-3] + D2MF_ACCENTED_ENDINGS[inflection]
end

def self.inflect_d2_n_early_accent(lemma, inflection)
stem = lemma[0..-3]
stem = move_oxia_to_last_vowel(stem) if [:gs, :ds, :gp, :dp].include?(inflection)
stem + D2N_UNACCENTED_ENDINGS[inflection]
end

def self.inflect_d2_n_final_accent(lemma, inflection)
lemma[0..-3] + D2N_ACCENTED_ENDINGS[inflection]
end

def self.move_circumflex_to_last_vowel(stem)
stem = remove_accent(stem)
i = stem.rindex(/[αἀἁᾳεἐἑηἠἡῃιἰἱοὀὁυὐὑωὠὡῳ]/)
stem[i] = stem[i].tr('αἀἁᾳηἠἡῃιἰἱυὐὑωὠὡῳ', 'ᾶἆἇᾷῆἦἧῇῖἶἷῦὖὗῶὦὧῷ')
stem
end

def self.move_oxia_to_last_vowel(stem)
stem = remove_accent(stem)
i = stem.rindex(/[αἀἁᾳεἐἑηἠἡῃιἰἱοὀὁυὐὑωὠὡῳ]/)
Expand All @@ -33,7 +94,39 @@ def self.remove_accent(word)
'αααἀἀἀἁἁἁᾳᾳᾳεεἐἐἑἑηηηἠἠἠἡἡἡῃῃῃιιιἰἰἰἱἱἱοοὀὀὁὁυυυὐὐὐὑὑὑωωωὠὠὠὡὡὡῳῳῳ'
end

D1_ENDINGS = {
D1X_UNACCENTED_ENDINGS = {
:ns => 'α', :np => 'αι',
:gs => 'ης', :gp => 'ῶν',
:ds => 'ῃ', :dp => 'αις',
:as => 'αν', :ap => 'ας',
:vs => 'α', :vp => 'αι'
}

D1A_UNACCENTED_ENDINGS = {
:ns => 'α', :np => 'αι',
:gs => 'ας', :gp => 'ῶν',
:ds => 'ᾳ', :dp => 'αις',
:as => 'αν', :ap => 'ας',
:vs => 'α', :vp => 'αι'
}

D1A_ACCENTED_ENDINGS = {
:ns => 'ά', :np => 'αί',
:gs => 'ᾶς', :gp => 'ῶν',
:ds => 'ᾷ', :dp => 'αῖς',
:as => 'άν', :ap => 'άς',
:vs => 'ά', :vp => 'αί'
}

D1H_UNACCENTED_ENDINGS = {
:ns => 'η', :np => 'αι',
:gs => 'ης', :gp => 'ῶν',
:ds => 'ῃ', :dp => 'αις',
:as => 'ην', :ap => 'ας',
:vs => 'η', :vp => 'αι'
}

D1H_ACCENTED_ENDINGS = {
:ns => 'ή', :np => 'αί',
:gs => 'ῆς', :gp => 'ῶν',
:ds => 'ῇ', :dp => 'αῖς',
Expand All @@ -49,14 +142,6 @@ def self.remove_accent(word)
:vs => 'ε', :vp => 'οι'
}

D2N_UNACCENTED_ENDINGS = {
:ns => 'ον', :np => 'α',
:gs => 'ου', :gp => 'ων',
:ds => 'ῳ', :dp => 'οις',
:as => 'ον', :ap => 'α',
:vs => 'ον', :vp => 'α'
}

D2MF_ACCENTED_ENDINGS = {
:ns => 'ός', :np => 'οί',
:gs => 'οῦ', :gp => 'ῶν',
Expand All @@ -65,6 +150,14 @@ def self.remove_accent(word)
:vs => 'έ', :vp => 'οί'
}

D2N_UNACCENTED_ENDINGS = {
:ns => 'ον', :np => 'α',
:gs => 'ου', :gp => 'ων',
:ds => 'ῳ', :dp => 'οις',
:as => 'ον', :ap => 'α',
:vs => 'ον', :vp => 'α'
}

D2N_ACCENTED_ENDINGS = {
:ns => 'όν', :np => 'ά',
:gs => 'οῦ', :gp => 'ῶν',
Expand Down
77 changes: 58 additions & 19 deletions spec/noun_inflector_spec.rb
Expand Up @@ -3,7 +3,59 @@

describe NounInflector do

describe "first-declension accented eta nouns" do
describe "first-declension (alpha-impure early-accent)" do
specify { subject.inflect('γλῶσσα', :ns).should == 'γλῶσσα' }
specify { subject.inflect('γλῶσσα', :gs).should == 'γλώσσης' }
specify { subject.inflect('γλῶσσα', :ds).should == 'γλώσσῃ' }
specify { subject.inflect('γλῶσσα', :as).should == 'γλῶσσαν' }
specify { subject.inflect('γλῶσσα', :vs).should == 'γλῶσσα' }
specify { subject.inflect('γλῶσσα', :np).should == 'γλῶσσαι' }
specify { subject.inflect('γλῶσσα', :gp).should == 'γλωσσῶν' }
specify { subject.inflect('γλῶσσα', :dp).should == 'γλώσσαις' }
specify { subject.inflect('γλῶσσα', :ap).should == 'γλῶσσας' }
specify { subject.inflect('γλῶσσα', :vp).should == 'γλῶσσαι' }
end

describe "first-declension (alpha-pure early-accent)" do
specify { subject.inflect('ἀλήθεια', :ns).should == 'ἀλήθεια' }
specify { subject.inflect('ἀλήθεια', :gs).should == 'ἀληθείας' }
specify { subject.inflect('ἀλήθεια', :ds).should == 'ἀληθείᾳ' }
specify { subject.inflect('ἀλήθεια', :as).should == 'ἀλήθειαν' }
specify { subject.inflect('ἀλήθεια', :vs).should == 'ἀλήθεια' }
specify { subject.inflect('ἀλήθεια', :np).should == 'ἀλήθειαι' }
specify { subject.inflect('ἀλήθεια', :gp).should == 'ἀληθειῶν' }
specify { subject.inflect('ἀλήθεια', :dp).should == 'ἀληθείαις' }
specify { subject.inflect('ἀλήθεια', :ap).should == 'ἀληθείας' }
specify { subject.inflect('ἀλήθεια', :vp).should == 'ἀλήθειαι' }
end

describe "first-declension (alpha-pure final-accent)" do
specify { subject.inflect('δωρεά', :ns).should == 'δωρεά' }
specify { subject.inflect('δωρεά', :gs).should == 'δωρεᾶς' }
specify { subject.inflect('δωρεά', :ds).should == 'δωρεᾷ' }
specify { subject.inflect('δωρεά', :as).should == 'δωρεάν' }
specify { subject.inflect('δωρεά', :vs).should == 'δωρεά' }
specify { subject.inflect('δωρεά', :np).should == 'δωρεαί' }
specify { subject.inflect('δωρεά', :gp).should == 'δωρεῶν' }
specify { subject.inflect('δωρεά', :dp).should == 'δωρεαῖς' }
specify { subject.inflect('δωρεά', :ap).should == 'δωρεάς' }
specify { subject.inflect('δωρεά', :vp).should == 'δωρεαί' }
end

describe "first-declension (eta-pure early-accent)" do
specify { subject.inflect('ἀγάπη', :ns).should == 'ἀγάπη' }
specify { subject.inflect('ἀγάπη', :gs).should == 'ἀγάπης' }
specify { subject.inflect('ἀγάπη', :ds).should == 'ἀγάπῃ' }
specify { subject.inflect('ἀγάπη', :as).should == 'ἀγάπην' }
specify { subject.inflect('ἀγάπη', :vs).should == 'ἀγάπη' }
specify { subject.inflect('ἀγάπη', :np).should == 'ἀγᾶπαι' }
specify { subject.inflect('ἀγάπη', :gp).should == 'ἀγαπῶν' }
specify { subject.inflect('ἀγάπη', :dp).should == 'ἀγάπαις' }
specify { subject.inflect('ἀγάπη', :ap).should == 'ἀγάπας' }
specify { subject.inflect('ἀγάπη', :vp).should == 'ἀγάπαι' }
end

describe "first-declension (eta-pure final-accent)" do
specify { subject.inflect('ἀρχή', :ns).should == 'ἀρχή' }
specify { subject.inflect('ἀρχή', :gs).should == 'ἀρχῆς' }
specify { subject.inflect('ἀρχή', :ds).should == 'ἀρχῇ' }
Expand All @@ -16,7 +68,7 @@
specify { subject.inflect('ἀρχή', :vp).should == 'ἀρχαί' }
end

describe "second-declension nouns (early-accent)" do
describe "second-declension (masculine/feminine early-accent)" do
specify { subject.inflect('ἄνθρωπος', :ns).should == 'ἄνθρωπος' }
specify { subject.inflect('ἄνθρωπος', :gs).should == 'ἀνθρώπου' }
specify { subject.inflect('ἄνθρωπος', :ds).should == 'ἀνθρώπῳ' }
Expand All @@ -29,7 +81,7 @@
specify { subject.inflect('ἄνθρωπος', :vp).should == 'ἄνθρωποι' }
end

describe "second-declension nouns (final-accent)" do
describe "second-declension (masculine/feminine final-accent)" do
specify { subject.inflect('ἀδελφός', :ns).should == 'ἀδελφός' }
specify { subject.inflect('ἀδελφός', :gs).should == 'ἀδελφοῦ' }
specify { subject.inflect('ἀδελφός', :ds).should == 'ἀδελφῷ' }
Expand All @@ -42,7 +94,7 @@
specify { subject.inflect('ἀδελφός', :vp).should == 'ἀδελφοί' }
end

describe "second-declension nouns (penult-circumflex)" do
describe "second-declension (masculine/feminine penult-circumflex)" do
specify { subject.inflect('δοῦλος', :ns).should == 'δοῦλος' }
specify { subject.inflect('δοῦλος', :gs).should == 'δούλου' }
specify { subject.inflect('δοῦλος', :ds).should == 'δούλῳ' }
Expand All @@ -55,7 +107,7 @@
specify { subject.inflect('δοῦλος', :vp).should == 'δοῦλοι' }
end

describe "second-declension nouns (nueter early-accent)" do
describe "second-declension (nueter early-accent)" do
specify { subject.inflect('δῶρον', :ns).should == 'δῶρον' }
specify { subject.inflect('δῶρον', :gs).should == 'δώρου' }
specify { subject.inflect('δῶρον', :ds).should == 'δώρῳ' }
Expand All @@ -68,7 +120,7 @@
specify { subject.inflect('δῶρον', :vp).should == 'δῶρα' }
end

describe "second-declension nouns (nueter final-accent)" do
describe "second-declension (nueter final-accent)" do
specify { subject.inflect('ἱερόν', :ns).should == 'ἱερόν' }
specify { subject.inflect('ἱερόν', :gs).should == 'ἱεροῦ' }
specify { subject.inflect('ἱερόν', :ds).should == 'ἱερῷ' }
Expand All @@ -81,17 +133,4 @@
specify { subject.inflect('ἱερόν', :vp).should == 'ἱερά' }
end

=begin
LETTERS = "αβγδεζηθικλμνξοπρςστυφχψω"
ALPHA = "αὰάᾶἀἂἄἆἁἃἅἇᾳᾲᾴᾷ"
EPSILON = "εὲέ ἐἒἔ ἑἓἕ "
ETA = "ηὴήῆἠἢἤἦἡἣἥἧῃῂῄῇ"
IOTA = "ιὶίῖἰἲἴἶἱἳἵἷ "
OMICRON = "οὸό ὀὂὄ ὁὃὅ "
RHO = "ρ ῤ ῥ "
UPSILON = "υὺύῦὐὒὔὖὑὓὕὗ "
OMEGA = "ωὼώῶὠὢὤὦὡὣὥὧῳῲῴῷ"
end
=end

end

0 comments on commit 4e7903c

Please sign in to comment.