Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Draft - Lingua::ES::Conjugate

by Ea (Chaplain)
on Dec 19, 2011 at 12:33 UTC ( [id://944238]=perlmeditation: print w/replies, xml ) Need Help??

¡Feliz Navidad!

I started this spare time project in the vain hope that I might be able to aid my child process in learning how to conjugate Spanish verbs. I'm about halfway through and starting to run out of steam, so I'm putting it out for comments and making it available on Github in case anyone might find it useful.

The API consists of one sub, conjugate, which takes 4 arguments, the infinitive of the verb, the tense, the person and the number, so for the third person plural, present tense of the verb "dormir" would be produced with conjugate('dormir', 'present', 3, 2) and should return "duermen". Regular verbs are available for most tenses except perfect and progressive because those involve more than just changing a stem and adding the appropriate ending. There is a TODO list in the project which lets you know what doesn't work, but the best indicator of what does work is the test suite. That's been the big slog and will be the most valuable part of this module. I have over 300 tests now (about a third of what's needed)

This first attempt is just a prototype to see where the pitfalls are and as a result, the code design has grown organically to handle exceptions. I'm wondering if I'm going down hard-to-maintain path if I continue like this, so any suggestions on how to change stems, endings, prefixes, accents and deal with spelling changes to preserve pronunciation would be gratefully received.

Without any further ado, here's all 653 lines:

package Lingua::ES::Conjugate; use Carp; use Storable qw(dclone); require Exporter; our @ISA = qw(Exporter); use warnings; use strict; my @AR_present = qw( o as a amos áis an ); my @ER_present = qw( o es e emos éis en ); my @IR_present = qw( o es e imos ís en ); my @AR_preterit = qw( é aste ó amos asteis aron ); my @ER_preterit = qw( í iste ió imos isteis ieron ); my @IR_preterit = @ER_preterit; my @AR_imperfect = qw( aba abas aba ábamos abais aban ); my @ER_imperfect = qw( ía ías ía íamos íais ían ); my @IR_imperfect = @ER_imperfect; my @AR_subjunctive = qw( e es e emos éis en ); my @ER_subjunctive = qw( a as a amos áis an ); my @IR_subjunctive = @ER_subjunctive; my @future = qw( é ás á emos éis án ); my @conditional = qw( ía ías ía íamos íais ían ); my $AR_pastparticiple = 'ado'; my $ER_pastparticiple = 'ido'; my $IR_pastparticiple = $ER_pastparticiple; my $AR_gerund = 'ando'; my $ER_gerund = 'iendo'; my $IR_gerund = $ER_gerund; my @AR_imperitive = qw( a ad ); # tu habla, vosostros hablad, need for +mal and negative my @ER_imperitive = qw( e ed ); # tu habla, vosostros hablad, need for +mal and negative my @IR_imperitive = qw( e id ); # tu habla, vosostros hablad, need for +mal and negative

I had thought about putting it up for the Google's Code-in contest for teens, but I don't have time to mentor anyone. Anyways, thanks for looking

Replies are listed 'Best First'.
Re: Draft - Lingua::ES::Conjugate
by dHarry (Abbot) on Dec 19, 2011 at 13:33 UTC
    ¡Hola Ea!

    There are a lot more tenses in Spanish than the ones you mention:) Check for example: Wordreference (the one stop solution for this humble student of Castellano). You only posted a snippet of code, I went through it on github though.

    I would probably have implemented it differently. I think I would have chopped up all different tenses in categories, e.g.

    • Indicativo (presente, imperfecto, pretérito, futuro, condicional)
    • Tiempos compuestos (pretérito perfecto, pluscuamperfecto, futuro perfecto, condicional perfecto)
    • Subjuntivo (presente, imperfecto, futuro)
    • Imperativo (afirmativo, negativo)
    and use commonalities per category. NB there are even more tenses;)

    Also with respect to irregular verbs there is also a lot of structure, e.g. types of irregularity. Furthermore sometimes verbs are only irregular in some person and/or in some tense(s). I think you can make use of this structure.

    All in all you need about 90 ways of conjugating to cover close to a 100% of the verbs (based on the examples in my Spanish dictionary).

    un abrazo

    Harry

      Gracias, Harry

      I like treeware myself. This site only displays the first lines of code and provides a download link at the end of the code section to improve readability. I've got a good idea of all the verbs required, just not enough energy to finish it at the moment. The compound tenses are the ones that are bugging me a bit. I had hoped that all I would have to do is to run the auxiliary verb "haber" through the conjugate method and then add on the past participle, but the tail end of the conjugate sub makes that an ugly modification.

      Currently, it's

      my $verb_class = get_class($conj); my $stem = get_stem($conj); my $ending = $endings->{$conj->{tense}}->{$verb_class}->[ _get_end +ing_index($conj) ] or carp "No ending found for $conj->{tense} tense +of $conj->{verb} in conjugate( @_ )\n"; if ( my $pronoun = is_reflexive($conj) ) { # commands and infinitives can have the pronoun afterwards, wh +ich changes the accenting return "$pronoun $stem$ending"; } return $stem . $ending;

      The irregular verbs are being handled by hashes that hold the special cases which weren't as bad as I'd expected. The imperfect, future and conditional are finished as are the regular forms of the present, preterite and subjunctives. There are a dozen classes of spelling changes which need to be handled and I've glossed over the imperative. As I'm only conjugating verbs for now, I'm not considering object pronouns which can get caught up between the verbs or stuck on the end. Just trying to keep it simple.

      I do wonder why this hasn't been written before now. It isn't that hard and should have some uses. Essentially, it's the reverse of Lingua::StopWords for Spanish verbs. Personally, I could see this in the backend of a quiz site or app. Any thoughts on where you'd think it would be useful?

      Que vayas bien,
      Boyd

        Any thoughts on where you'd think it would be useful?

        I can see it go into a website to learn Spanish, maybe complemented by:

        • A dictionary
        • Common usage of the verbs
        I can also see it acting as a building block for other applications, e.g. generating sentences, validating sentences etc.

      As a former native Spaniard, i can assure you this:
      Indicativo (presente, imperfecto, pretérito, futuro, condicional)
      Tiempos compuestos (pretérito perfecto, pluscuamperfecto, futuro perfecto, condicional perfecto)
      Subjuntivo (presente, imperfecto, futuro)
      Imperativo (afirmativo, negativo)


      It's just to make it sound as we have some sort of "lexical rules" or "coherent structures", as well as the accented words, plus middle H usage, v or b, y or LL, etc...

      We can just survive a whole life with the basic verbs and about 100 words...

      Don't be fooled by the Real Academia Española, we send there all the elder writers/bookworms to have them busy over "language quality", to prevent them from raving at wild 60+ parties over Benidorm! (tourists could not follow their rythm overnight and fainted, increasing national healthcare costs).

      Remember, never try to follow the lead of a Spaniard on a party, no matter how old he/she is, he/she is being training hard since chilhood!... You won't ever know what hit you!! =8-P

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://944238]
Approved by ww
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found