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

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 76 SCAR 45.0
CC
9
Cov
0%
new
30.0
getRelatedness
30.0
BEGIN
2.0
CRAP 90.0
1 # UMLS::Similarity::cdist.pm
2 #
3 # Module implementing the simple edge counting measure of
4 # semantic relatedness proposed by Rada, et. al. (1989).
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::cdist;
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 my $originaloption = undef;
54  
55 sub new
56 {
57 my $className = shift;
58 my $interface = shift;
59 my $params = shift;
60  
61 return undef if(ref $className);
62
63 if($debug) { print STDERR "In UMLS::Similarity::cdist->new()\n"; }
64
65 my $self = {};
66
67 # Bless the object.
68 bless($self, $className);
69
70 # The backend interface object.
71 $self->{'interface'} = $interface;
72
73 # check the configuration file if defined
74 my $errorhandler = UMLS::Similarity::ErrorHandler->new("path", $interface);
75 if(!$errorhandler) {
76 print STDERR "The UMLS::Similarity::ErrorHandler did not load properly\n";
77 exit;
78 }
79  
80 # check if the original distance score should be returned rather
81 # than the similarity score
82 if( defined $params->{"original"} ) { $originaloption = 1; }
83  
84 return $self;
85 }
86  
87  
88 sub getRelatedness
89 {
90 my $self = shift;
91 return undef if(!defined $self || !ref $self);
92 my $concept1 = shift;
93 my $concept2 = shift;
94  
95 # if concept 1 and 2 are the same just return 1
96 if($concept1 eq $concept2) { return 1; }
97  
98 # set up the interface
99 my $interface = $self->{'interface'};
100
101 # get the shortest path between the concepts
102 my $length = $interface->findShortestPathLength($concept1, $concept2);
103
104 # if there are no paths return nothing
105 if($length < 0) { return -1; }
106  
107 if(defined $originaloption) {
108 return $length;
109 }
110 else {
111 return (1/$length);
112 }
113 }
114  
115 1;
116 __END__