OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Rule store for math syntax tree nodes. | 6 * @fileoverview Rule store for math syntax tree nodes. |
7 */ | 7 */ |
8 | 8 |
9 goog.provide('cvox.MathStore'); | 9 goog.provide('cvox.MathStore'); |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 this.addAlias_(rule, query, cstrList); | 152 this.addAlias_(rule, query, cstrList); |
153 }, | 153 }, |
154 this)); | 154 this)); |
155 }; | 155 }; |
156 | 156 |
157 | 157 |
158 /** | 158 /** |
159 * Adds a new speech rule as alias of the given rule. | 159 * Adds a new speech rule as alias of the given rule. |
160 * @param {cvox.SpeechRule} rule The existing rule. | 160 * @param {cvox.SpeechRule} rule The existing rule. |
161 * @param {string} query Precondition query of the rule. | 161 * @param {string} query Precondition query of the rule. |
162 * @param {Array.<string>} cstrList List of additional constraints. | 162 * @param {Array<string>} cstrList List of additional constraints. |
163 * @private | 163 * @private |
164 */ | 164 */ |
165 cvox.MathStore.prototype.addAlias_ = function(rule, query, cstrList) { | 165 cvox.MathStore.prototype.addAlias_ = function(rule, query, cstrList) { |
166 var prec = new cvox.SpeechRule.Precondition(query, cstrList); | 166 var prec = new cvox.SpeechRule.Precondition(query, cstrList); |
167 var newRule = new cvox.SpeechRule( | 167 var newRule = new cvox.SpeechRule( |
168 rule.name, rule.dynamicCstr, prec, rule.action); | 168 rule.name, rule.dynamicCstr, prec, rule.action); |
169 newRule.name = rule.name; | 169 newRule.name = rule.name; |
170 this.addRule(newRule); | 170 this.addRule(newRule); |
171 }; | 171 }; |
172 | 172 |
173 | 173 |
174 // Evaluator | 174 // Evaluator |
175 /** | 175 /** |
176 * @override | 176 * @override |
177 */ | 177 */ |
178 cvox.MathStore.prototype.evaluateDefault = function(node) { | 178 cvox.MathStore.prototype.evaluateDefault = function(node) { |
179 return this.evaluateString_(node.textContent); | 179 return this.evaluateString_(node.textContent); |
180 }; | 180 }; |
181 | 181 |
182 | 182 |
183 /** | 183 /** |
184 * Evaluates a single string of a math expressions. The method splits the given | 184 * Evaluates a single string of a math expressions. The method splits the given |
185 * string into components such as single characters, function names or words, | 185 * string into components such as single characters, function names or words, |
186 * numbers, etc. and creates the appropriate navigation descriptions. | 186 * numbers, etc. and creates the appropriate navigation descriptions. |
187 * @param {string} str A string. | 187 * @param {string} str A string. |
188 * @return {!Array.<cvox.NavDescription>} Messages for the math expression. | 188 * @return {!Array<cvox.NavDescription>} Messages for the math expression. |
189 * @private | 189 * @private |
190 */ | 190 */ |
191 cvox.MathStore.prototype.evaluateString_ = function(str) { | 191 cvox.MathStore.prototype.evaluateString_ = function(str) { |
192 var descs = new Array(); | 192 var descs = new Array(); |
193 if (str.match(/^\s+$/)) { | 193 if (str.match(/^\s+$/)) { |
194 // Nothing but whitespace: Ignore. | 194 // Nothing but whitespace: Ignore. |
195 return descs; | 195 return descs; |
196 } | 196 } |
197 var split = cvox.MathStore.removeEmpty_(str.replace(/\s/g, ' ').split(' ')); | 197 var split = cvox.MathStore.removeEmpty_(str.replace(/\s/g, ' ').split(' ')); |
198 for (var i = 0, s; s = split[i]; i++) { | 198 for (var i = 0, s; s = split[i]; i++) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 return new cvox.NavMathDescription( | 252 return new cvox.NavMathDescription( |
253 {'text': text, | 253 {'text': text, |
254 'domain': cvox.TraverseMath.getInstance().domain, | 254 'domain': cvox.TraverseMath.getInstance().domain, |
255 'style': cvox.TraverseMath.getInstance().style | 255 'style': cvox.TraverseMath.getInstance().style |
256 }); | 256 }); |
257 }; | 257 }; |
258 | 258 |
259 | 259 |
260 /** | 260 /** |
261 * Removes all empty strings from an array of strings. | 261 * Removes all empty strings from an array of strings. |
262 * @param {Array.<string>} strs An array of strings. | 262 * @param {Array<string>} strs An array of strings. |
263 * @return {Array.<string>} The cleaned array. | 263 * @return {Array<string>} The cleaned array. |
264 * @private | 264 * @private |
265 */ | 265 */ |
266 cvox.MathStore.removeEmpty_ = function(strs) { | 266 cvox.MathStore.removeEmpty_ = function(strs) { |
267 return strs.filter(function(str) {return str;}); | 267 return strs.filter(function(str) {return str;}); |
268 }; | 268 }; |
OLD | NEW |