[Tutor] language aid (various)

Eike Welk eike.welk at gmx.net
Sat Feb 6 13:10:25 CET 2010


On Friday February 5 2010 12:29:30 Owain Clarke wrote:
> What a helpful forum - much thanks to all who've commented.  Seems to be
> a bit of a consensus here about dictionaries.  Let me just restate my
> reluctance, using examples from Spanish.
> 
> esperar = to hope
> esperar = to wait

You could have a dict that maps: word -> list of translations
d = {"esperar":["to hope", "to wait"]}

> tambien = too [i.e. also]
> demasiado = too [i.e. excessive]

> 
> So there are repeats in both languages.  I would like to end up with a
> file which I can use to generate flash cards, either to or from English,
> and I suppose I want the flexibility to have 1 word with 1 definition.

You should possibly have an object for each term:

class LangEntity(object):
	def __init__(self, word_en, word_es, 
                 definition_en=None, definition_es=None, image=None):
		self.word_en = word_en
		self.word_es = word_es
		self.definition_en = definition_en
		self.definition_es = definition_es
		self.image = image

	#TODO: def __repr__(self) so you can see what you are doing.

all_entities = [LangEntity("too", "tambien"), 
                LangEntity("to hope", "esperar")]


Then you can create dictionaries that map from the words to the LangEntity 
objects:

def make_en_dict(all_ents):
	res_dict = {}
	for ent in all_ents:
		key = ent.word_en
		ent_list = res_dict.get(key, [])
		ent_list.append(ent)
		res_dict[key] = ent_list
	return res_dict

en_dict = make_en_dict(all_entities)


WARNING: I didn't try the code, I just typed it into the mail client! So there 
might be bugs!

For useful ways how to model terms of a dictionary, maybe look at these 
projects, and talk to their developers.
http://edu.kde.org/parley/
http://www.voxhumanitatis.org/content/ambaradan-owm2-storage-engine
http://www.omegawiki.org/Meta:Main_Page


Eike.


More information about the Tutor mailing list