This is, what I hope will become a burgeoning array of tools for those interested in languages and linguistics. Any given language’s conjugation can be seen as a vector, an intersection of several aspects that singularly identify the correct grammatical choice for a given utterance.
In Latin, for example, this is defined by voice, mood, tense, number, and person. Other languages have a more- or less-specific vector. The function of this module, therefore, is to make the exhaustive generation of these vectors simple.
Usage is performed by passing a DSL into the module. The module then returns a module based on the language parameter. This resultant module can be mixed-in to your class (say, LanguageVerb) to define all the possible method calls (for playing nice with responds_to in case LanguageVerb uses metaprogramming in its responses)
Initial attempts at producing a verb tense generator wound up producing an incredibly confusing snarl of eval
statments and other oddities and wound up neither being specific enough to be easily used nor portable enough to be generally helpful.
The DSL is simple and recognizes the following statements:
The first statement. It takes a block that will be further processed and which contains other defining statements for the :Language. The only accepted argument is a symbol for the Language name.
This defines an aspect common to all vectors. Aspects are defined in an anonymous hash included in the block. The :position symbol is not presently used but instead stacks from left to right. This may have reason to change.
Inside the block one gives the aspect as a symbol and then gives an array containing the valid specifications for that aspect.
Example:
{ :voice => %w(active passive), :mood => %w(indicative subjunctive imperative) }
This defines an aspect common to all vectors. Aspects are defined in an anonymous hash included in the block. Thus for all existing vectors in the vector stack that match the Regexp, this aspect/specification will be added
{ :tense => %w(present imperfect future perfect pastperfect futureperfect) }
Languages are not perfectly rational in their combinations. Occasionally you may need to manually add a vector or, more likely, prune a vector.
Taken from the test/ directory
Lingustics::Verbs::Verbvector::VerbvectorGenerator.new do language :Latin do all_vectors :start_with do { :voice => %w(active passive), :mood => %w(indicative subjunctive imperative) } end vectors_that /.*_indicative_mood/ do { :tense => %w(present imperfect future perfect pastperfect futureperfect) } end vectors_that /.*_subjunctive_mood/ do { :tense => %w(present imperfect perfect pastperfect) } end vectors_that /.*_imperative_mood/ do { :tense => %w(present) } end all_vectors :end_with do { :number => %w(singular plural), :person => %w(first second third) } end exception :remove, :passive_voice_imperative_mood_present_tense end end
Steven G. Harms