function AI_WordRecognition(env){
this.env = env;
+ this.wordListCache = null;
+ this.wordListCacheLastModifiedDate = new Date();
}
AI_WordRecognition.prototype = {
slideLookUpCandidateWordByHistory: function(input){
}
}
if(cLen > 0){
- cList.pushUnique(new AI_CandidateWordTag(iStr.substr(0, cLen))).wordCount++;
+ cList.pushUnique(new AI_CandidateWordTag(iStr.substr(0, cLen).trim())).wordCount++;
}
}
//フィルター
this.filterCandidateWordList00(cList);
this.filterCandidateWordList01(cList, 2);
+ this.filterCandidateWordList03(cList);
//追加
this.mergeCandidateWordList(cList);
+
},
appendCandidateWordList: function(strTag){
var s = this.env.memory.candidateWordList.isIncluded(strTag, function(a, b){ return (a.str == b.str); });
this.env.memory.appendMemoryTag(strTag);
}
},
+ getCandidateWordTagByString: function(str){
+ return this.env.memory.candidateWordList.isIncluded(str, function(a, b){ return (a.str == b); });
+ },
mergeCandidateWordList: function(strTagList){
for(var i = 0, iLen = strTagList.length; i < iLen; i++){
this.appendCandidateWordList(strTagList[i]);
}
},
+ cleanCandidateWordList: function(){
+ //不要な候補単語を削除
+ //出現回数の少ない候補単語
+ //単語度が1未満の単語(暫定)
+ var iLen = this.env.memory.candidateWordList.length;
+ for(var i = 0; i < iLen; i++){
+ if(this.env.memory.candidateWordList[i].wordCount < 10){
+ this.env.debug("Too small wordCount of candidateWord [" + this.env.memory.candidateWordList[i].str + "]. Removed.\n");
+ this.env.memory.removeMemoryTagByObject(this.env.memory.candidateWordList[i]);
+ i--;
+ iLen--;
+ continue;
+ }
+ if(this.env.memory.candidateWordList[i].wordLevel < 1){
+ this.env.debug("Too small wordLevel of candidateWord [" + this.env.memory.candidateWordList[i].str + "]. Removed.\n");
+ this.env.memory.removeMemoryTagByObject(this.env.memory.candidateWordList[i]);
+ i--;
+ iLen--;
+ continue;
+ }
+ }
+ this.env.memory.candidateWordListLastCleanedDate = new Date();
+ },
debugShowCandidateWordList: function(){
- this.env.debug("candidateWordList:\n");
- var c = this.env.memory.candidateWordList;
+ var c = this.env.memory.candidateWordList.copy();
+ c.reverse();
+ this.env.debug("candidateWordList:" + c.length + "\n #:wCount:level:str\n");
+
for(var i = 0, iLen = c.length; i < iLen; i++){
- this.env.debug(c[i].wordCount.toString() + " :" + c[i].wordLevel.toString() + " :" + c[i].str + "\n");
+ this.env.debug((i + 1) + ":\t" + c[i].wordCount.toString() + ":\t" + c[i].wordLevel.toString() + ":\t" + c[i].str + "\n");
}
this.env.debug("candidateWordList end\n");
},
},
filterCandidateWordList01:function(cList, minLen){
//01:minLenに満たない文字数の候補を削除
- //削除処理
var iLen = cList.length;
for(var i = 0; i < iLen; i++){
if(cList[i].str.length < minLen){
},
filterCandidateWordList02:function(cList, minCount){
//02:minCountに満たない出現回数の候補を削除
- //削除処理
var iLen = cList.length;
for(var i = 0; i < iLen; i++){
if(cList[i].wordCount < minCount){
}
}
},
+ filterCandidateWordList03: function(cList){
+ //03:すでに単語と判明している候補を削除
+ var iLen = cList.length;
+ for(var i = 0; i < iLen; i++){
+ if(this.env.memory.getUUIDFromWord(cList[i].str) != this.env.UUID_Meaning_UndefinedString){
+ cList.removeByIndex(i);
+ i--;
+ iLen--;
+ }
+ }
+ },
sortCandidateWordListByWordCount: function(){
this.env.memory.candidateWordList.stableSort(function(a, b){
return a.wordCount - b.wordCount;
return a.wordLevel - b.wordLevel;
});
},
+ sortWordListByLength: function(){
+ //文字数の大きい方がリストの最初に来るようにする。
+ this.env.memory.wordList.stableSort(function(a, b){
+ return b.str.length - a.str.length;
+ });
+ },
computeWordLevel: function(strTag){
var s = strTag.str;
var iLen = s.length;
for(var i = 0; i < iLen; i++){
this.computeWordLevel(this.env.memory.candidateWordList[i]);
}
- }
+ },
+ splitByWord: function(s){
+ if(!this.wordListCache || this.wordListCacheLastModifiedDate < this.env.memory.wordListLastModifiedDate){
+ //キャッシュが存在しないか古い場合、元のリストをソートしてからキャッシュを作成
+ this.sortWordListByLength();
+ this.wordListCache = this.env.memory.wordList.propertiesNamed("str");
+ this.wordListCacheLastModifiedDate = new Date();
+ }
+ return s.splitByArraySeparatorSeparatedLong(this.wordListCache);
+ },
+ getUUIDListFromSeparatedString: function(separated){
+ var retv = new Array();
+ for(var i = 0, iLen = separated.length; i < iLen; i++){
+ retv.push(this.env.memory.getUUIDFromWord(separated[i]));
+ }
+ return retv;
+ },
}