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

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 62 SCAR 37.4
CC
6
Cov
0%
getRelatedness
20.0
new
12.0
BEGIN
2.0
CRAP 42.0
1 # UMLS::Similarity::path.pm
2 #
3 # Module implementing the simple edge counting measure of
4 # semantic relatedness.
5 #
6 # Copyright (c) 2004-2011,
7 #
8 # Bridget T McInnes, University of Minnesota, Twin Cities
9 # bthomson at cs.umn.edu
10 #
11 # Siddharth Patwardhan, University of Utah, Salt Lake City
12 # sidd at cs.utah.edu
13 #
14 # Serguei Pakhomov, University of Minnesota, Twin Cities
15 # pakh002 at umn.edu
16 #
17 # Ted Pedersen, University of Minnesota, Duluth
18 # tpederse at d.umn.edu
19 #
20 # Ying Liu, University of Minnesota
21 # liux0935 at umn.edu
22 #
23 # This program is free software; you can redistribute it and/or
24 # modify it under the terms of the GNU General Public License
25 # as published by the Free Software Foundation; either version 2
26 # of the License, or (at your option) any later version.
27 #
28 # This program is distributed in the hope that it will be useful,
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 # GNU General Public License for more details.
32 #
33 # You should have received a copy of the GNU General Public License
34 # along with this program; if not, write to
35 #
36 # The Free Software Foundation, Inc.,
37 # 59 Temple Place - Suite 330,
38 # Boston, MA 02111-1307, USA.
39  
40  
41 package UMLS::Similarity::path;
42  
43 use strict;
44 use warnings;
45 use UMLS::Similarity;
46 use UMLS::Similarity::ErrorHandler;
47  
48 use vars qw($VERSION);
49 $VERSION = '0.07';
50  
51 my $debug = 0;
52  
53 sub new
54 {
55 my $className = shift;
56 my $interface = shift;
57
58 return undef if(ref $className);
59
60 my $self = {};
61
62 # Bless the object.
63 bless($self, $className);
64
65 # The backend interface object.
66 $self->{'interface'} = $interface;
67  
68 # check the configuration file if defined
69 my $errorhandler = UMLS::Similarity::ErrorHandler->new("path", $interface);
70 if(!$errorhandler) {
71 print STDERR "The UMLS::Similarity::ErrorHandler did not load properly\n";
72 exit;
73 }
74  
75 return $self;
76 }
77  
78  
79 sub getRelatedness
80 {
81 my $self = shift;
82 return undef if(!defined $self || !ref $self);
83 my $concept1 = shift;
84 my $concept2 = shift;
85
86 # if concept 1 and 2 are the same just return 1
87 if($concept1 eq $concept2) { return 1; }
88  
89 # get the interface
90 my $interface = $self->{'interface'};
91
92 # find the shortest paths
93 my $length = $interface->findShortestPathLength($concept1, $concept2);
94
95 # if length is less than zero (this shouldn't happen)
96 # return a score of zero
97 if($length <= 0) { return $length; }
98  
99 # otherwise return the reciprocal of the length
100 return (1/$length);
101 }
102  
103  
104 1;
105 __END__