| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Declaring the Package for the module. |
|
4
|
|
|
|
|
|
|
package Text::SenseClusters::LabelEvaluation::PrintingHashData; |
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
30408
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
94
|
|
|
7
|
2
|
|
|
2
|
|
1137
|
use encoding "utf-8"; |
|
|
2
|
|
|
|
|
18351
|
|
|
|
2
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# The following two lines will make this module inherit from the Exporter Class. |
|
10
|
|
|
|
|
|
|
require Exporter; |
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
####################################################################################################################### |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 Name |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Text::SenseClusters::LabelEvaluation::PrintingHashData - Module for printing information stored in a Hash-Variable. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
The following code snippet will show how to use this module: |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Including the LabelEvaluation Module. |
|
26
|
|
|
|
|
|
|
use Text::SenseClusters::LabelEvaluation::PrintingHashData; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my %labelClusterHash = ( |
|
29
|
|
|
|
|
|
|
'cluster0' => { |
|
30
|
|
|
|
|
|
|
'Descriptive' => 'George Bush, Al Gore, White House, Cox News, BRITAIN London, Prime Minister, New York', |
|
31
|
|
|
|
|
|
|
'Discriminating' => 'George Bush, Cox News, BRITAIN London' |
|
32
|
|
|
|
|
|
|
}, |
|
33
|
|
|
|
|
|
|
'cluster1' => { |
|
34
|
|
|
|
|
|
|
'Descriptive' => 'Al Gore, White House, more than, George W, York Times, New York, Prime Minister', |
|
35
|
|
|
|
|
|
|
'Discriminating' => 'more than, York Times, George W' |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Text::SenseClusters::LabelEvaluation::PrintingHashData::prinHashOfHash(\%labelClusterHash); |
|
40
|
|
|
|
|
|
|
print "\n"; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This module provide two functions. First function will print the content |
|
46
|
|
|
|
|
|
|
of Hash-of-hash that is passed to it as argument. The second function will be |
|
47
|
|
|
|
|
|
|
used by confusion-matrix-module, to print the data in the matrix format. The |
|
48
|
|
|
|
|
|
|
function will present data in more readable format to users. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
########################################################################################## |
|
55
|
|
|
|
|
|
|
=head1 Function: prinHashOfHash |
|
56
|
|
|
|
|
|
|
------------------------------------------------ |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Function to print the content of Hash-of-Hash. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
@argument1 : Reference of HashOfHash whose values has to be printed. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
@return : Nothing. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Description: |
|
65
|
|
|
|
|
|
|
1. Iterate through the outer key in sorted order. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
2. Iterate through the inner key and print the corresponding value. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
|
70
|
|
|
|
|
|
|
########################################################################################## |
|
71
|
|
|
|
|
|
|
sub prinHashOfHash{ |
|
72
|
|
|
|
|
|
|
# Getting the Hash Reference from the argument. |
|
73
|
1
|
|
|
1
|
0
|
19
|
my $hashOfHashRef = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Getting the Hash from its reference. |
|
76
|
1
|
|
|
|
|
6
|
my %hashOfHash = %$hashOfHashRef; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Step 1: Iterating through the OuterKeys Of the Hash. |
|
79
|
1
|
|
|
|
|
8
|
foreach my $sortedOuterKey (sort keys %hashOfHash){ |
|
80
|
2
|
|
|
|
|
263
|
print "\n\nOuterKey = '$sortedOuterKey'"; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Step 2: Iterating through the InnerKeys Of the Hash. |
|
83
|
2
|
|
|
|
|
7
|
foreach my $sortedInnerKey (sort keys %{$hashOfHash{$sortedOuterKey}}){ |
|
|
2
|
|
|
|
|
12
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Step 3:Printing the value. |
|
86
|
4
|
|
|
|
|
842
|
print "\nInnerKey=$sortedInnerKey ". |
|
87
|
|
|
|
|
|
|
"Value=$hashOfHash{$sortedOuterKey}{$sortedInnerKey}"; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
########################################################################################## |
|
94
|
|
|
|
|
|
|
=head1 Function: prinHashOfScore |
|
95
|
|
|
|
|
|
|
------------------------------------------------ |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This function will print the score of each cluster and its most |
|
98
|
|
|
|
|
|
|
probable against a topic and its corresponding score. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
For e.g: |
|
103
|
|
|
|
|
|
|
Direct Col Conclusion:: |
|
104
|
|
|
|
|
|
|
Cluster0 : Tony_Blair , 0.577 |
|
105
|
|
|
|
|
|
|
Cluster1 : Bill_Clinton , 0.571 |
|
106
|
|
|
|
|
|
|
Direct Row Conclusion:: |
|
107
|
|
|
|
|
|
|
Bill_Clinton : Cluster1 , 0.522 |
|
108
|
|
|
|
|
|
|
Tony_Blair : Cluster0 , 0.625 |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Inverse Row Conclusion:: |
|
111
|
|
|
|
|
|
|
Cluster0 : Tony_Blair , 0.625 |
|
112
|
|
|
|
|
|
|
Cluster1 : Bill_Clinton , 0.522 |
|
113
|
|
|
|
|
|
|
Inverse Col Conclusion:: |
|
114
|
|
|
|
|
|
|
Bill_Clinton : Cluster1 , 0.571 |
|
115
|
|
|
|
|
|
|
Tony_Blair : Cluster0 , 0.577 |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
@Argument : Reference of HashOfHash |
|
119
|
|
|
|
|
|
|
(i) containing the topic (with supporting score) against a |
|
120
|
|
|
|
|
|
|
cluster name. |
|
121
|
|
|
|
|
|
|
(ii) containing the cluster name (with supporting score) |
|
122
|
|
|
|
|
|
|
against a topic. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
@return : Nothing. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
@Description: |
|
127
|
|
|
|
|
|
|
1. Get the HashOfHash Reference from the function argument. |
|
128
|
|
|
|
|
|
|
2. Iterate through key in sorted order. |
|
129
|
|
|
|
|
|
|
3. Clean the key and value. |
|
130
|
|
|
|
|
|
|
4. Write the result into the Output file. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Output File: |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Output file is the final file that user can see to get the detailed |
|
136
|
|
|
|
|
|
|
result about the complete evaluation process. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
|
139
|
|
|
|
|
|
|
########################################################################################## |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub prinHashOfScore{ |
|
142
|
|
|
|
|
|
|
# Getting the Hash Reference from the argument. |
|
143
|
0
|
|
|
0
|
0
|
|
my $topicClusterHashRef = shift; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Getting the Hash from its reference. |
|
146
|
0
|
|
|
|
|
|
my %topicClusterHash = %$topicClusterHashRef; |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Getting the File Handle from the function argument. |
|
149
|
0
|
|
|
|
|
|
my $outputFileHandle = shift; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# Going through Hash and Printing the score. |
|
152
|
|
|
|
|
|
|
# Getting the Key of the Hash in the sorted order. |
|
153
|
0
|
|
|
|
|
|
foreach my $sortedKey (sort keys %topicClusterHash){ |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Extracting the "topic" from the key (FileName is the key). |
|
156
|
0
|
|
|
|
|
|
my $key = $sortedKey; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Removing the additional text from the key (filename related stuff). |
|
159
|
0
|
|
|
|
|
|
$key =~ s/temp_//; |
|
160
|
0
|
|
|
|
|
|
$key =~ s/.txt//; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# Extracting the value from the hash. |
|
163
|
0
|
|
|
|
|
|
my $value = $topicClusterHash{$sortedKey}; |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# Removing the additional text from the values (filename related stuff). |
|
166
|
0
|
|
|
|
|
|
$value =~ s/temp_//; |
|
167
|
0
|
|
|
|
|
|
$value =~ s/.txt//; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# Writing the data into the output file. |
|
170
|
0
|
|
|
|
|
|
print $outputFileHandle "\n \t$key \t:\t$value"; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
####################################################################################################### |
|
178
|
|
|
|
|
|
|
=pod |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
http://senseclusters.cvs.sourceforge.net/viewvc/senseclusters/LabelEvaluation/ |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
@Last modified by : Anand Jha |
|
187
|
|
|
|
|
|
|
@Last_Modified_Date : 24th Dec. 2012 |
|
188
|
|
|
|
|
|
|
@Modified Version : 1.6 |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 AUTHORS |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Ted Pedersen, University of Minnesota, Duluth |
|
194
|
|
|
|
|
|
|
tpederse at d.umn.edu |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Anand Jha, University of Minnesota, Duluth |
|
197
|
|
|
|
|
|
|
jhaxx030 at d.umn.edu |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Copyright (C) 2012 Ted Pedersen, Anand Jha |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
208
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
|
209
|
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or |
|
210
|
|
|
|
|
|
|
(at your option) any later version. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
|
213
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
214
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
215
|
|
|
|
|
|
|
GNU General Public License for more details. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
|
218
|
|
|
|
|
|
|
along with this program; if not, write to: |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
The Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
|
222
|
|
|
|
|
|
|
Boston, MA 02111-1307 USA |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |
|
226
|
|
|
|
|
|
|
####################################################################################################### |
|
227
|
|
|
|
|
|
|
# Making the default return statement as 1; |
|
228
|
|
|
|
|
|
|
# Reference : http://lists.netisland.net/archives/phlpm/phlpm-2001/msg00426.html |
|
229
|
|
|
|
|
|
|
1; |