OSDN Git Service

modified: src/padarea.c
[kp123/kp123.git] / src / recognize_kanji.c
index 8579f1d..d9c27bf 100644 (file)
@@ -139,7 +139,7 @@ static gunichar2* find_next_entry(gchar *allkanji, gunichar2 *entry, gint allkan
 
 static gunichar2* pick_kanji(GList *strokes, gchar **sdata, gchar *allkanji, gint allkanjilen)
 {
-    const gint MAX_DISTANCE = g_list_length(strokes) - 1;
+    const gint MAX_COUNT = 25;
     gint datalen = g_strv_length(sdata), i;
     gunichar2 key = 'A' + datalen - 1;
     gunichar2 *entry = (gunichar2*)allkanji;
@@ -155,18 +155,23 @@ static gunichar2* pick_kanji(GList *strokes, gchar **sdata, gchar *allkanji, gin
     {
        kanji_result *res = rate_next_kanji(strokes, sdata, entry);
        g_ptr_array_add(arr, res);
-       g_ptr_array_sort(arr, (GCompareFunc)kanji_results_compare);
-       for(i = arr->len - 1; i >= 0; i--)
+       entry = find_next_entry(allkanji, entry, allkanjilen, key);
+       if(!entry)
+           break;
+    }
+    g_ptr_array_sort(arr, (GCompareFunc)kanji_results_compare);
+    if(arr->len > MAX_COUNT)
+    {
+       kanji_result *res = g_ptr_array_index(arr, MAX_COUNT-1);
+       gint max_dist = res->dist;
+       for(i = arr->len - 1; i >= MAX_COUNT; i--)
        {
            kanji_result *res = g_ptr_array_index(arr, i);
-           if(res->dist > MAX_DISTANCE)
+           if(res->dist > max_dist)
                g_ptr_array_remove_index(arr, i);
            else
                break;
        }
-       entry = find_next_entry(allkanji, entry, allkanjilen, key);
-       if(!entry)
-           break;
     }
     gunichar2 *ret = calloc(arr->len + 1, sizeof(gunichar2));
     for(i = 0; i < arr->len; i++)