Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored NounInflector and project layout.
- Loading branch information
Showing
8 changed files
with
217 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
require 'noun_inflector' | ||
$: << File.dirname(__FILE__) | ||
|
||
require 'homer/greek_string' | ||
require 'homer/core_ext' | ||
require 'homer/article_inflector' | ||
require 'homer/noun_inflector' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
String.class_eval { include GreekString } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# coding: utf-8 | ||
module GreekString | ||
|
||
GREEK_UPPER = 'ΑᾺΆἈἊἌἎἉἋἍἏᾼΒΓΔΕῈΈἘἚἜἙἛἝΖΗῊΉἨἪἬἮἩἫἭἯῌΘΙῚΊἸἺἼἾἹἻἽἿΚΛΜΝΞΟῸΌὈὊὌὉὋὍΠΡῬΣΣΤΥῪΎὙὛὝὟΦΧΨΩῺΏὨὪὬὮὩὫὭὯῼ' | ||
GREEK_LOWER = 'αὰάἀἂἄἆἁἃἅἇᾳβγδεὲέἐἒἔἑἓἕζηὴήἠἢἤἦἡἣἥἧῃθιὶίἰἲἴἶἱἳἵἷκλμνξοὸόὀὂὄὁὃὅπρῥςστυὺύὑὓὕὗφχψωὼώὠὢὤὦὡὣὥὧῳ' | ||
|
||
GREEK_ACCENTED = 'ὰάᾶἂἄἆἃἅἇᾲᾴᾷὲέἒἔἓἕὴήῆἢἤἦἣἥἧῂῄῇὶίῖἲἴἶἳἵἷὸόὂὄὃὅὺύῦὒὔὖὓὕὗὼώῶὢὤὦὣὥὧῲῴῷ' | ||
GREEK_UNACCENTED = 'αααἀἀἀἁἁἁᾳᾳᾳεεἐἐἑἑηηηἠἠἠἡἡἡῃῃῃιιιἰἰἰἱἱἱοοὀὀὁὁυυυὐὐὐὑὑὑωωωὠὠὠὡὡὡῳῳῳ' | ||
|
||
GREEK_VOWELS_UNACCENTED = 'αἀἁᾳεἐἑηἠἡῃιἰἱοὀὁυὐὑωὠὡῳ' | ||
GREEK_VOWELS_WITH_OXIA = 'άἄἅᾴέἔἕήἤἥῄίἴἵόὄὅύὔὕώὤὥῴ' | ||
GREEK_VOWELS_WITH_PERISPOMENE = 'ᾶἆἇᾷ***ῆἦἧῇῖἶἷ***ῦὖὗῶὦὧῷ' | ||
|
||
GREEK_DIPTHONG_REGEXP = /[αᾳεο][ιἰἱυὐὑ]|υ[ιἰἱ]|[ηῃ][υὐὑ]/ | ||
|
||
def downcase_greek | ||
tr(GREEK_UPPER, GREEK_LOWER).sub(/σ$/, 'ς') | ||
end | ||
|
||
def upcase_greek | ||
tr(GREEK_LOWER, GREEK_UPPER) | ||
end | ||
|
||
def remove_greek_accent | ||
tr(GREEK_ACCENTED, GREEK_UNACCENTED) | ||
end | ||
|
||
def add_greek_oxytone | ||
s = remove_greek_accent | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/) | ||
s[i] = s[i].tr(GREEK_VOWELS_UNACCENTED, GREEK_VOWELS_WITH_OXIA) | ||
s | ||
end | ||
|
||
def add_greek_paroxytone | ||
s = remove_greek_accent | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/) - 1 | ||
i -= 1 if s[i, 2] =~ GREEK_DIPTHONG_REGEXP | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/, i) | ||
s[i] = s[i].tr(GREEK_VOWELS_UNACCENTED, GREEK_VOWELS_WITH_OXIA) | ||
s | ||
end | ||
|
||
def add_greek_proparoxytone | ||
s = remove_greek_accent | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/) - 1 | ||
i -= 1 if s[i, 2] =~ GREEK_DIPTHONG_REGEXP | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/, i) - 1 | ||
i -= 1 if s[i, 2] =~ GREEK_DIPTHONG_REGEXP | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/, i) | ||
s[i] = s[i].tr(GREEK_VOWELS_UNACCENTED, GREEK_VOWELS_WITH_OXIA) | ||
s | ||
end | ||
|
||
def add_greek_perispomenon | ||
s = remove_greek_accent | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/) | ||
s[i] = s[i].tr(GREEK_VOWELS_UNACCENTED, GREEK_VOWELS_WITH_PERISPOMENE) | ||
s | ||
end | ||
|
||
def add_greek_properispomenon | ||
s = remove_greek_accent | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/) - 1 | ||
i -= 1 if s[i, 2] =~ GREEK_DIPTHONG_REGEXP | ||
i = s.rindex(/[#{GREEK_VOWELS_UNACCENTED}]/, i) | ||
s[i] = s[i].tr(GREEK_VOWELS_UNACCENTED, GREEK_VOWELS_WITH_PERISPOMENE) | ||
s | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# coding: utf-8 | ||
module NounInflector | ||
|
||
def self.inflect(lemma, inflection) | ||
case lemma | ||
when /[αάηή]ς?/ then inflect_d1(lemma, inflection) | ||
when /[οό][ςν]$/ then inflect_d2(lemma, inflection) | ||
end | ||
end | ||
|
||
private | ||
|
||
def self.inflect_d1(lemma, inflection) | ||
case kind = lemma[-2, 2].remove_greek_accent | ||
when /.η/ then kind = 'Xη' | ||
when /[βγδζθκλμνξπστφχψ]α/ then kind = 'Cα' | ||
when /.α/ then kind = 'Vα' | ||
end | ||
ivow = (kind[-1] == 'ς' ? -2 : -1) | ||
form = lemma[0...ivow] + D1_ENDINGS[kind.to_sym][inflection] | ||
if 'άή'.include?(lemma[ivow]) | ||
if [:gs, :ds, :gp, :dp].include?(inflection) | ||
form.add_greek_perispomenon | ||
else | ||
form.add_greek_oxytone | ||
end | ||
elsif inflection == :gp | ||
form.add_greek_perispomenon | ||
elsif [:gs, :ds, :dp].include?(inflection) || (kind == 'Vα' && inflection == :ap) | ||
form.add_greek_paroxytone | ||
elsif kind == 'Xη' && inflection == :np | ||
form.add_greek_properispomenon | ||
else | ||
form | ||
end | ||
end | ||
|
||
def self.inflect_d2(lemma, inflection) | ||
form = lemma[0..-3] + D2_ENDINGS[lemma[-1].to_sym][inflection] | ||
if lemma[-2] == 'ό' | ||
if [:gs, :ds, :gp, :dp].include?(inflection) | ||
form.add_greek_perispomenon | ||
else | ||
form.add_greek_oxytone | ||
end | ||
elsif [:gs, :ds, :gp, :dp].include?(inflection) || (lemma[-1] == 'ς' && inflection == :ap) | ||
form.add_greek_paroxytone | ||
else | ||
form | ||
end | ||
end | ||
|
||
D1_ENDINGS = { | ||
:Vα => { :ns => 'α', :np => 'αι', | ||
:gs => 'ας', :gp => 'ων', | ||
:ds => 'ᾳ', :dp => 'αις', | ||
:as => 'αν', :ap => 'ας', | ||
:vs => 'α', :vp => 'αι' }, | ||
:Xη => { :ns => 'η', :np => 'αι', | ||
:gs => 'ης', :gp => 'ων', | ||
:ds => 'ῃ', :dp => 'αις', | ||
:as => 'ην', :ap => 'ας', | ||
:vs => 'η', :vp => 'αι' }, | ||
:Cα => { :ns => 'α', :np => 'αι', | ||
:gs => 'ης', :gp => 'ων', | ||
:ds => 'ῃ', :dp => 'αις', | ||
:as => 'αν', :ap => 'ας', | ||
:vs => 'α', :vp => 'αι' }, | ||
:ας => { :ns => 'ας', :np => 'αι', | ||
:gs => 'ου', :gp => 'ων', | ||
:ds => 'ᾳ', :dp => 'αις', | ||
:as => 'αν', :ap => 'ας', | ||
:vs => 'α', :vp => 'αι' }, | ||
:ης => { :ns => 'ης', :np => 'αι', | ||
:gs => 'ου', :gp => 'ων', | ||
:ds => 'ῃ', :dp => 'αις', | ||
:as => 'ην', :ap => 'ας', | ||
:vs => 'α', :vp => 'αι' } | ||
} | ||
|
||
D2_ENDINGS = { | ||
:ς => { :ns => 'ος', :np => 'οι', | ||
:gs => 'ου', :gp => 'ων', | ||
:ds => 'ῳ', :dp => 'οις', | ||
:as => 'ον', :ap => 'ους', | ||
:vs => 'ε', :vp => 'οι' }, | ||
:ν => { :ns => 'ον', :np => 'α', | ||
:gs => 'ου', :gp => 'ων', | ||
:ds => 'ῳ', :dp => 'οις', | ||
:as => 'ον', :ap => 'α', | ||
:vs => 'ον', :vp => 'α' } | ||
} | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.