-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdegree_of_relevance.rb
565 lines (532 loc) · 25.2 KB
/
degree_of_relevance.rb
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
require 'wordnet_based_similarity'
require 'graph_generator'
class DegreeOfRelevance
#creating accessors for the instance variables
attr_accessor :vertex_match
attr_accessor :review
=begin
Identifies relevance between a review and a submission
=end
def get_relevance(reviews, submissions, num_reviews, pos_tagger, core_NLP_tagger, speller) #double dimensional arrays that contain the submissions and the reviews respectively
review_vertices = nil
review_edges = nil
subm_vertices = nil
subm_edges = nil
num_rev_vert = 0
num_rev_edg = 0
num_sub_vert = 0
numSubEdg = 0
vert_match = 0.0
edge_without_syn = 0.0
edge_with_syn = 0.0
edge_diff_type = 0.0
double_edge = 0.0
double_edge_with_syn = 0.0
#since Reviews and Submissions "should" contain the same number of records review - submission pairs
g = GraphGenerator.new
#generating review's graph
g.generate_graph(reviews, pos_tagger, core_NLP_tagger, true, false)
review_vertices = g.vertices
review_edges = g.edges
num_rev_vert = g.num_vertices
num_rev_edg = g.num_edges
#assigning graph as a review graph to use in content classification
@review = g.clone
# puts "@review.num_edges: #{@review.num_edges}"
#generating the submission's graph
g.generate_graph(submissions, pos_tagger, core_NLP_tagger, true, false)
subm_vertices = g.vertices
subm_edges = g.edges
num_sub_vert = g.num_vertices
num_sub_edg = g.num_edges
vert_match = compare_vertices(pos_tagger, review_vertices, subm_vertices, num_rev_vert, num_sub_vert, speller)
if(num_rev_edg > 0 and num_sub_edg > 0)
edge_without_syn = compare_edges_non_syntax_diff(review_edges, subm_edges, num_rev_edg, num_sub_edg)
edge_with_syn = compare_edges_syntax_diff(review_edges, subm_edges, num_rev_edg, num_sub_edg)
edge_diff_type = compare_edges_diff_types(review_edges, subm_edges, num_rev_edg, num_sub_edg)
edge_match = (edge_without_syn.to_f + edge_with_syn.to_f )/2.to_f #+ edge_diff_type.to_f
double_edge = compare_SVO_edges(review_edges, subm_edges, num_rev_edg, num_sub_edg)
double_edge_with_syn = compare_SVO_diff_syntax(review_edges, subm_edges, num_rev_edg, num_sub_edg)
double_edge_match = (double_edge.to_f + double_edge_with_syn.to_f)/2.to_f
else
edge_match = 0
double_edge_match = 0
end
#differently weighted cases
#tweak this!!
alpha = 0.55
beta = 0.35
gamma = 0.1 #alpha > beta > gamma
relevance = (alpha.to_f * vert_match.to_f) + (beta * edge_match.to_f) + (gamma * double_edge_match.to_f) #case1's value will be in the range [0-6] (our semantic values)
scaled_relevance = relevance.to_f/6.to_f #scaled from [0-6] in the range [0-1]
#printing values
# puts("vertexMatch is [0-6]:: #{vert_match}")
# puts("edgeWithoutSyn Match is [0-6]:: #{edge_without_syn}")
# puts("edgeWithSyn Match is [0-6]:: #{edge_with_syn}")
# puts("edgeDiffType Match is [0-6]:: #{edge_diff_type}")
# puts("doubleEdge Match is [0-6]:: #{double_edge}")
# puts("doubleEdge with syntax Match is [0-6]:: #{double_edge_with_syn}")
# puts("relevance [0-6]:: #{relevance}")
# puts("scaled relevance on [0-1]:: #{scaled_relevance}")
# puts("*************************************************")
return scaled_relevance
end
=begin
* every vertex is compared with every other vertex
* Compares the vertices from across the two graphs to identify matches and quantify various metrics
* v1- vertices of the submission/past review and v2 - vertices from new review
=end
def compare_vertices(pos_tagger, rev, subm, num_rev_vert, num_sub_vert, speller)
# puts("****Inside compare_vertices:: rev.length:: #{num_rev_vert} subm.length:: #{num_sub_vert}")
#for double dimensional arrays, one of the dimensions should be initialized
@vertex_match = Array.new(num_rev_vert){Array.new}
wnet = WordnetBasedSimilarity.new
cum_vertex_match = 0.0
count = 0
max = 0.0
flag = 0
for i in (0..num_rev_vert - 1)
if(!rev.nil? and !rev[i].nil?)
rev[i].node_id = i
#puts("%%%%%%%%%%% Token #{rev[i].name} ::: POS tags:: rev[i].pos_tag:: #{rev[i].pos_tag} :: rev[i].node_id #{rev[i].node_id}")
#skipping frequent words from vertex comparison
if(wnet.is_frequent_word(rev[i].name))
next #ruby equivalent for continue
end
#looking for the best match
#j tracks every element in the set of all vertices, some of which are null
for j in (0..num_sub_vert - 1)
if(!subm[j].nil?)
if(subm[j].node_id == -1)
subm[j].node_id = j
end
#puts("%%%%%%%%%%% Token #{subm[j].name} ::: POS tags:: subm[j].pos_tag:: #{subm[j].pos_tag} subm[j].node_id #{subm[j].node_id}")
if(wnet.is_frequent_word(subm[j].name))
next #ruby equivalent for continue
end
#comparing only if one of the two vertices are nouns
#if(rev[i].pos_tag.include?("NN") and subm[j].pos_tag.include?("NN"))
@vertex_match[i][j] = wnet.compare_strings(rev[i], subm[j], speller)
# puts "returned value #{@vertex_match[i][j]}, max #{max}"
#only if the "if" condition is satisfied, since there could be null objects in between and you dont want unnecess. increments
flag = 1
if(@vertex_match[i][j] > max)
max = @vertex_match[i][j]
end
#end
end
end #end of for loop for the submission vertices
if(flag != 0)#if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with
#puts("**** Best match for:: #{rev[i].name}-- #{max}")
cum_vertex_match = cum_vertex_match + max
count+=1
max = 0.0 #re-initialize
flag = 0
end
end #end of if condition
end #end of for loop
avg_match = 0.0
if(count > 0)
avg_match = cum_vertex_match/ count
end
return avg_match
end #end of compare_vertices
#------------------------------------------#------------------------------------------
=begin
* SAME TYPE COMPARISON!!
* Compares the edges from across the two graphs to identify matches and quantify various metrics
* compare SUBJECT-VERB edges with SUBJECT-VERB matches
* where SUBJECT-SUBJECT and VERB-VERB or VERB-VERB and OBJECT-OBJECT comparisons are done
=end
def compare_edges_non_syntax_diff(rev, subm, num_rev_edg, num_sub_edg)
# puts("*****Inside compareEdgesnNonSyntaxDiff numRevEdg:: #{num_rev_edg} numSubEdg:: #{num_sub_edg}")
best_SV_SV_match = Array.new(num_rev_edg){Array.new}
cum_edge_match = 0.0
count = 0
max = 0.0
flag = 0
wnet = WordnetBasedSimilarity.new
for i in (0..num_rev_edg - 1)
if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)
#skipping edges with frequent words for vertices
if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))
next
end
#looking for best matches
for j in (0..num_sub_edg - 1)
#comparing in-vertex with out-vertex to make sure they are of the same type
if(!subm[j].nil? && subm[j].in_vertex.node_id != -1 && subm[j].out_vertex.node_id != -1)
#checking if the subm token is a frequent word
if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))
next
end
#carrying out the normal comparison
if(rev[i].in_vertex.type == subm[j].in_vertex.type && rev[i].out_vertex.type == subm[j].out_vertex.type)
if(!rev[i].label.nil?)
if(!subm[j].label.nil?)
#taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!
sum = 0.0
cou = 0
if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]
cou +=1
end
if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]
cou +=1
end
#--Only vertex matches
if(cou > 0)
best_SV_SV_match[i][j] = sum.to_f/cou.to_f
else
best_SV_SV_match[i][j] = 0.0
end
#--Vertex and SRL - Dividing it by the label's match value
best_SV_SV_match[i][j] = best_SV_SV_match[i][j]/ compare_labels(rev[i], subm[j])
flag = 1
if(best_SV_SV_match[i][j] > max)
max = best_SV_SV_match[i][j]
end
end
end
end
end
end #end of for loop for the submission edges
#cumulating the review edges' matches in order to get its average value
if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with
# puts("**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}")
cum_edge_match = cum_edge_match + max
count+=1
max = 0.0#re-initialize
flag = 0
end
end
end #end of 'for' loop for the review's edges
#getting the average for all the review edges' matches with the submission's edges
avg_match = 0.0
if(count > 0)
avg_match = cum_edge_match/ count
end
return avg_match
end
#------------------------------------------#------------------------------------------
=begin
* SAME TYPE COMPARISON!!
* Compares the edges from across the two graphs to identify matches and quantify various metrics
* compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa
* where SUBJECT-OBJECT and VERB_VERB comparisons are done - same type comparisons!!
=end
def compare_edges_syntax_diff(rev, subm, num_rev_edg, num_sub_edg)
# puts("*****Inside compareEdgesSyntaxDiff :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}")
best_SV_VS_match = Array.new(num_rev_edg){Array.new}
cum_edge_match = 0.0
count = 0
max = 0.0
flag = 0
wnet = WordnetBasedSimilarity.new
for i in (0..num_rev_edg - 1)
if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)
#skipping frequent word
if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))
next
end
for j in (0..num_sub_edg - 1)
if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)
#checking if the subm token is a frequent word
if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))
next
end
if(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)
#taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!
sum = 0.0
cou = 0
if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]
cou +=1
end
if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]
cou +=1
end
if(cou > 0)
best_SV_VS_match[i][j] = sum.to_f/cou.to_f
else
best_SV_VS_match[i][j] = 0.0
end
flag = 1
if(best_SV_VS_match[i][j] > max)
max = best_SV_VS_match[i][j]
end
end
end #end of the if condition
end #end of the for loop for the submission edges
if(flag != 0)#if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with
# puts("**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name}-- #{max}")
cum_edge_match = cum_edge_match + max
count+=1
max = 0.0 #re-initialize
flag = 0
end
end #end of the if condition
end #end of the for loop for the review
avg_match = 0.0
if(count > 0)
avg_match = cum_edge_match.to_f/count.to_f
end
return avg_match
end #end of the method
#------------------------------------------#------------------------------------------
=begin
DIFFERENT TYPE COMPARISON!!
* Compares the edges from across the two graphs to identify matches and quantify various metrics
* compare SUBJECT-VERB edges with VERB-OBJECT matches and vice-versa
* SUBJECT-VERB, VERB-SUBJECT, OBJECT-VERB, VERB-OBJECT comparisons are done!
=end
def compare_edges_diff_types(rev, subm, num_rev_edg, num_sub_edg)
# puts("*****Inside compareEdgesDiffTypes :: numRevEdg :: #{num_rev_edg} numSubEdg:: #{num_sub_edg}")
best_SV_VS_match = Array.new(num_rev_edg){Array.new}
cum_edge_match = 0.0
count = 0
max = 0.0
flag = 0
wnet = WordnetBasedSimilarity.new
for i in (0..num_rev_edg - 1)
if(!rev[i].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1)
#skipping edges with frequent words for vertices
if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name))
next
end
#identifying best match for edges
for j in (0..num_sub_edg - 1)
if(!subm[j].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1)
#checking if the subm token is a frequent word
if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))
next
end
#for S-V with S-V or V-O with V-O
if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type)
#taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!
sum = 0.0
cou = 0
if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].out_vertex.node_id]
cou +=1
end
if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].in_vertex.node_id]
cou +=1
end
if(cou > 0)
best_SV_VS_match[i][j] = sum.to_f/cou.to_f
else
best_SV_VS_match[i][j] = 0.0
end
#-- Vertex and SRL
best_SV_VS_match[i][j] = best_SV_VS_match[i][j]/ compare_labels(rev[i], subm[j])
flag = 1
if(best_SV_VS_match[i][j] > max)
max = best_SV_VS_match[i][j]
end
#for S-V with V-O or V-O with S-V
elsif(rev[i].in_vertex.type == subm[j].out_vertex.type and rev[i].out_vertex.type == subm[j].in_vertex.type)
#taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!
sum = 0.0
cou = 0
if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]
cou +=1
end
if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]
cou +=1
end
if(cou > 0)
best_SV_VS_match[i][j] = sum.to_f/cou.to_f
else
best_SV_VS_match[i][j] =0.0
end
flag = 1
if(best_SV_VS_match[i][j] > max)
max = best_SV_VS_match[i][j]
end
end
end #end of the if condition
end #end of the for loop for submission edges
if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with
# puts("**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} -- #{max}")
cum_edge_match = cum_edge_match + max
count+=1
max = 0.0 #re-initialize
flag = 0
end
end #end of if condition
end #end of for loop for review edges
avg_match = 0.0
if(count > 0)
avg_match = cum_edge_match.to_f/ count.to_f
end
return avg_match
end #end of the method
#------------------------------------------#------------------------------------------
def compare_SVO_edges(rev, subm, num_rev_edg, num_sub_edg)
# puts("***********Inside compare SVO edges numRevEdg:: #{num_rev_edg} numSubEdg:: #{num_sub_edg}")
best_SVO_SVO_edges_match = Array.new(num_rev_edg){Array.new}
cum_double_edge_match = 0.0
count = 0
max = 0.0
flag = 0
wnet = WordnetBasedSimilarity.new
for i in (0..num_rev_edg - 1)
if(!rev[i].nil? and !rev[i+1].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1 and
rev[i+1].out_vertex.node_id != -1 and rev[i].out_vertex == rev[i+1].in_vertex)
#skipping edges with frequent words for vertices
if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name) and wnet.is_frequent_word(rev[i+1].out_vertex.name))
next
end
#best match
for j in (0..num_sub_edg - 1)
if(!subm[j].nil? and !subm[j+1].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1 and
subm[j+1].out_vertex.node_id != -1 and subm[j].out_vertex == subm[j+1].in_vertex)
#checking if the subm token is a frequent word
if(wnet.is_frequent_word(subm[j].in_vertex.name) and wnet.is_frequent_word(subm[j].out_vertex.name))
next
end
#making sure the types are the same during comparison
if(rev[i].in_vertex.type == subm[j].in_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type and
rev[i+1].out_vertex.type == subm[j+1].out_vertex.type)
#taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!
sum = 0.0
cou = 0
if(!@vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j].in_vertex.node_id]
cou +=1
end
if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]
cou +=1
end
if(!@vertex_match[rev[i+1].out_vertex.node_id][subm[j+1].out_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i+1].out_vertex.node_id][subm[j+1].out_vertex.node_id]
cou +=1
end
#-- Only Vertex match
if(cou > 0)
best_SVO_SVO_edges_match[i][j] = sum.to_f/cou.to_f
else
best_SVO_SVO_edges_match[i][j] = 0.0
end
#-- Vertex and SRL
best_SVO_SVO_edges_match[i][j] = best_SVO_SVO_edges_match[i][j].to_f/ compare_labels(rev[i], subm[j]).to_f
best_SVO_SVO_edges_match[i][j] = best_SVO_SVO_edges_match[i][j].to_f/ compare_labels(rev[i+1], subm[j+1]).to_f
#-- Only SRL
if(best_SVO_SVO_edges_match[i][j] > max)
max = best_SVO_SVO_edges_match[i][j]
end
flag = 1
end
end #end of 'if' condition
end #end of 'for' loop for 'j'
if(flag != 0) #if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with
# puts("**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} - #{rev[i+1].out_vertex.name} -- #{max}")
cum_double_edge_match = cum_double_edge_match + max
count+=1
max = 0.0 #re-initialize
flag = 0
end
end #end of 'if' condition
end #end of 'for' loop for 'i'
avg_match = 0.0
if(count > 0)
avg_match = cum_double_edge_match.to_f/ count.to_f
end
return avg_match
end
#------------------------------------------#------------------------------------------
def compare_SVO_diff_syntax(rev, subm, num_rev_edg, num_sub_edg)
# puts("***********Inside compare SVO edges with syntax difference numRevEdg:: #{num_rev_edg} numSubEdg:: #{num_sub_edg}")
best_SVO_OVS_edges_match = Array.new(num_rev_edg){ Array.new}
cum_double_edge_match = 0.0
count = 0
max = 0.0
flag = 0
wnet = WordnetBasedSimilarity.new
for i in (0..num_rev_edg - 1)
if(!rev[i].nil? and !rev[i+1].nil? and rev[i].in_vertex.node_id != -1 and rev[i].out_vertex.node_id != -1 and
rev[i+1].out_vertex.node_id != -1 and rev[i].out_vertex == rev[i+1].in_vertex)
#skipping edges with frequent words for vertices
if(wnet.is_frequent_word(rev[i].in_vertex.name) and wnet.is_frequent_word(rev[i].out_vertex.name) and wnet.is_frequent_word(rev[i+1].out_vertex.name))
next
end
for j in (0..num_sub_edg - 1)
if(!subm[j].nil? and !subm[j+1].nil? and subm[j].in_vertex.node_id != -1 and subm[j].out_vertex.node_id != -1 and subm[j+1].out_vertex.node_id != -1 and subm[j].out_vertex == subm[j+1].in_vertex)
#making sure the types are the same during comparison
if(rev[i].in_vertex.type == subm[j+1].out_vertex.type and rev[i].out_vertex.type == subm[j].out_vertex.type and
rev[i+1].out_vertex.type == subm[j].in_vertex.type)
#taking each match separately because one or more of the terms may be a frequent word, for which no @vertex_match exists!
sum = 0.0
cou = 0
if(!@vertex_match[rev[i].in_vertex.node_id][subm[j+1].out_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].in_vertex.node_id][subm[j+1].out_vertex.node_id]
cou +=1
end
if(!@vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i].out_vertex.node_id][subm[j].out_vertex.node_id]
cou +=1
end
if(!@vertex_match[rev[i+1].out_vertex.node_id][subm[j].in_vertex.node_id].nil?)
sum = sum + @vertex_match[rev[i+1].out_vertex.node_id][subm[j].in_vertex.node_id]
cou +=1
end
#comparing s-v-o (from review) with o-v-s (from submission)
if(cou > 0)
best_SVO_OVS_edges_match[i][j] = sum.to_f/cou.to_f
else
best_SVO_OVS_edges_match[i][j] = 0.0
end
flag = 1
if(best_SVO_OVS_edges_match[i][j] > max)
max = best_SVO_OVS_edges_match[i][j]
end
end
end #end of 'if' condition
end #end of 'for' loop for 'j'
if(flag != 0)#if the review edge had any submission edges with which it was matched, since not all S-V edges might have corresponding V-O edges to match with
# puts("**** Best match for:: #{rev[i].in_vertex.name} - #{rev[i].out_vertex.name} - #{rev[i+1].out_vertex.name}-- #{max}")
cum_double_edge_match = cum_double_edge_match + max
count+=1
max = 0.0 #re-initialize
flag = 0
end
end #end of if condition
end #end of for loop for 'i'
avg_match = 0.0
if(count > 0)
avg_match = cum_double_edge_match.to_f / count.to_f
end
return avg_match
end #end of method
#------------------------------------------#------------------------------------------
=begin
SR Labels and vertex matches are given equal importance
* Problem is even if the vertices didn't match, the SRL labels would cause them to have a high similarity.
* Consider "boy - said" and "chocolate - melted" - these edges have NOMATCH for vertices, but both edges have the same label "SBJ" and would get an EXACT match,
* resulting in an avg of 3! This cant be right!
* We therefore use the labels to only decrease the match value found from vertices, i.e., if the labels were different.
* Match value will be left as is, if the labels were the same.
=end
def compare_labels(edge1, edge2)
result = EQUAL
if(!edge1.label.nil? and !edge2.label .nil?)
if(edge1.label.downcase == edge2.label.downcase)
result = EQUAL #divide by 1
else
result = DISTINCT #divide by 2
end
elsif((!edge1.label.nil? and !edge2.label.nil?) or (edge1.label.nil? and !edge2.label.nil? )) #if only one of the labels was null
result = DISTINCT
elsif(edge1.label.nil? and edge2.label.nil?) #if both labels were null!
result = EQUAL
end
return result
end # end of method
end