Create devel package not to install header and .pc file in binary
[platform/core/uifw/anthy.git] / mkworddic / calcfreq.c
1 /* Ã±¸ì¤ÎÉÑÅÙ¤ò·×»»¤¹¤ë */
2 #include <stdlib.h>
3 #include "mkdic.h"
4
5 static int
6 count_nr_words(struct yomi_entry_list *yl)
7 {
8   int nr = 0;
9   struct yomi_entry *ye;
10   for (ye = yl->head; ye; ye = ye->next) {
11     nr += ye->nr_entries;
12   }
13   return nr;
14 }
15
16 static struct word_entry **
17 make_word_array(struct yomi_entry_list *yl, int nr)
18 {
19   struct word_entry **array = malloc(sizeof(struct word_entry *) *
20                                     nr);
21   int nth = 0;
22   struct yomi_entry *ye;
23   for (ye = yl->head; ye; ye = ye->next) {
24     int i;
25     for (i = 0; i < ye->nr_entries; i++) {
26       array[nth] = &ye->entries[i];
27       nth ++;
28     }
29   }
30   return array;
31 }
32
33 /** qsortÍѤÎÈæ³Ó´Ø¿ô */
34 static int
35 compare_word_entry_by_freq(const void *p1, const void *p2)
36 {
37   const struct word_entry * const *e1 = p1;
38   const struct word_entry * const *e2 = p2;
39   return abs((*e2)->raw_freq) - abs((*e1)->raw_freq);
40 }
41
42 static void
43 set_freq(struct word_entry **array, int nr)
44 {
45   int i;
46   int percent = nr / 100;
47   for (i = 0; i < nr; i++) {
48     struct word_entry *we = array[i];
49     we->freq = 99 - (i / percent);
50     if (we->freq < 1) {
51       we->freq = 1;
52     }
53     we->freq *= 100;
54     we->freq -= we->source_order;
55     if (we->raw_freq < 0) {
56       we->freq *= -1;
57     }
58   }
59 }
60
61 void
62 calc_freq(struct yomi_entry_list *yl)
63 {
64   int nr;
65   struct word_entry **we;
66   /**/
67   nr = count_nr_words(yl);
68   we = make_word_array(yl, nr);
69   /**/
70   qsort(we, nr,
71         sizeof(struct word_entry *),
72         compare_word_entry_by_freq);
73   set_freq(we, nr);
74   /**/
75   free(we);
76 }
77