blib/lib/UMLS/Similarity/ErrorHandler.pm untested

filter: Statementstmt 0.0% 0 / 97 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 138 SCAR 53.5
CC
14
Cov
0%
checkPathBasedMeasures
30.0
checkRelatednessMeasures
30.0
_error
20.0
CRAP 210.0
1 # UMLS::Similarity::ErrorHandler
2 # (Last Updated $Id: ErrorHandler.pm,v 1.13 2011/05/18 13:08:08 btmcinnes Exp $)
3 #
4 # Perl module that provides a perl interface to the
5 # Unified Medical Language System (UMLS)
6 #
7 # Copyright (c) 2004-2011,
8 #
9 # Bridget T. McInnes, University of Minnesota, Twin Cities
10 # bthomson at cs.umn.edu
11 #
12 # Siddharth Patwardhan, University of Utah, Salt Lake City
13 # sidd at cs.utah.edu
14 #
15 # Serguei Pakhomov, University of Minnesota, Twin Cities
16 # pakh0002 at umn.edu
17 #
18 # Ted Pedersen, University of Minnesota, Duluth
19 # tpederse at d.umn.edu
20 #
21 # Ying Liu, University of Minnesota, Twin Cities
22 # liux0935 at umn.edu
23 #
24 # This program is free software; you can redistribute it and/or
25 # modify it under the terms of the GNU General Public License
26 # as published by the Free Software Foundation; either version 2
27 # of the License, or (at your option) any later version.
28 #
29 # This program is distributed in the hope that it will be useful,
30 # but WITHOUT ANY WARRANTY; without even the implied warranty of
31 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 # GNU General Public License for more details.
33 #
34 # You should have received a copy of the GNU General Public License
35 # along with this program; if not, write to
36 #
37 # The Free Software Foundation, Inc.,
38 # 59 Temple Place - Suite 330,
39 # Boston, MA 02111-1307, USA.
40  
41 package UMLS::Similarity::ErrorHandler;
42  
43 use Fcntl;
44 use strict;
45 use warnings;
46 use DBI;
47 use bytes;
48  
49 my $e1 = "Measure does not support the configuration option (Error Code 1).";
50 my $e2 = "Missing configuration option (Error Code 2). ";
51 my $e3 = "Duplicate configuration option (Error Code 3).";
52  
53 sub _error {
54  
55 my $self = shift;
56 my $measure = shift;
57 my $string = shift;
58 my $code = shift;
59
60 my $errorstring = "";
61 if($code == 1) { $errorstring = $e1; }
62 if($code == 2) { $errorstring = $e2; }
63 if($code == 3) { $errorstring = $e3; }
64
65
66 print STDERR "ERROR: UMLS::Similarity->$measure\n";
67 print STDERR "$errorstring\n";
68 print STDERR "$string\n";
69
70 exit;
71 }
72  
73 # checks the configuration file for the measure
74 # input : $measure <- string containing the measure name
75 # $interface <- UMLS::Interface handler
76 # output:
77 sub checkConfig {
78 my $self = shift;
79 my $measure = shift;
80 my $interface = shift;
81  
82 if($measure=~/(path|cdist|nam|wup|lch|jcn|lin|res)/) {
83 $self->checkPathBasedMeasures($measure, $interface);
84 }
85 elsif($measure=~/(vector|lesk)/ ) {
86 $self->checkRelatednessMeasures($measure, $interface);
87 }
88 }
89  
90 # check the config file with the path-based and IC measures
91 # input : $measure <- string containing the measure name
92 # $interface <- UMLS::Interface handler
93 sub checkPathBasedMeasures {
94
95 my $self = shift;
96 my $measure = shift;
97 my $interface = shift;
98  
99 my $hash = $interface->getConfigParameters();
100  
101 # set possible options
102 my %options = ();
103 $options{"SAB"} = 0;
104 $options{"REL"} = 0;
105 $options{"RELA"} = 0;
106  
107 # get the config options
108 my $check = 0;
109 foreach my $param (sort keys %{$hash}) {
110 $check++;
111 if(exists $options{$param}) { $options{$param}++; }
112 else {
113 my $string = "Option: ($param).\n";
114 $self->_error($measure, $string, 1);
115 }
116 }
117  
118 # remove the optional parameters
119 delete $options{"RELA"};
120  
121 # if the check is zero there are no parameters so
122 # it is using defaults which is good otherewise
123 # check to make certain nothing is mising
124 if($check != 0) {
125 foreach my $param (sort keys %options) {
126 if($options{$param} == 0) {
127 my $string = "Option Missing : $param\n";
128 $self->_error($measure, $string, 2);
129 }
130 if($options{$param} > 1) {
131 my $string = "Duplicate Options : $param\n";
132 $self->_error($measure, $string, 3);
133 }
134 }
135 }
136 }
137  
138  
139 # check the config file with the relatedness measures
140 # input : $measure <- string containing the measure name
141 # $interface <- UMLS::Interface handler
142 # output:
143 sub checkRelatednessMeasures {
144
145 my $self = shift;
146 my $measure = shift;
147 my $interface = shift;
148  
149 my $hash = $interface->getConfigParameters();
150  
151 # set possible options
152 my %options = ();
153 $options{"SABDEF"} = 0;
154 $options{"RELDEF"} = 0;
155 $options{"RELADEF"} = 0;
156
157 # get the config options
158 my $check = 0;
159 foreach my $param (sort keys %{$hash}) {
160 $check++;
161 if(exists $options{$param}) { $options{$param}++; }
162 else {
163 my $string = "Option: ($param).\n";
164 $self->_error($measure, $string, 1);
165 }
166 }
167
168 # remove the optional parameters
169 delete $options{"RELADEF"};
170  
171 # if the check is zero there are no parameters so
172 # it is using defaults which is good otherewise
173 # check to make certain nothing is mising
174 if($check != 0) {
175 foreach my $param (sort keys %options) {
176 if($options{$param} == 0) {
177 my $string = "Option Missing : $param\n";
178 $self->_error($measure, $string, 2);
179 }
180 if($options{$param} > 1) {
181 my $string = "Duplicate Options : $param\n";
182 $self->_error($measure, $string, 3);
183 }
184 }
185 }
186 }
187  
188 # sets up the error handler module
189 # input : $measure <- string containing the measure name
190 # $interface <- UMLS::Interface handler
191 # output: $self
192 sub new {
193  
194 my $self = {};
195 my $className = shift;
196 my $measure = shift;
197 my $interface = shift;
198  
199 # Bless the object.
200 bless($self, $className);
201
202 # check the config options
203 $self->checkConfig($measure, $interface);
204
205  
206 return $self;
207 }
208 1;
209 __END__