-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchange_format.cpp
66 lines (50 loc) · 1.46 KB
/
change_format.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<iostream>
#include<bits/stdc++.h>
#define size 1000
using namespace std;
int main(){
FILE *fe = fopen("entity2id.txt","r");
FILE *fr = fopen("relation2id.txt","r");
if(fe==NULL||fr==NULL){
printf("error");
return 0;
}
map<string,int> me;
map<string,int> mr;
int ne,nr;
char a[size];
fgets(a,size,fe);
ne = atoi(a);
fgets(a,size,fr);
nr = atoi(a);
for(int i=0;i<ne;i++){
fgets(a,size,fe);
char *tok;
tok = strtok(a,"\t");
string s(tok);
me[s]=i;
}
for(int i=0;i<nr;i++){
fgets(a,size,fr);
char *tok = strtok(a,"\t");
string s(tok);
mr[s]=i;
}
fclose(fr);
fclose(fe);
FILE *fp = fopen("test.txt","r");
FILE *f = fopen("test2id.txt","w");
while(fgets(a,size,fp)!=0){
char *tok = strtok(a,"\t");
string s(tok);
fprintf(f,"%d\t",me[s]);
tok = strtok(NULL,"\t");
string d(tok);
fprintf(f,"%d\t",me[d]);
tok = strtok(NULL,"\t");
tok[strlen(tok)-1]=0;
string g(tok);;
fprintf(f,"%d\n",mr[g]);
}
return 0;
}