softcount: tolerate zero ngrams
[vspell.git] / utils / sc2wngram.c
blob3f79a7222afc0582fd0ca7208c9e185ed7e21326
1 #include <stdio.h>
2 #include <string.h>
4 int main(int argc,char **argv)
6 char w1[750],w2[750],w3[750];
7 char ow1[750],ow2[750],ow3[750];
8 double count,total_count;
9 total_count = 0;
10 int n_digit = 2;
11 long long int base;
13 if (argc == 2)
14 sscanf(argv[1],"%d",&n_digit);
15 for (base = 1;n_digit > 0; n_digit --) base *= 10;
17 while (scanf("%s %s %lf",w1,w2,&count) == 3) {
18 if (!strcmp(w1,ow1) && !strcmp(w2,ow2))
19 total_count += count;
20 else {
21 if (total_count > 0)
22 printf("%s %s %Ld\n",ow1, ow2, (long long int)(total_count*base) > 0 ? (long long int)(total_count*base) : (long long int)1);
23 strcpy(ow1,w1);
24 strcpy(ow2,w2);
25 total_count = count;
30 Force to long long int because <s> <digit>/<opaque>/<punct>
31 can easily run over int limit
33 if ((long long int)(total_count*base) > 0)
34 printf("%s %s %Ld\n",ow1, ow2, (long long int)(total_count*base) > 0 ? (long long int)(total_count*base) : (long long int)1);
35 return 0;