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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*
gcc -g SFH_function.c -o SFH_function -lmaatframe -lMESA_htable -I../include
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "gram_index_engine.h"
#include <MESA/MESA_htable.h>
#include <assert.h>
#include <ctype.h>
#define SLOT_SIZE (1024*1024*16)
#define THREAD_SAFE 0
#define BUFFER_LEN (10*1024)
#define SFH_LEN (10*1024)
#define TD_LEN 33
typedef struct sfh_link
{
char *sfh_str;
int similiar;
int all_similiar;
long hash_len;
struct sfh_link *next;
}sfh_link;
typedef struct top_similiar_sfh
{
int all_num;
int all_similiar;
char *sfh_str;
long hash_len;
sfh_link *sfh_link_items;
}top_similiar_sfh;
long get_hashed_len(const char* sfh)
{
char *data=(char*)malloc(strlen(sfh)+1);
memcpy(data,sfh, strlen(sfh));
data[strlen(sfh)]='\0';
char *token=NULL,*sub_token=NULL,*saveptr;
long left_offset=0,right_offset=0,hashed_length=0;
int ret=0,first=0;
for (token = data; ; token= NULL)
{
sub_token= strtok_r(token,"[", &saveptr);
if (sub_token == NULL)
{
break;
}
if(first==0)//jump over the first sub string.
{
first=1;
continue;
}
ret=sscanf(sub_token,"%ld:%ld",&left_offset,&right_offset);
if(ret!=2)
{
return 0;
}
assert(ret==2);
hashed_length+=right_offset-left_offset+1;
}
//printf("hashed length=%ld\n",hashed_length);
free(data);
return hashed_length/2;
}
void print_mistake_td(const uchar *key,uint size,void *data,void *arg)
{
FILE *ripe_file = (FILE*)arg;
top_similiar_sfh *temp_top_similiar_sfh=(top_similiar_sfh*)data;
fprintf(ripe_file,"%s,%s\n",key,temp_top_similiar_sfh->sfh_str);
sfh_link *temp_sfh_link=temp_top_similiar_sfh->sfh_link_items;
for(;;temp_sfh_link=temp_sfh_link->next)
{
if(temp_sfh_link==NULL)
{
break;
}
fprintf(ripe_file,"%d;%s;%d\n",temp_sfh_link->similiar,temp_sfh_link->sfh_str,temp_sfh_link->hash_len);
}
fprintf(ripe_file,"\n");
}
int main()
{
FILE *raw_file;
FILE *ripe_file;
char *raw_file_dir="../data/td_data_set/td_data_20171207/video_id_raw_data";
char *ripe_file_dir="../data/ripe_data/td_data_20171207/all_av_digest_mistake_level_2";
char *sfh_str=NULL,*td=NULL,*buffer=NULL,*td_str=NULL;
raw_file = fopen(raw_file_dir,"r+");
ripe_file = fopen(ripe_file_dir,"w+");
long temp_hash_len=0;
unsigned int slot_size=SLOT_SIZE;
int i=0,thread_safe=THREAD_SAFE,ret=0,temp_similiar=0,temp_all_similiar=0;
top_similiar_sfh *temp_top_similiar_sfh=NULL;
sfh_link *temp_sfh_link=NULL;
MESA_htable_handle htable=NULL;
if(raw_file==NULL)
{
printf("open all_av_digest error\n");
return -1;
}
if(ripe_file==NULL)
{
printf("open all_av_digest_mistake_level error");
return -1;
}
buffer = (char*)calloc(BUFFER_LEN,sizeof(char));
sfh_str = (char*)calloc(SFH_LEN,sizeof(char));
td = (char*)calloc(TD_LEN,sizeof(char));
td[32]='\0';
htable=MESA_htable_born();
MESA_htable_set_opt(htable,MHO_SCREEN_PRINT_CTRL,&thread_safe,sizeof(unsigned int));
MESA_htable_set_opt(htable,MHO_HASH_SLOT_SIZE,&slot_size,sizeof(unsigned int));
MESA_htable_mature(htable);
while(feof(raw_file)==0)
{
i++;
if(i%10000==0)
{
printf("%d\n",i);
}
fgets(buffer,BUFFER_LEN-1,raw_file);
buffer[BUFFER_LEN-1]='\0';
ret=sscanf(buffer,"%[^;];%[^;];%[^;]",td_str,td,sfh_str);
assert(ret==2);
td[32]='\0';
if((temp_top_similiar_sfh=MESA_htable_search(htable,td,TD_LEN))==NULL)
{
temp_top_similiar_sfh=(top_similiar_sfh*)calloc(1,sizeof(top_similiar_sfh));
temp_top_similiar_sfh->all_num=1;
temp_top_similiar_sfh->all_similiar=0;
temp_top_similiar_sfh->hash_len=get_hashed_len(sfh_str);
temp_top_similiar_sfh->sfh_str=strdup(sfh_str);
temp_top_similiar_sfh->sfh_link_items=(sfh_link*)calloc(1,sizeof(sfh_link));
temp_top_similiar_sfh->sfh_link_items->sfh_str=strdup(sfh_str);
temp_top_similiar_sfh->sfh_link_items->similiar=0;
temp_top_similiar_sfh->sfh_link_items->all_similiar=0;
temp_top_similiar_sfh->sfh_link_items->next=NULL;
ret=MESA_htable_add(htable,td,TD_LEN,(void *)temp_top_similiar_sfh);
assert(ret>0);
}
else
{
temp_similiar=GIE_sfh_similiarity(temp_top_similiar_sfh->sfh_str,(int)strlen(temp_top_similiar_sfh->sfh_str),sfh_str,(int)strlen(sfh_str));
temp_top_similiar_sfh->all_similiar+=temp_similiar;
temp_sfh_link=temp_top_similiar_sfh->sfh_link_items;
for(temp_all_similiar=0;;temp_sfh_link=temp_sfh_link->next)
{
temp_similiar=GIE_sfh_similiarity(temp_sfh_link->sfh_str,(int)strlen(temp_sfh_link->sfh_str),sfh_str,(int)strlen(sfh_str));
temp_sfh_link->all_similiar+=temp_similiar;
temp_all_similiar+=temp_similiar;
if(temp_sfh_link->all_similiar>temp_top_similiar_sfh->all_similiar)
{
free(temp_top_similiar_sfh->sfh_str);
temp_top_similiar_sfh->sfh_str=strdup(temp_sfh_link->sfh_str);
temp_top_similiar_sfh->all_similiar=temp_sfh_link->all_similiar;
}
if(temp_sfh_link->next==NULL)
{
break;
}
}
temp_sfh_link->next=(sfh_link*)calloc(1,sizeof(sfh_link));
temp_sfh_link->next->sfh_str=strdup(sfh_str);
temp_sfh_link->next->hash_len=get_hashed_len(sfh_str);
temp_sfh_link->next->similiar=0;
temp_sfh_link->next->all_similiar=temp_all_similiar;
temp_sfh_link->next->next=NULL;
temp_top_similiar_sfh->all_num+=1;
}
}
fclose(raw_file);
MESA_htable_iterate(htable,print_mistake_td,ripe_file);
}
|