I've just started learning Python 3 and built a small program to help me study Basque. One of the most complicated things about Basque is the verb system, in English verbs sometimes change depending on the person (eg. 3rd person singular generally adds 's' in the present). In Basque, verbs can change depending on how many objects are being acted upon, which person is doing the action, whether someone is receiving the action, etc. So i wrote a small program to help me practice some of the verb forms as a sort of Python practice. However, i feel like my method could be simplified quite a bit. (Source is available here).

The NOR-NORI verb is used to talk about something happening to an indirect object. NOR is the subject, and NORI is the indirect object. For example, IT (NOR) seems strange TO ME (NORI), or WE (NOR) seem strong TO YOU (NORI). Currently, i've got something like this (I've changed the Basque pronouns to English ones to make it easier to follow):

Code:
NOR = (('I','NATZAI'),
      ('THOU','HATZAI'),
      ('HE','ZAI'),
      ('WE','GATZAIZKI'),
      ('YOU','ZATZAIZKI'),
      ('YALL','ZATZAIZKI+TE'),
      ('THEY','ZAIZKI'))
NORI = (('TO ME','T/DA'),
      ('TO THEE','K'),
      ('TO HIM','O'),
      ('TO US','GU'),
      ('TO YOU','ZU'),
      ('TO YALL','ZUE'),
      ('TO THEM','E'))
What i do is pass the NOR (I, you, they) part and NORI part to my buildVerb function, which looks through the lists, pulls the correct stem/ending out, and then builds the verb. The problem is that each time i want to add a new verb or new tense, i've got to create a new function. I think a better method would be to pass two lists to the function, the first one has the separate parts of the verb (there can be between one and three parts) and the second list holding the corresponding verb tables (here, (NOR,NORI)). It'd be easier to add new verbs later on, but i'm still not sure if that's the best way to go about it and i'm not quite sure how to go about it, either.

I'm not sure if what i've said makes any sense or not, but i'd appreciate any help Very Happy
I did something similar for German and implemented classes for each type of word I was studying (noun, verb, etc) that encompassed irregularities for that kind of word (e.g. vowel changes for different tenses), and then classes for each tense / declension. I don't know how much irregularity Basque has, but if it's nontrivial (which is usually the case for natural languages), you'll want to do some kind of similar data encapsulation.
Thanks, Basque is kinda special in that very few verbs are actually conjugated. Most words use an auxiliary (similar to sein/haben/werden in German past/future tenses). Right now i'm just focusing on verbs, though something to practice the cases would be useful in the future, too. So you really just need to learn how the auxiliary verbs conjugate (there are two, one for transitive verbs and one for intransitive). I'm very new to Python, i've been reading through the Dive Into Python 3 tutorials and have read through pretty much everything, but there are no practical drills or anything after each lesson so, while i can understand what the code does, i wouldn't necessarily be able to write it.

How did you set up the classes? And how exactly did you use them? I just looked at some code for a Spanish conjugator and their idea seems pretty similar to mine, my idea was to come up with lists of stems and suffixes for each tense for both the transitive and intransitive auxiliary and put them in lists or dictionaries, i dunno. I'm not really sure what the best way to organize it would be.
Here was the code I used for displaying just the basic form of the word. Tracking stems and suffixes is basically the right approach, but having classes allows you to encapsulate any logic related to special casing. In any case, this is how you set up classes:


Code:

class DWord(object):

   def __init__(self, deutsch,english):
      self.deutsch = deutsch
      self.english = english
   def auf_Deutsch(self):
      return self.deutsch

   def in_English(self):
      return self.english

   def __repr__(self):
      return "DWord(\'%s\' : \'%s\')" % (self.english, self.deutsch)
      
   def __string__(self):
      return "%s\t:\t%s" % (self.english, self.deutsch)

class DNoun(DWord):
   ALWAYS_PLURAL = -1
   NEVER_PLURAL = 1
   ARTICLES = {"p" : "die", "m" : "der", "f" : "die", "n" : "das"}
   def __init__(self,deutsch,english,gender,plural,n=None):
      DWord.__init__(self,deutsch,english)
      self.gender=gender
      self.plural=plural
      self.n = n

   def auf_Deutsch(self):
      pieces = ["%s %s" % (DNoun.ARTICLES[self.gender], self.deutsch)]
      if self.n:
         pieces += [self.n]
      if self.plural and self.plural != DNoun.ALWAYS_PLURAL and self.plural != DNoun.NEVER_PLURAL:
         pieces += [self.plural]
      elif self.plural:
         pieces += ["-"]
      
      return ", ".join(pieces)

class DVerb(DWord):
   def __init__(self,deutsch_infinitive,english,vowel_change,d_present,d_past_participle):
      DWord.__init__(self,deutsch_infinitive,english)
      self.vowel_change = vowel_change
      self.d_present = d_present
      self.d_past_participle = d_past_participle

   def auf_Deutsch(self):
      return "%s; %s" % ((("%s (%s)" % (self.deutsch,self.d_present)) if self.vowel_change else self.deutsch), self.d_past_participle)
Sorry for the late reply, had a busy couple of days. Thanks for sharing the class definitions, i'm going to see if i can clean things up a bit and make it a bit more modular this weekend.
Ok, i'm getting closer to getting something much more flexible. I've got a file that uses indentation to separate its entries, it looks like this:

