-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cab
executable file
·179 lines (140 loc) · 5.45 KB
/
Cab
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
#!/usr/bin/perl
#####
# usage :
# ```
# $ ./Cab [summarization rate] [list_of_source]
# ```
#####
use strict;
#use warnings;
use utf8;
use v5.10; # using state
use open IO=> ':encoding(utf8)';
binmode STDIN, ':encoding(utf8)';
binmode STDOUT, ':encoding(utf8)';
binmode STDERR, ':encoding(utf8)';
use lib qw(lib);
use Storable qw(nstore retrieve);
use Latex2Text ':all';
use CabCommon ':all';
use LocalTF ':all';
use GlobalTF ':all';
use RelParagMatching ':all';
$#ARGV >= 0 || die "Usage: ./Cab [NAME OF LATEX SOURCE FILES]\n";
##### Cab process start
my @latex_files = <@ARGV>;
print scalar @latex_files." input latex files\n";
my $num_done;
### init log directory
### make the structure of each section and subsection from latex file
{
open my $fh, '>', 'classified_rate.md' or die "Can't open'classified_rate.md': $!";
for my $path_latex (@latex_files) {
my $log_dir = make_log_dir($path_latex);
my $struct = latex_to_section_structure($path_latex);
dump_sec_file($struct, $log_dir);
analysis_morpheme($struct->[0]); # mecab
dump_struct($struct, $log_dir);
check_classified_rate($log_dir, $fh, 0);
# debug_title($struct);
### print all sent id and sent
# for (0..$#{$struct->[0]}){
# print "$_: $struct->[0][$_]{sent}\n";
# }
###
}
check_classified_rate('', $fh, 1);
close $fh;
}
### make local term frequency table and calc the score
{
for my $path_latex (@latex_files) {
my $log_dir = get_log_dir($path_latex);
my $struct_path = File::Spec->catfile($log_dir, "struct");
my $struct = retrieve $struct_path;
my %local_tf;
make_local_tf_table($struct->[0], \%local_tf);
dump_local_tf_table(\%local_tf, $log_dir);
calc_local_tf_score($struct->[0], \%local_tf);
# debug_calc_local_tf_score($struct);
# dump_high_local_tf_sent($struct, $log_dir);
dump_struct($struct, $log_dir);
}
}
### make the global tf table(this table is unique within entire files) and tfidf table(this table is for each file), calc the tf idf score
{
my %global_tf;
my %doc_freq;
my $doc_total = scalar @latex_files;
make_global_tf_table(\%global_tf, \%doc_freq, get_log_dir($_)) for (@latex_files);
dump_global_tf_table(\%global_tf, './logs');
for my $path_latex (@latex_files) {
my $log_dir = get_log_dir($path_latex);
my $struct_path = File::Spec->catfile($log_dir, "struct");
my $struct = retrieve $struct_path;
my %tf_idf;
make_tf_idf_table(\%tf_idf, \%global_tf, \%doc_freq, $doc_total, $log_dir);
dump_tf_idf_table(\%tf_idf, $log_dir);
calc_tf_idf_score($struct, \%tf_idf, $log_dir); # scoring with sigmoid
# debug_calc_tf_idf_score # empty
# dump_high_tf_idf_sent($struct, $log_dir);
dump_struct($struct, $log_dir);
$num_done++;
}
}
### 2nd match for related_study
{
for my $path_latex (@latex_files) {
my $log_dir = get_log_dir($path_latex);
my $struct_path = File::Spec->catfile($log_dir, "struct");
my $struct = retrieve $struct_path;
my $rel_file = File::Spec->catfile($log_dir, "related_study");
# check wether 'related_study' section inspected or not
my $rel_flag = 0;
for my $n (1..$#$struct) {
$rel_flag = $n if ($struct->[$n]{type} eq 'related_study');
}
if ($rel_flag) { # if related_study inspected in 1st matching
print "[$path_latex] rel_title matched\n";
my ($parag_chunk, $both_end_idx) = bind_sec_to_parag($struct, $rel_flag);
# debug_bind_sec_to_parag($struct, $parag_chunk, $both_end_idx);
my $parag_score = get_score_by_pattern_matching_paragraph($parag_chunk);
# debug_get_score_by_pattern_matching_paragraph($parag_chunk, $parag_score);
my $parag_high_idx = get_highest_scored_paragraph($parag_score, $#$parag_chunk);
# debug_get_highest_scored_paragraph($parag_chunk, $parag_score, $parag_high_idx);
add_rel_score($struct, $rel_flag, $parag_score, $parag_high_idx);
# debug_add_rel_score($struct, $parag_score, $rel_flag, $parag_high_idx);
} else { # if related_study not inspected in 1st matching
print "[$path_latex] rel_title no matched\n";
my ($parag_chunk, $both_end_idx) = bind_sent_to_parag($struct);
# debug_bind_sent_to_parag($parag_chunk, $both_end_idx, $struct);
my $parag_score = get_score_by_pattern_matching_paragraph($parag_chunk);
# debug_get_score_by_pattern_matching_paragraph($parag_chunk, $parag_score);
my $parag_high_idx = get_highest_scored_paragraph($parag_score, $#$parag_chunk);
# debug_get_highest_scored_paragraph($parag_chunk, $parag_score, $parag_high_idx);
make_imitate_struct($struct, $parag_score, $both_end_idx, $parag_high_idx);
# debug_make_imitate_struct($struct, $parag_score, $parag_high_idx);
# dump_rel_paragraph($log_dir, $struct);
# debug_struct($struct);
# debug_paragraphs($struct);
# debug_sections($struct);
}
dump_struct($struct, $log_dir);
dump_sec_file($struct, $log_dir);
}
}
### write the Cab file 'merged_summary'
{
for my $path_latex (@latex_files) {
my $log_dir = get_log_dir($path_latex);
my $struct_path = File::Spec->catfile($log_dir, "struct");
my $struct = retrieve $struct_path;
# my $int_sum = get_intro_summary();
my $rel = get_rel_summary($struct, $log_dir, 4);
my $out_path = File::Spec->catfile($log_dir, "merged_summary");
open my $fh_out, '>', $out_path or die "Can't open $out_path: $!";
print $fh_out "$struct->[0][$rel->[$_]]{sent}\nSCORE: $struct->[0][$rel->[$_]]{rel_score}, idx: $rel->[$_]\n\n" for (0..$#$rel);
close $fh_out;
}
}
print "$num_done input latex files processed\n";