| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | # @File CUI.pm | ||
| 4 | # @Author andriy | ||
| 5 | # @Created Jun 27, 2016 1:16:36 PM | ||
| 6 | # | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | package CUI; | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my $class = shift;; | ||
| 14 | my $self = { | ||
| 15 | _ID => shift, | ||
| 16 | _preferredname => shift, | ||
| 17 | _strength => 0, | ||
| 18 | _pathlength => -1, | ||
| 19 | _prevCUI => 0, | ||
| 20 | _prevPredicate => 0, | ||
| 21 | |||
| 22 | }; | ||
| 23 | bless $self, $class; | ||
| 24 | return $self; | ||
| 25 | } | ||
| 26 | #returns id of cui | ||
| 27 | sub getId { | ||
| 28 | return shift->{_ID}; | ||
| 29 | } | ||
| 30 | #returns preferred name of cui | ||
| 31 | sub getPreferredName { | ||
| 32 | return shift->{_preferredname}; | ||
| 33 | } | ||
| 34 | |||
| 35 | #returns aggregate path length, -1 if vertex has not been reached | ||
| 36 | sub getPathLength(){ | ||
| 37 | return shift->{_pathlength}; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub getStrength(){ | ||
| 41 | return shift->{_strength}; | ||
| 42 | } | ||
| 43 | |||
| 44 | #updates aggregate path length | ||
| 45 | sub setPathLength(){ | ||
| 46 | my $self = shift; | ||
| 47 | $self->{_pathlength} = shift; | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | sub setPrevCUI(){ | ||
| 52 | my $self = shift; | ||
| 53 | $self->{_prevCUI} = shift; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub setStrength(){ | ||
| 57 | my $self = shift; | ||
| 58 | $self->{_strength} = shift; | ||
| 59 | } | ||
| 60 | |||
| 61 | sub getPrevCUI(){ | ||
| 62 | my $self = shift; | ||
| 63 | return $self->{_prevCUI}; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub setPrevPredicate{ | ||
| 67 | my $self = shift; | ||
| 68 | $self->{_prevPredicate} = shift; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub getPath{ | ||
| 72 | my $self = shift; | ||
| 73 | my $length = $self->{_pathlength}; | ||
| 74 | |||
| 75 | my $path = $self->getPreferredName(); | ||
| 76 | |||
| 77 | while($self->getPrevCUI()){ | ||
| 78 | $path = $self->getPrevCUI()->getPreferredName() . " ".$self->{_prevPredicate}." ".$path; | ||
| 79 | $self = $self->getPrevCUI(); | ||
| 80 | |||
| 81 | } | ||
| 82 | return $path; | ||
| 83 | } | ||
| 84 | |||
| 85 | #test method for printing | ||
| 86 | sub _print{ | ||
| 87 | my $self = shift; | ||
| 88 | print $self->{_ID} ." ".$self->{_preferredname}." ".$self. " ". $self->{_pathlength}."\n"; | ||
| 89 | } | ||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | |||
| 94 | #checks if two cui's are equivalent i.e. have the same id's | ||
| 95 | sub equals { | ||
| 96 | return shift-> {_ID}== shift-> {_ID}; | ||
| 97 | } | ||
| 98 | 1; |