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 stores for the basic components of math expressions: | 6 * @fileoverview Rule stores for the basic components of math expressions: |
7 * Unicode symbols and functions. | 7 * Unicode symbols and functions. |
8 * | 8 * |
9 * The idea of these stores is to provide a more efficient data structure to | 9 * The idea of these stores is to provide a more efficient data structure to |
10 * look up rules in the background page than the usual flat array of rules | 10 * look up rules in the background page than the usual flat array of rules |
(...skipping 16 matching lines...) Expand all Loading... |
27 goog.base(this); | 27 goog.base(this); |
28 }; | 28 }; |
29 goog.inherits(cvox.MathSimpleStore, cvox.MathStore); | 29 goog.inherits(cvox.MathSimpleStore, cvox.MathStore); |
30 | 30 |
31 | 31 |
32 /** | 32 /** |
33 * Turns a domain mapping from its JSON representation containing simple strings | 33 * Turns a domain mapping from its JSON representation containing simple strings |
34 * only into a list of speech rules. | 34 * only into a list of speech rules. |
35 * @param {string} name Name for the rules. | 35 * @param {string} name Name for the rules. |
36 * @param {string} str String for precondition and constraints. | 36 * @param {string} str String for precondition and constraints. |
37 * @param {Object.<string, Object.<string, string>>} mapping Simple string | 37 * @param {Object<string, Object<string, string>>} mapping Simple string |
38 * mapping. | 38 * mapping. |
39 */ | 39 */ |
40 cvox.MathSimpleStore.prototype.defineRulesFromMappings = function( | 40 cvox.MathSimpleStore.prototype.defineRulesFromMappings = function( |
41 name, str, mapping) { | 41 name, str, mapping) { |
42 for (var domain in mapping) { | 42 for (var domain in mapping) { |
43 for (var style in mapping[domain]) { | 43 for (var style in mapping[domain]) { |
44 var content = mapping[domain][style]; | 44 var content = mapping[domain][style]; |
45 var cstr = 'self::text() = "' + str + '"'; | 45 var cstr = 'self::text() = "' + str + '"'; |
46 var rule = this.defineRule( | 46 var rule = this.defineRule( |
47 name, domain + '.' + style, '[t] "' + content + '"', | 47 name, domain + '.' + style, '[t] "' + content + '"', |
48 'self::text()', cstr); | 48 'self::text()', cstr); |
49 } | 49 } |
50 } | 50 } |
51 }; | 51 }; |
52 | 52 |
53 | 53 |
54 /** | 54 /** |
55 * A compound store for simple Math objects. | 55 * A compound store for simple Math objects. |
56 * @constructor | 56 * @constructor |
57 */ | 57 */ |
58 cvox.MathCompoundStore = function() { | 58 cvox.MathCompoundStore = function() { |
59 /** | 59 /** |
60 * A set of efficient substores. | 60 * A set of efficient substores. |
61 * @type {Object.<string, cvox.MathStore>} | 61 * @type {Object<string, cvox.MathStore>} |
62 * @private | 62 * @private |
63 */ | 63 */ |
64 this.subStores_ = {}; | 64 this.subStores_ = {}; |
65 }; | 65 }; |
66 goog.addSingletonGetter(cvox.MathCompoundStore); | 66 goog.addSingletonGetter(cvox.MathCompoundStore); |
67 | 67 |
68 | 68 |
69 /** | 69 /** |
70 * Function creates a rule store in the compound store for a particular string, | 70 * Function creates a rule store in the compound store for a particular string, |
71 * and populates it with a set of rules. | 71 * and populates it with a set of rules. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 135 } |
136 return rule.action.components | 136 return rule.action.components |
137 .map(function(comp) { | 137 .map(function(comp) { |
138 return comp.content.slice(1, -1);}) | 138 return comp.content.slice(1, -1);}) |
139 .join(' '); | 139 .join(' '); |
140 }; | 140 }; |
141 | 141 |
142 | 142 |
143 /** | 143 /** |
144 * Get a set of all dynamic constraint values. | 144 * Get a set of all dynamic constraint values. |
145 * @return {!Object.<cvox.SpeechRule.DynamicCstrAttrib, Array.<string>>} The | 145 * @return {!Object<cvox.SpeechRule.DynamicCstrAttrib, Array<string>>} The |
146 * object with all annotations. | 146 * object with all annotations. |
147 */ | 147 */ |
148 cvox.MathCompoundStore.prototype.getDynamicConstraintValues = function() { | 148 cvox.MathCompoundStore.prototype.getDynamicConstraintValues = function() { |
149 var newCstr = {}; | 149 var newCstr = {}; |
150 for (var store in this.subStores_) { | 150 for (var store in this.subStores_) { |
151 var cstr = this.subStores_[store].getDynamicConstraintValues(); | 151 var cstr = this.subStores_[store].getDynamicConstraintValues(); |
152 for (var key in cstr) { | 152 for (var key in cstr) { |
153 var set = newCstr[key]; | 153 var set = newCstr[key]; |
154 if (set) { | 154 if (set) { |
155 newCstr[key] = cvox.MathUtil.union(set, cstr[key]); | 155 newCstr[key] = cvox.MathUtil.union(set, cstr[key]); |
(...skipping 16 matching lines...) Expand all Loading... |
172 cvox.MathSimpleStore.parseUnicode_ = function(number) { | 172 cvox.MathSimpleStore.parseUnicode_ = function(number) { |
173 var keyValue = parseInt(number, 16); | 173 var keyValue = parseInt(number, 16); |
174 if (keyValue < 0x10000) { | 174 if (keyValue < 0x10000) { |
175 return String.fromCharCode(keyValue); | 175 return String.fromCharCode(keyValue); |
176 } | 176 } |
177 keyValue -= 0x10000; | 177 keyValue -= 0x10000; |
178 var hiSurrogate = (keyValue >> 10) + 0xD800; | 178 var hiSurrogate = (keyValue >> 10) + 0xD800; |
179 var lowSurrogate = (keyValue & 0x3FF) + 0xDC00; | 179 var lowSurrogate = (keyValue & 0x3FF) + 0xDC00; |
180 return String.fromCharCode(hiSurrogate, lowSurrogate); | 180 return String.fromCharCode(hiSurrogate, lowSurrogate); |
181 }; | 181 }; |
OLD | NEW |