1 function AI_WordRecognition(env){
4 AI_WordRecognition.prototype = {
5 slideLookUpCandidateWordByHistory: function(input){
6 var h = this.env.input.historyList;
7 var cList = new Array();
8 for(var i = 0, iLen = input.length; i < iLen; i++){
10 var iStr = input.substr(i);
13 for(var j = 0, jLen = h.length; j < jLen; j++){
16 for(var k = 0, kLen = hStrBase.length; k < kLen; k++){
17 //history character loop
18 var hStr = hStrBase.substr(k);
19 var m = hStr.compareLeftHand(iStr);
20 if(m > cLen && m != iStr.length){
26 cList.pushUnique(new AI_CandidateWordTag(iStr.substr(0, cLen))).wordCount++;
30 this.filterCandidateWordList00(cList);
31 this.filterCandidateWordList01(cList, 2);
33 this.mergeCandidateWordList(cList);
35 appendCandidateWordList: function(strTag){
36 var s = this.env.memory.candidateWordList.isIncluded(strTag, function(a, b){ return (a.str == b.str); });
41 this.env.memory.appendMemoryTag(strTag);
44 mergeCandidateWordList: function(strTagList){
45 for(var i = 0, iLen = strTagList.length; i < iLen; i++){
46 this.appendCandidateWordList(strTagList[i]);
49 debugShowCandidateWordList: function(){
50 this.env.debug("candidateWordList:\n");
51 var c = this.env.memory.candidateWordList;
52 for(var i = 0, iLen = c.length; i < iLen; i++){
53 this.env.debug(c[i].wordCount.toString() + " :" + c[i].wordLevel.toString() + " :" + c[i].str + "\n");
55 this.env.debug("candidateWordList end\n");
57 filterCandidateWordList00:function(cList){
58 //00:長い単語に含まれており、かつ出現頻度が長い単語と等しい単語を削除
59 //cList内の候補単語に対して、フィルターをかける。
60 var iLen = cList.length;
64 var baseStrTag = cList[0];
65 for(var i = 1; i < iLen; i++){
67 if(baseStrTag.str.indexOf(c.str) != -1){
68 //c.strはbaseStrTag.strに含まれている
69 if(baseStrTag.wordCount == c.wordCount){
71 //後で削除する。出現回数を0にマークする。
76 //単語は削除されなかった、つまり異なる単語なので、baseStrTagを更新
81 for(var i = 1; i < iLen; i++){
84 cList.removeByIndex(i);
90 filterCandidateWordList01:function(cList, minLen){
91 //01:minLenに満たない文字数の候補を削除
93 var iLen = cList.length;
94 for(var i = 0; i < iLen; i++){
95 if(cList[i].str.length < minLen){
96 cList.removeByIndex(i);
102 filterCandidateWordList02:function(cList, minCount){
103 //02:minCountに満たない出現回数の候補を削除
105 var iLen = cList.length;
106 for(var i = 0; i < iLen; i++){
107 if(cList[i].wordCount < minCount){
108 cList.removeByIndex(i);
114 sortCandidateWordListByWordCount: function(){
115 this.env.memory.candidateWordList.stableSort(function(a, b){
116 return a.wordCount - b.wordCount;
119 sortCandidateWordListByWordLevel: function(){
120 this.env.memory.candidateWordList.stableSort(function(a, b){
121 return a.wordLevel - b.wordLevel;
124 computeWordLevel: function(strTag){
128 strTag.wordLevel = 0;
130 for(var i = 0; i < iLen; i++){
131 if(s.isHiraganaAt(i)){
133 } else if(s.isKanjiAt(i)){
135 } else if(s.isKatakanaAt(i)){
137 } else if(s.isHankakuKanaAt(i)){
143 for(var i = 0; i < 5; i++){
149 strTag.wordLevel = 1 / strTag.wordLevel;
152 computeEachWordLevel: function(){
153 var iLen = this.env.memory.candidateWordList.length;
154 for(var i = 0; i < iLen; i++){
155 this.computeWordLevel(this.env.memory.candidateWordList[i]);