X-Git-Url: http://git.osdn.net/view?p=chnosproject%2FCHNOSProject.git;a=blobdiff_plain;f=CHNOSProject%2FAI003%2FAI003%2Fmain.c;fp=CHNOSProject%2FAI003%2FAI003%2Fmain.c;h=10775b5707454005ae0d9638dd25c543c33309f6;hp=7401c6c4a32a398383060602d7e8bf5c7ddcaa82;hb=8ee053a8fb8c7186e9b5a0c45a37e1e59f860821;hpb=a0956e5b600135d63ba7b003ddc1e21daac59082 diff --git a/CHNOSProject/AI003/AI003/main.c b/CHNOSProject/AI003/AI003/main.c index 7401c6c..10775b5 100755 --- a/CHNOSProject/AI003/AI003/main.c +++ b/CHNOSProject/AI003/AI003/main.c @@ -84,45 +84,51 @@ int main(int argc, const char * argv[]) CHNLIB_UIPArray *AI_Think_SlideLookUpWordByHistory(CHNLIB_String *input) { //入力文字列と履歴文字列を照らし合わせ、単語の候補を抜き出す。 + //候補単語は、新たに確保されたUIPArrayに格納され、そのArrayへのポインタを返す。 + //data32=入力文字列中に含まれる候補単語の数。 + //pointer=候補単語を示すCHNLIB_String. + //[UTF-8] CHNLIB_UIPArray *candidatewordlist; int i, i_max; int j, j_max; int k, k_max; + const char *cstr_input, *cstrp_input; + const char *cstr_history, *cstrp_history; int candidatelength, templength; - const char *cstr_input, *cstr_history; + int cstrp_input_length; candidatewordlist = CHNLIB_UIPArray_Initialize(); - i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.InputHistory); cstr_input = CHNLIB_String_GetReferencePointerOfCString(input); - k_max = CHNLIB_CString_GetLength(cstr_input); - + k_max = CHNLIB_UTF8_GetStringLengthByCharacter(cstr_input); + cstrp_input = cstr_input; + for(k = 0; k < k_max; k++){ - //**UTF-8 only - //UTF-8のマルチバイト部分でないことを確認 - if(CHNLIB_UTF8_GetCharacterType(cstr_input[k]) != 0){ - //**** - candidatelength = 0; - for(i = 0; i < i_max; i++){ - cstr_history = CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.InputHistory, i)); - j_max = CHNLIB_CString_GetLength(cstr_history); - for(j = 0; j < j_max; j++){ - templength = CHNLIB_CString_CompareString_LeftHand(&cstr_history[j], &cstr_input[k]); - if(templength > candidatelength && templength != (k_max - k)){ - //前方一致の長さが、 - //これまで見つかった単語よりも長く、かつ - //入力文字列の検索部分の全長ではない場合、 - //単語の候補とする。 - candidatelength = templength; - } + //input character loop + candidatelength = 0; + cstrp_input_length = CHNLIB_UTF8_GetStringLengthByCharacter(cstrp_input); + for(i = 0; i < i_max; i++){ + //history entry loop + cstr_history = CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.InputHistory, i)); + j_max = CHNLIB_UTF8_GetStringLengthByCharacter(cstr_history); + cstrp_history = cstr_history; + + for(j = 0; j < j_max; j++){ + //history character loop + templength = CHNLIB_UTF8_CompareString_LeftHand(cstrp_history, cstrp_input); + if(templength > candidatelength && templength != cstrp_input_length){ + //前方一致の長さが、これまで見つかった単語よりも長く、かつ入力文字列の検索部分の全長ではない場合、 + //単語の候補とする。 + candidatelength = templength; } + CHNLIB_UTF8_GetNextUnicodeOfCharacter(cstrp_history, &cstrp_history); } - if(candidatelength > 0){ - //AI_Memory_AddRootWordData(CHNLIB_String_ExtractByLength(input, k, candidatelength)); - CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&candidatewordlist, 0, CHNLIB_String_ExtractByLength(input, k, candidatelength), &AI_Memory_AddRootWordData_IsDuplicated); - } } + if(candidatelength > 0){ + CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&candidatewordlist, 0, CHNLIB_String_ExtractByLength(input, CHNLIB_UTF8_GetByteSizeFromLengthByCharacter(cstr_input, 0, k - 1), CHNLIB_UTF8_GetByteSizeFromLengthByCharacter(cstrp_input, 0, candidatelength - 1)), &AI_Memory_AddRootWordData_IsDuplicated); + } + CHNLIB_UTF8_GetNextUnicodeOfCharacter(cstrp_input, &cstrp_input); } //各候補単語が入力文字列にいくつ含まれているかをdata32に保存する。