Skip to content

Commit

Permalink
fix(decoder): 最大拼音长度为6
Browse files Browse the repository at this point in the history
  • Loading branch information
zzl221000 committed Jan 1, 2023
1 parent 727e0cf commit 8dba8a0
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 4 deletions.
Binary file added shuangpin-chromeos.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ime/decoder/tokendecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ goog.ime.offline.TokenDecoder.prototype.inSameRange_ = function(start, end) {
*/
goog.ime.offline.TokenDecoder.prototype.getSuffixTokens_ = function(source) {
var ret = [];
for (var i = 1; i <= 5 && i <= source.length; ++i) {
for (var i = 1; i <= 6 && i <= source.length; ++i) {
var suffix = this.currentStr_.slice(-i);
if (suffix.match(this.tokenReg_)) {
ret.push(suffix);
Expand Down
29 changes: 29 additions & 0 deletions test/background_deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions test/data.js

Large diffs are not rendered by default.

200 changes: 200 additions & 0 deletions test/dataloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// Copyright 2013 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//

/**
* @fileoverview goog.ime.offline.DataLoader is implemented to load required
* data in offline transliterator.
*/
goog.provide('goog.ime.offline.DataLoader');

goog.require('goog.Disposable');
goog.require('goog.ime.offline.InputToolCode');



/**
* goog.ime.offline.DataLoader provides the functions to load token
* dictionary, generation model and dictionary for the offline transliterator.
*
* @param {string} inputTool The input tool code.
* @constructor
* @extends {goog.Disposable}
*/
goog.ime.offline.DataLoader = function(inputTool) {
/**
* The current input tool.
* @type {string}
*/
this.inputTool = inputTool;

/**
* The source map for the model data.
*
* @type {Object}
*/
this.sourceMap;

/**
* The target map for the model data.
*
* @type {Array}
*/
this.targetMap;

/**
* The number used to normalize probabilities.
*
* @type {Object}
*/
this.defaultProb;

/**
* The encoded source segments.
*
* @type {Array}
*/
this.sourceSegments;

/**
* The encoded target segments.
*
* @type {Array}
*/
this.targetSegments;

/**
* The probabilities for target segments. The scores for the corresponding
* target segemnts in this.targetSegments.
*
* @type {Array.<*>}
*/
this.targetProbs;

/**
* The offsets of the first target segment for all source segments.
*
* @type {Array.<*>}
*/
this.targetPositions;

/**
* The full tokens for the decoder, separated by '|'.
*
* @type {string}
*/
this.tokens;

/**
* The tokens without tones, separated by '|'.
*
* @type {string}
*/
this.untoneTokens;

/**
* The initial tones, separated by '|'.
*
* @type {string}
*/
this.initialTokens = '';

/**
* Whether the data is ready now.
*
* @type {boolean}
*/
this.dataReady = false;
};
goog.inherits(goog.ime.offline.DataLoader, goog.Disposable);


/**
* The variables from the model data.
*
* @enum {string}
*/
goog.ime.offline.DataLoader.PARAMS = {
INPUT_TOOL: 'chosInputTool',
SOURCE_MAP: 'sourceMap',
TARGET_MAP: 'targetMap',
DEFAULT_PROB: 'defaultProb',
SOURCE_SEGS: 'sourceSegments',
TARGET_SEGS: 'targetSegments',
SOURCE_PROS: 'sourceProbs',
TARGET_PROS: 'targetProbs',
TARGET_POS: 'targetPositions',
TOKENS: 'chosTokens'
};
const { chosInputTool,
sourceMap,
targetMap,
defaultProb,
sourceSegments,
targetSegments,
targetProbs,
targetPositions,
chosTokens,}=require('./data')

/**
* Loads the model data.
*
* @param {Function} callBackFn The function to call when the data is loaded.
*/
goog.ime.offline.DataLoader.prototype.loadModelData = function(callBackFn) {
if (this.dataReady) {
callBackFn();
return;
}

if (chosInputTool=== this.inputTool) {
this.loadModelDataInternal_();
this.dataReady = true;
callBackFn();
return;
}
};


/**
* Loads the model data internal.
*
* @private
*/
goog.ime.offline.DataLoader.prototype.loadModelDataInternal_ = function() {
this.sourceMap = sourceMap;
this.targetMap = targetMap;
this.defaultProb = defaultProb;
this.tokens = chosTokens;

this.sourceSegments = sourceSegments;
this.targetSegments = targetSegments;
this.targetProbs = targetProbs;
this.targetPositions = targetPositions;

this.buildTokens_();
this.dataReady = true;
};


/**
* Builds the untone tokens and initial tokens.
*
* @private
*/
goog.ime.offline.DataLoader.prototype.buildTokens_ = function() {
const code = goog.ime.offline.InputToolCode;
if (this.inputTool === code.INPUTMETHOD_PINYIN_CHINESE_SIMPLIFIED ) {
this.initialTokens = 'b|p|m|f|d|t|n|l|k|g|h|j|q|x|zh|ch|sh|r|z|c|s|y|w';
}
};
2 changes: 2 additions & 0 deletions test/js_lang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let i=0
console.log(i=1)
2 changes: 1 addition & 1 deletion test/shuangpin/flypy.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,4 @@ const FLYPY = {
for(const k in FLYPY){
this[k]=FLYPY[k]
}
console.log(FLYPY.parse('hv'));
console.log(FLYPY.parse('ul'));
7 changes: 5 additions & 2 deletions test/test_model.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8dba8a0

Please sign in to comment.