|
@@ -11,8 +11,8 @@ import logging
|
|
|
# user_said = "maman je voudrais ecouter ACDC"
|
|
|
# order = "je voudrais ecouter {{ artist_name }}"
|
|
|
|
|
|
-user_said = "s'il te plait regle le reveil pour sept heures et dix minutes"
|
|
|
-order = "regle le reveil pour {{ hour }} heures et {{ minute }} minutes"
|
|
|
+user_said = "s'il te plait regle le reveil pour dix huit heures et dix neuf minutes trente trois secondes cent quatre vingt dix "
|
|
|
+order = "regle le reveil pour {{ hour}} heures et {{minute }} minutes {{ seconde }} secondes {{mili}}"
|
|
|
|
|
|
|
|
|
# take a look to each order
|
|
@@ -28,11 +28,16 @@ def _is_containing_bracket(sentence):
|
|
|
return False
|
|
|
|
|
|
|
|
|
+def _get_next_value_list(list):
|
|
|
+ ite = list.__iter__()
|
|
|
+ next(ite, None)
|
|
|
+ return next(ite, None)
|
|
|
+
|
|
|
# check if the order contain bracket
|
|
|
if _is_containing_bracket(order):
|
|
|
# remove white space between {{ and }}
|
|
|
# get a table of word said
|
|
|
- list_word_in_order = order.replace("{{ ","{{").replace(" }}", "}}").split()
|
|
|
+ list_word_in_order = re.sub('\s+(?=[^\{\{\}\}]*\}\})', '',order).split()
|
|
|
print "order matched: %s" % list_word_in_order
|
|
|
|
|
|
# get the order, defined by the first words before {{
|
|
@@ -51,20 +56,23 @@ if _is_containing_bracket(order):
|
|
|
for idx, ow in enumerate(list_word_in_order):
|
|
|
if _is_containing_bracket(ow):
|
|
|
# remove bracket et key dict
|
|
|
- oo = ow.replace("{{","").replace("}}", "")
|
|
|
- dictVar[oo] = truncate_list_word_said[idx]
|
|
|
-
|
|
|
+ varname = ow.replace("{{","").replace("}}", "")
|
|
|
+ stopValue = _get_next_value_list(list_word_in_order[idx:])
|
|
|
+ if stopValue is None:
|
|
|
+ dictVar[varname] = " ".join(truncate_list_word_said)
|
|
|
+ break
|
|
|
+ for word_said in truncate_list_word_said:
|
|
|
+ if word_said == stopValue: break
|
|
|
+ if varname in dictVar:
|
|
|
+ dictVar[varname] += " " + word_said
|
|
|
+ truncate_list_word_said = truncate_list_word_said[1:]
|
|
|
+ else:
|
|
|
+ dictVar[varname] = word_said
|
|
|
+ truncate_list_word_said = truncate_list_word_said[1:]
|
|
|
print "The dict Var : %s" % dictVar
|
|
|
|
|
|
|
|
|
|
|
|
-# return the beginning of the sentence before first bracket
|
|
|
-# return
|
|
|
-
|
|
|
-# split each word
|
|
|
-#
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|