| 110 | See `dialog_counting` app for details. |
| 111 | Concepts for arithmetic operators and numbers are created. Not every number is defined, but rather decimal places and their combination, eg. |
| 112 | |
| 113 | {{{ |
| 114 | concept:(tens) [20 30 40 50 60 70 80 90] |
| 115 | concept:(number_hundreds) ["{[1 "jedno"]} sto" "dvě stě" "[3 4] sta" "[5 6 7 8 "osum" 9] set" dvěsta dvěstě pěcet šescet devěcet] |
| 116 | concept:(number) ["~number_hundreds {~number_tens} {~digits}" "~number_tens {~digits}" ~digits] |
| 117 | }}} |
| 118 | |
| 119 | This way, robot can understand numbers up to 999. Concepts are used in the dialogue, passed into counting function and output result is said in the dialogue: |
| 120 | |
| 121 | {{{ |
| 122 | u:(["kolik [je jsou]" spočítej spočti] _"~number ~operator [~number ~number2]") |
| 123 | $num_expression=$1 |
| 124 | ^call(ALDialogCounting.compute($num_expression)) |
| 125 | c1:(_* equals nan) $1 přece nejde spočítat! |
| 126 | c1:(_* equals _*) $1 [je "by mohlo být"] {asi} {tak} $2 |
| 127 | |
| 128 | }}} |
| 129 | |
| 130 | Computing function receive recognized words as parameters and have to convert the words to numbers before producing the result. `command` parameter contains recognized sentence, eg. "dvacet dva plus třináct". |
| 131 | |
| 132 | {{{ |
| 133 | m = re.match('(.*) (' + '|'.join(OPERATOR_WORDS) + ') (.*)', command) |
| 134 | if m: |
| 135 | number1 = self.convert_number(m.group(1)) |
| 136 | operator_word = m.group(2) |
| 137 | operator = OPERATOR_WORDS[operator_word] |
| 138 | number2 = self.convert_number(m.group(3)) |
| 139 | try: |
| 140 | result = str(int(eval(str(number1) + operator + str(number2)))).replace('-','minus') |
| 141 | except: |
| 142 | result = 'nan' |
| 143 | }}} |
| 144 | |