Created
September 21, 2009 21:27
-
-
Save apohllo/190559 to your computer and use it in GitHub Desktop.
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
module Apohllo | |
module Synthesis | |
module Inflector | |
def inflect(arg,det) | |
det = det.dup | |
lexemes = to_lexemes(arg) | |
det[:gender] ||= determine_gender(lexemes) | |
(lexemes.map do |lexeme| | |
if lexeme.respond_to?(:inflect) | |
lexeme.inflect(det) | |
else | |
lexeme | |
end | |
end).join(" ") | |
end | |
def determine_gender(lexemes) | |
# the earlier elements have precedence over the later | |
lexemes.each do |lexeme| | |
if lexeme.respond_to?(:noun?) && lexeme.noun? | |
# special case - different gender for the "dziecko" | |
# lexeme, cf. dwoje dzieci/dwa drzewa | |
return :n1 if lexeme.base_form == "dziecko" | |
return lexeme.gender | |
end | |
end | |
nil | |
end | |
def to_lexemes(arg) | |
if arg.respond_to?(:inflect) | |
[arg] | |
else | |
if arg =~ / / | |
arg.split(/ /).map{|a| Rlp::Lexeme.find(a)[0] || a} | |
else | |
[Rlp::Lexeme.find(arg)[0] || arg] | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment