Skip to content

Instantly share code, notes, and snippets.

@apohllo
Created September 21, 2009 21:27
Show Gist options
  • Save apohllo/190559 to your computer and use it in GitHub Desktop.
Save apohllo/190559 to your computer and use it in GitHub Desktop.
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