-
Notifications
You must be signed in to change notification settings - Fork 0
/
synlink.cpp
47 lines (44 loc) · 1.19 KB
/
synlink.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "synlink.h"
bool compare (Synset first, Synset second){
return ( first.rel() > second.rel() );
}
int main(int argc, char* argv[]){
if(argc != 3){
printf("input:input-filename output-filename\n");
return -1;
}
list<Synset> synsetlist;
sqlite3 *db;
int rc,i;
FILE *fp,*fout;
rc = sqlite3_open("wnjpn.1.1.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
exit(0);
}else{
fprintf(stderr, "Opened database successfully\n");
}
int total = 0;
list<Synset>::iterator iter;
char tmpsyn[20];
int tmpnum = 0;
fp = fopen(argv[1],"r");
fout = fopen(argv[2],"w");
while(fscanf(fp,"%s",tmpsyn) != EOF){
total++;
char sql[1000];
snprintf(sql,1000,"select count(*) from synlink where synset2 = '%s' or synset1 = '%s'",tmpsyn,tmpsyn);
ssql(db,sql,callback2,(void*)&tmpnum);
synsetlist.push_back(Synset(tmpsyn,tmpnum));
}
synsetlist.sort(compare);
for (iter = synsetlist.begin(); iter != synsetlist.end(); iter++){
iter->fileout(fout);
}
printf("over\n");
fclose(fp);
fclose(fout);
sqlite3_close(db);
printf("%d\n",total);
return 0;
}