2 * Copyright 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * This source code is a language specified script for Chinese(zh_TW).
24 * vc_search_word function found the text with similarity calculated using words in the @param.
26 * @param param param from voice-control.
27 * @param replace If replace true, function correct some confused charaters and try again.
29 function vc_search_word(param, replace) {
30 /* phase 2. search partial word in the webpage */
31 /* First, compare with links in html documents */
32 if (vc_flag_log == true) {
33 vc_rec_result.style.background = 'rgba(0, 100, 200, 1)';
35 var resultTokenArr = param.replace(/ /gi, '');
36 var threshold = resultTokenArr.length * 0.6;
40 vc_print_log('=== start vc_search_word');
42 for (var i = 0; i < vc_text_indicators.length; ++i) {
43 var text = vc_text_indicators[i].textContent.replace(/[ `~!‘’@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '').toLowerCase();
46 for (var j = 0; j < resultTokenArr.length; j++) {
47 if (vc_is_visible(vc_text_indicators[i], vc_scr, true) && text.indexOf(resultTokenArr[j].toLowerCase()) != -1) {
55 for (var i = 0; i < vc_text_indicators.length; i++) {
56 if (temp[i] >= threshold && (max == -1 || temp[i] > temp[max])) {
57 el = vc_text_indicators[i];
62 if (el != undefined) {
66 /* Second, compare with whole text of elements in html documents */
68 for (var i = 0; i < resultTokenArr.length; i++) {
69 var obj = vc_selector([resultTokenArr[i]]);
70 for (var j = 0; j < obj.length; j++) {
72 if (temp.childElementCount === 0) {
73 if (temp.hasAttribute('vc_count') == false) {
74 temp.setAttribute('vc_count', 1);
77 temp.setAttribute('vc_count', parseInt(temp.getAttribute('vc_count')) + 1);
83 for (var i = 0; i < result.length; i++) {
84 var vccnt = parseInt(result[i].getAttribute('vc_count'));
85 if (vccnt >= threshold && (el == undefined || vccnt > parseInt(el.getAttribute('vc_count')))) {
90 for (var i = 0; i < result.length; i++) {
91 result[i].removeAttribute('vc_count');
98 * vc_search_word function found the text with similarity calculated using characters in the @param.
100 * @param param param from voice-control.
102 function vc_search_character(param) {
105 /* TODO: Fill the logic here to find the link or text include the character keys in param.
106 * If you find the link or text, then allocate that into el.
107 * If the language does not need to pronunciation comapring, you can erase this function.
114 * vc_search_word function found the text with similarity calculated using pronunciation keys in the @param.
116 * @param param param from voice-control.
118 function vc_search_pronunciation(param) {
121 /* TODO: Fill the logic here to find the link or text include the pronunciation keys in param.
122 * If you find the link or text, then allocate that into el.
123 * If the language does not need to pronunciation comapring, you can erase this function.
130 * vc_is_included_number function separate a number value from the @text.
132 * @param text text string from voice-control-webview.cpp.
134 function vc_is_included_number(text) {
135 var numbers = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十',
136 '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十',
137 '二十一', '二十二', '二十三', '二十四', '二十五', '二十六', '二十七', '二十八', '二十九', '三十',
138 '三十一', '三十二', '三十三', '三十四', '三十五', '三十六', '三十七', '三十八', '三十九', '四十',
139 '四十一', '四十二', '四十三', '四十四', '四十五', '四十六', '四十七', '四十八', '四十九', '五十',
140 '五十一', '五十二', '五十三', '五十四', '五十五', '五十六', '五十七', '五十八', '五十九', '六十',
141 '六十一', '六十二', '六十三', '六十四', '六十五', '六十六', '六十七', '六十八', '六十九', '七十',
142 '七十一', '七十二', '七十三', '七十四', '七十五', '七十六', '七十七', '七十八', '七十九', '八十',
143 '八十一', '八十二', '八十三', '八十四', '八十五', '八十六', '八十七', '八十八', '八十九', '九十',
144 '九十一', '九十二', '九十三', '九十四', '九十五', '九十六', '九十七', '九十八', '九十九', '百'];
145 var convert = text.toLowerCase();
148 for (var i = 0; numbers.length > i; i++) {
149 if (true == convert.startsWith(numbers[i]) && (' ' == text[numbers[i].length] || text.length == numbers[i].length)) {
150 var partial = text.substr(numbers[i].length);
152 if (vc_visible_hints[i].type == 'input' || text.length == numbers[i].length) {
155 param : partial.trim()
171 * vc_correct_parameter function correct the voice recognition result.
173 * @param text text string from voice-control-webview.cpp.
175 function vc_correct_parameter(text) {
176 var result = vc_is_included_number(text),
177 words = result.param.split(' ');
179 if (isNaN(result.cmd) == true && isNaN(words[0]) == false) {
180 result.cmd = parseFloat(words[0]);
181 result.param = result.param.substr(words[0].length + 1).trim();
188 * vc_check_web_control function check some special keyword and run it.
190 * @param spokenWord voice recognized result string.
192 function vc_check_web_control(text) {
193 text = text.toLowerCase();
194 var convert = text.replace(/ /g, '');
196 if (convert == '刷新' || convert == '重新加载') {
198 } else if (convert == '向下滚动' || convert == '向下滾動') {
199 vc_scroll_event_firing('DOWN');
200 } else if (convert == '向上滚动' || convert == '向上滾動') {
201 vc_scroll_event_firing('UP');
202 } else if (convert == '去顶部' || convert == '去頂部') {
203 vc_scroll_event_firing('TOP');
204 } else if (convert == '源代碼' || convert == '源代码') {
206 } else if (convert == '下一个' || convert == '下一個' || convert == '向前' || convert == '前进' || convert == '前進') {
208 } else if (convert == '背部' || convert == '背部' || convert == '前' || convert == '以前') {
210 } else if ((convert == '记录' || convert == '記錄') && vc_flag_log) {
211 if (vc_log_area.style.visibility == 'visible') vc_log_area.style.visibility = 'hidden';
212 else vc_log_area.style.visibility = 'visible';