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-2015 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
|
|
7443
|
use OBO::Util::Set; |
|
16
|
|
|
|
|
30
|
|
|
16
|
|
|
|
|
406
|
|
14
|
|
|
|
|
|
|
|
15
|
16
|
|
|
16
|
|
105
|
use strict; |
|
16
|
|
|
|
|
29
|
|
|
16
|
|
|
|
|
327
|
|
16
|
16
|
|
|
16
|
|
82
|
use warnings; |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
7090
|
|
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
|
11
|
my $self = shift; |
28
|
4
|
|
|
|
|
7
|
my $result = undef; |
29
|
4
|
50
|
|
|
|
14
|
if (@_) { |
30
|
4
|
|
|
|
|
6
|
my $ele = shift; |
31
|
4
|
100
|
|
|
|
17
|
if ($self->size() > 0) { |
32
|
3
|
|
|
|
|
7
|
for (my $i = 0; $i < scalar(@{$self->{SET}}); $i++){ |
|
7
|
|
|
|
|
23
|
|
33
|
7
|
|
|
|
|
9
|
my $e = ${$self->{SET}}[$i]; |
|
7
|
|
|
|
|
12
|
|
34
|
7
|
100
|
|
|
|
22
|
if ($ele->equals($e)) { |
35
|
3
|
100
|
|
|
|
9
|
if ($self->size() > 1) { |
|
|
50
|
|
|
|
|
|
36
|
2
|
|
|
|
|
4
|
my $first_elem = shift (@{$self->{SET}}); |
|
2
|
|
|
|
|
4
|
|
37
|
2
|
|
|
|
|
4
|
${$self->{SET}}[$i-1] = $first_elem; |
|
2
|
|
|
|
|
6
|
|
38
|
|
|
|
|
|
|
} elsif ($self->size() == 1) { |
39
|
1
|
|
|
|
|
2
|
shift (@{$self->{SET}}); |
|
1
|
|
|
|
|
3
|
|
40
|
|
|
|
|
|
|
} |
41
|
3
|
|
|
|
|
5
|
$result = $ele; |
42
|
3
|
|
|
|
|
5
|
last; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
4
|
|
|
|
|
10
|
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
|
2223
|
|
|
2223
|
1
|
3636
|
my $self = shift; |
61
|
2223
|
|
|
|
|
2724
|
my $result = 0; |
62
|
2223
|
50
|
|
|
|
4914
|
if (@_){ |
63
|
2223
|
|
|
|
|
2852
|
my $target = shift; |
64
|
|
|
|
|
|
|
|
65
|
2223
|
|
|
|
|
2787
|
foreach my $ele (@{$self->{SET}}){ |
|
2223
|
|
|
|
|
4819
|
|
66
|
3865
|
100
|
|
|
|
10007
|
if ($target->equals($ele)) { |
67
|
46
|
|
|
|
|
65
|
$result = 1; |
68
|
46
|
|
|
|
|
102
|
last; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
2223
|
|
|
|
|
6833
|
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
|
14
|
my $self = shift; |
85
|
5
|
|
|
|
|
10
|
my $result = 0; # I guess they'are NOT identical |
86
|
5
|
50
|
|
|
|
17
|
if (@_) { |
87
|
5
|
|
|
|
|
9
|
my $other_set = shift; |
88
|
|
|
|
|
|
|
|
89
|
5
|
|
|
|
|
13
|
my %count = (); |
90
|
|
|
|
|
|
|
|
91
|
5
|
|
|
|
|
7
|
my @this = map ({scalar $_->def_as_string();} @{$self->{SET}}); |
|
24
|
|
|
|
|
68
|
|
|
5
|
|
|
|
|
17
|
|
92
|
5
|
|
|
|
|
21
|
my @that = map ({scalar $_->def_as_string();} $other_set->get_set()); |
|
20
|
|
|
|
|
53
|
|
93
|
|
|
|
|
|
|
|
94
|
5
|
100
|
|
|
|
22
|
if ($#this == $#that) { |
95
|
4
|
|
|
|
|
8
|
foreach (@this, @that) { |
96
|
40
|
|
|
|
|
86
|
$count{$_}++; |
97
|
|
|
|
|
|
|
} |
98
|
4
|
|
|
|
|
19
|
foreach my $count (sort values %count) { |
99
|
20
|
50
|
|
|
|
33
|
if ($count != 2) { |
100
|
0
|
|
|
|
|
0
|
$result = 0; |
101
|
0
|
|
|
|
|
0
|
last; |
102
|
|
|
|
|
|
|
} else { |
103
|
20
|
|
|
|
|
41
|
$result = 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
5
|
|
|
|
|
21
|
return $result; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |