line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: SynonymSet.pm 2014-09-29 erick.antezana $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Module : SynonymSet.pm |
4
|
|
|
|
|
|
|
# Purpose : Synonym set. |
5
|
|
|
|
|
|
|
# License : Copyright (c) 2006-2014 by Erick Antezana. All rights reserved. |
6
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
7
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
# Contact : Erick Antezana |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
package OBO::Util::SynonymSet; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(OBO::Util::Set); |
13
|
16
|
|
|
16
|
|
4836
|
use OBO::Util::Set; |
|
16
|
|
|
|
|
19
|
|
|
16
|
|
|
|
|
446
|
|
14
|
|
|
|
|
|
|
|
15
|
16
|
|
|
16
|
|
86
|
use strict; |
|
16
|
|
|
|
|
20
|
|
|
16
|
|
|
|
|
369
|
|
16
|
16
|
|
|
16
|
|
53
|
use warnings; |
|
16
|
|
|
|
|
17
|
|
|
16
|
|
|
|
|
5253
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head2 remove |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Usage - $set->remove($element) |
21
|
|
|
|
|
|
|
Returns - the removed element |
22
|
|
|
|
|
|
|
Args - the element (OBO::Core::Synonym) to be removed |
23
|
|
|
|
|
|
|
Function - removes an element from this set |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
sub remove { |
27
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
28
|
4
|
|
|
|
|
6
|
my $result = undef; |
29
|
4
|
50
|
|
|
|
11
|
if (@_) { |
30
|
4
|
|
|
|
|
3
|
my $ele = shift; |
31
|
4
|
100
|
|
|
|
13
|
if ($self->size() > 0) { |
32
|
3
|
|
|
|
|
7
|
for (my $i = 0; $i < scalar(@{$self->{SET}}); $i++){ |
|
7
|
|
|
|
|
13
|
|
33
|
7
|
|
|
|
|
8
|
my $e = ${$self->{SET}}[$i]; |
|
7
|
|
|
|
|
10
|
|
34
|
7
|
100
|
|
|
|
13
|
if ($ele->equals($e)) { |
35
|
3
|
100
|
|
|
|
49
|
if ($self->size() > 1) { |
|
|
50
|
|
|
|
|
|
36
|
2
|
|
|
|
|
2
|
my $first_elem = shift (@{$self->{SET}}); |
|
2
|
|
|
|
|
3
|
|
37
|
2
|
|
|
|
|
4
|
${$self->{SET}}[$i-1] = $first_elem; |
|
2
|
|
|
|
|
5
|
|
38
|
|
|
|
|
|
|
} elsif ($self->size() == 1) { |
39
|
1
|
|
|
|
|
2
|
shift (@{$self->{SET}}); |
|
1
|
|
|
|
|
1
|
|
40
|
|
|
|
|
|
|
} |
41
|
3
|
|
|
|
|
5
|
$result = $ele; |
42
|
3
|
|
|
|
|
5
|
last; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
4
|
|
|
|
|
7
|
return $result; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 contains |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Usage - $set->contains() |
54
|
|
|
|
|
|
|
Returns - true if this set contains the given element |
55
|
|
|
|
|
|
|
Args - the element (OBO::Core::Synonym) to be checked |
56
|
|
|
|
|
|
|
Function - checks if this set constains the given element |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
sub contains { |
60
|
2217
|
|
|
2217
|
1
|
2153
|
my $self = shift; |
61
|
2217
|
|
|
|
|
1916
|
my $result = 0; |
62
|
2217
|
50
|
|
|
|
3272
|
if (@_){ |
63
|
2217
|
|
|
|
|
1681
|
my $target = shift; |
64
|
|
|
|
|
|
|
|
65
|
2217
|
|
|
|
|
1630
|
foreach my $ele (@{$self->{SET}}){ |
|
2217
|
|
|
|
|
3383
|
|
66
|
3850
|
100
|
|
|
|
6047
|
if ($target->equals($ele)) { |
67
|
46
|
|
|
|
|
40
|
$result = 1; |
68
|
46
|
|
|
|
|
57
|
last; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
2217
|
|
|
|
|
4966
|
return $result; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 equals |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Usage - $set->equals() |
78
|
|
|
|
|
|
|
Returns - true or false |
79
|
|
|
|
|
|
|
Args - the set (OBO::Util::SynonymSet) to compare with |
80
|
|
|
|
|
|
|
Function - tells whether this set is equal to the given one |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
sub equals { |
84
|
5
|
|
|
5
|
1
|
7
|
my $self = shift; |
85
|
5
|
|
|
|
|
6
|
my $result = 0; # I guess they'are NOT identical |
86
|
5
|
50
|
|
|
|
11
|
if (@_) { |
87
|
5
|
|
|
|
|
5
|
my $other_set = shift; |
88
|
|
|
|
|
|
|
|
89
|
5
|
|
|
|
|
8
|
my %count = (); |
90
|
|
|
|
|
|
|
|
91
|
5
|
|
|
|
|
6
|
my @this = map ({scalar $_->def_as_string();} @{$self->{SET}}); |
|
24
|
|
|
|
|
40
|
|
|
5
|
|
|
|
|
9
|
|
92
|
5
|
|
|
|
|
15
|
my @that = map ({scalar $_->def_as_string();} $other_set->get_set()); |
|
20
|
|
|
|
|
37
|
|
93
|
|
|
|
|
|
|
|
94
|
5
|
100
|
|
|
|
16
|
if ($#this == $#that) { |
95
|
4
|
|
|
|
|
7
|
foreach (@this, @that) { |
96
|
40
|
|
|
|
|
56
|
$count{$_}++; |
97
|
|
|
|
|
|
|
} |
98
|
4
|
|
|
|
|
17
|
foreach my $count (sort values %count) { |
99
|
20
|
50
|
|
|
|
22
|
if ($count != 2) { |
100
|
0
|
|
|
|
|
0
|
$result = 0; |
101
|
0
|
|
|
|
|
0
|
last; |
102
|
|
|
|
|
|
|
} else { |
103
|
20
|
|
|
|
|
32
|
$result = 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
5
|
|
|
|
|
17
|
return $result; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |