Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Pinto <dppintoroa@gmail.com>2013-01-25 21:40:05 (GMT)
committer Diego Pinto <dppintoroa@gmail.com>2013-01-25 21:40:05 (GMT)
commitebd32006ecfbdbbca5b62543070580310b95997b (patch)
tree1914df1abb8b4d4da1674606ee78615b18732c01
parent84d9ec1fe47f7b518015459a59423051b3e8b6f4 (diff)
parent4a35f8d15e25fcea54c499442bf34bf33ddb1992 (diff)
Merge branch 'master' of git.sugarlabs.org:elephant/elephant
-rwxr-xr-xEjemplo.py36
-rw-r--r--elephant.conf4
-rwxr-xr-xelephant.py85
3 files changed, 103 insertions, 22 deletions
diff --git a/Ejemplo.py b/Ejemplo.py
index b0b53b4..e4265b6 100755
--- a/Ejemplo.py
+++ b/Ejemplo.py
@@ -24,13 +24,39 @@ def main():
print 'Palabra aleatoria %s y el path correspndiente %s' %(word, path)
- choice_letter = elephant.letters()
+ choice_letter = elephant.letters(word)
- letter_to_say = 'Donde esta la letra '
- letter_to_say += choice_letter.get_letter(word)
- print letter_to_say
+ letter_to_say_index = choice_letter.letter_index
+ letter_to_say = choice_letter.letter
+
+ print 'Indice %s y letra %s' %(letter_to_say_index, letter_to_say)
+
+ all_indexes = choice_letter.get_all_indexes(word, letter_to_say)
+ print 'Todos los indices validos %s' %all_indexes
+
+ false_choices = choice_letter.get_false_options(word, all_indexes)
+ print 'Opciones invalidas %s. No tienen que coincidir con los validos' \
+ %false_choices
+
+ relative_place = choice_letter.get_relative_place( \
+ letter_to_say_index, \
+ all_indexes)
+ print 'Lugar relativo %s' %relative_place
+
+ place_word = choice_letter.translate_relative_place(relative_place)
+ print 'Lugar relativo %s' %place_word
+
+ speech_to_say = 'Donde esta la '
+ if relative_place == False:
+ speech_to_say += ''
+ else:
+ speech_to_say += place_word
+ speech_to_say += ' letra '
+ speech_to_say += letter_to_say
+
+ print speech_to_say
- say(letter_to_say)
+ say(speech_to_say)
def say(text):
Popen(['espeak', '-v', 'es', text])
diff --git a/elephant.conf b/elephant.conf
index 4cd67da..e3fa26e 100644
--- a/elephant.conf
+++ b/elephant.conf
@@ -1,7 +1,5 @@
[Main]
-icon = images/elefante_icon.png
-logo = images/elefante_logo.png
-
+Falseoptions = 2
[Categories]
cat01 = animals
diff --git a/elephant.py b/elephant.py
index 5f680e7..fc22814 100755
--- a/elephant.py
+++ b/elephant.py
@@ -1,16 +1,13 @@
-#!/usr/bin/python
-
import ConfigParser
-
-from random import choice
+import random
# Global definition
CONF_FILE='elephant.conf'
CAT_SECTION='Categories'
WORDS_SECTION='Words'
+MAIN_SECTION='Main'
-# Class
-# Return the word list from config file and numbers of word
+# Class word_list
class word_list:
def __init__(self):
@@ -55,20 +52,80 @@ class word_list:
return image_path
+# Class letters
class letters:
- def __init__(self):
- pass
+ def __init__(self, word):
+ self.letter_index, self.letter = self._get_letter_index(word)
- def get_letter(self, word):
- letter = choice (word)
+ # Return a random letter for a given word and index
+ def _get_letter_index(self, word):
- return letter
+ word_len = len(word)
+ # Generate a random index of a letter in the word
+ letter_index = random.randint(0, word_len - 1)
+
+ # Get the letter at position letter_index
+ letter = word[letter_index]
-
+ return letter_index+1, letter
-
+ # Return list of indexes for every ocurrence ot the letter in the word.
+ def get_all_indexes(self, word, letter):
+
+ # Init vars
+ word_len = len(word)
+ indexes = []
+ i = 0
+
+ # Generates a list with indexes of ocurrences of the letter
+ for i in range(word_len):
+ if word[i] == letter:
+ indexes.append(i+1)
+ i+=1
+
+ return indexes
+
+ # Return false options non-overlaping with true options
+ def get_false_options(self, word, true_indexes):
+ word_len = len(word)
+
+ #parser = ConfigParser.SafeConfigParser()
+ #parser.read(CONF_FILE)
+
+ #false_options = parser.get(MAIN_SECTION, 'Falseoptions')
+
+ false_choices = []
+ for i in [1, 2]:
+ false_choice = random.randrange(word_len)
+ if (false_choice in true_indexes) == True:
+ pass
+ else:
+ false_choices.append(false_choice)
+ i += 1
+
+ return false_choices
+
+ # Return the relative place of a letter in case there are multiples
+ # ocurrences of the letter. False in case there are only one.
+ def get_relative_place(self, letter_index, true_indexes):
+
+ if len(true_indexes) == 1:
+ return False
+
+ relative_place = true_indexes.index(letter_index)
+
+ return relative_place+1
+
+
+ # Translate relative place to words
+ def translate_relative_place(self, relative_place):
+
+ if relative_place == False:
+ return False
+ relative_place -= 1
+ places = ['Primera', 'Segunda', 'Tercera', 'Cuarta', 'Quinta', 'Sexta']
- \ No newline at end of file
+ return places[relative_place] \ No newline at end of file