Code:
nor-nori
   present
      nor
         natzai, hatzai, zai, gatzaizki, zatzaizki, zatzaizki+te, zaizki
      nori
         t/da, k, o, gu, zu, zue, e
   past
      nor
         nintzai+n, hintzai+n, zitzai+n, gintzaizki+n, zintzaizki+n, zintzaizki+ten, zitzaizki+n
      nori
         da, a, o, gu, zu, zue, e
joan
etc.

I've written two pieces of code to parse the file, one parses it into a list that looks like this:

Code:
>>> VERBS[0]
['nor-nori',
  ['present',
    ['nor',
      ['natzai', 'hatzai', 'zai', 'gatzaizki', 'zatzaizki', 'zatzaizki+te', 'zaizki']],
    ['nori',
      ['t/da', 'k', 'o', 'gu', 'zu', 'zue', 'e']]],
  ['past',
    ['nor',
      ['nintzai+n', 'hintzai+n', 'zitzai+n', 'gintzaizki+n', 'zintzaizki+n', 'zintzaizki+ten', 'zitzaizki+n']],
    ['nori',
      ['da', 'a', 'o', 'gu', 'zu', 'zue', 'e']]]]
Basically, a bunch of lists withinn lists within lists.

The other loads the file into a dictionary, which looks like this:

Code:
>>> VERBS['nor-nori']
{'past':
  {'nor': ['nintzai+n', 'hintzai+n', 'zitzai+n', 'gintzaizki+n', 'zintzaizki+n', 'zintzaizki+ten', 'zitzaizki+n'],
  'nori': ['da', 'a', 'o', 'gu', 'zu', 'zue', 'e']},
'present':
  {'nor': ['natzai', 'hatzai', 'zai', 'gatzaizki', 'zatzaizki', 'zatzaizki+te', 'zaizki'],
  'nori': ['t/da', 'k', 'o', 'gu', 'zu', 'zue', 'e']}}
The dictionary seems like the obvious choice since the code to use it would be much cleaner (i think), but the problem is that there's no order to the dictionary and my menu routine is built based off the items in the dictionary, so each time the program runs the menu changes. I'd like to keep them in the order they've got in the file. Or do i have the whole idea wrong?
if you want to iterate over a dictionary in a fixed order:

Code:

>>> for k,v in sorted(dictvar.iteritems()):
... # do stuff here
How would i order it in the same order i read it from the text file? I believe that would organize it alphabetically. And i think Python 3 doesn't have an iteritems attribute anymore, i think items() does the same thing.

I came across the OrderedDicts which seems like it's exactly what i need, but i dunno if it's bad form (ie. that i'm going about the problem the wrong way).

Actually, i just decided to reorganize my data a bit and now it's much more manageable, i've got a list of dictionaries with the following entries: name, type, and tenses. Tenses has a dictionary of the tenses. I tried putting that into a list to make it easier to order them, but in the end i just decided to use the sorted function with a dictionary.

EDIT: I spent a few hours working on it yesterday and i'm quite happy with how it works now. I've got many more verbs now (10 total, i believe officially there are only 24 synthetic verbs, some are regional and others are not very common) in the past and present tense, and i can easily add more by typing the conjugation data into the text file. Next i want to experiment with adding more test options, in particular being able to pick a particular group of verbs rather than only working on one verb at a time. My eventual goal is to turn it into an online study tool, but one step at a time!
chickendude wrote:
EDIT: I spent a few hours working on it yesterday and i'm quite happy with how it works now. I've got many more verbs now (10 total, i believe officially there are only 24 synthetic verbs, some are regional and others are not very common) in the past and present tense, and i can easily add more by typing the conjugation data into the text file. Next i want to experiment with adding more test options, in particular being able to pick a particular group of verbs rather than only working on one verb at a time. My eventual goal is to turn it into an online study tool, but one step at a time!
That sounds like an exciting goal! Do you have a plan on how you're going to design the next stage of the program, code-wise? I'm glad you were able to figure out the Python data structure issues that were delaying you.
I've got a general idea, but i haven't actually thought about it in depth yet. Since each verb is essentially a dictionary packed inside a list entry, i think i can pull the verbs out based on certain criteria. I've given each verb a type value, so i could for example pull all verbs of a certain type out and pass that on to the test routine. I've also been thinking of adding sentences for you to fill in, but i'll have to think how to organize that/how to connect the sentences to the verbs i've got now (or if i should separate the two completely).

I'm also still reading through tutorials online and other people's code as i go along, as i've always found higher level languages more complicated and less fun than assembly so my foundations are a bit shaky. I've heard Python is good for easily manipulating data which is exactly what i often need. So far it's been true and everything has been pretty straightforward. I've come across some weird stuff on Stack Exchange though, and lots of people talking about the "Python" way to do things, often accompanied by a "you're doing this completely wrong" comment, which is a bit discouraging, but at least i've already got something useful to me personally that's easy to maintain. So far it's been fun! My end goal is to make an interactive site for learning Basque.

add also showed me a project called Handmade Hero, a game/game programming tutorial written completely from scratch in C/C++ using no libraries at all, which is really appealing to my assembly mind. The guy's commentary is really interesting, too. Maybe someone's posted about it here on Cemetech, i'm not sure.

EDIT: Just added basic support to test yourself on groups of verbs. Right now it just builds a new verb list based on verb types, you just type the name (nor, nor-nori, nor-nori-nork, etc.) and it sends the list of verbs to the test function/method/whatever. In the future i might add support for handpicking the verbs/tenses you want to study, but only being able/knowing how to accept text input (at least for now) makes that a bit more awkward. It'd probably be easier to set up online once i get that far.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement