line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Treex::PML::Alt; |
3
|
6
|
|
|
6
|
|
42
|
use Carp; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
292
|
|
4
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
148
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
28
|
use vars qw($VERSION); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
235
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
6
|
|
|
6
|
|
131
|
$VERSION='2.24'; # version template |
9
|
|
|
|
|
|
|
} |
10
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
2604
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Treex::PML::Alt - an alternative of uniformly typed PML values |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This class implements the attribute value type 'alternative'. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=over 4 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item Treex::PML::Alt->new (value1,value2,...) |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Create a new alternative (optionally populated with given values). |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
NOTE: Don't call this constructor directly, use Treex::PML::Factory->createAlt() instead! |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
35
|
0
|
|
|
|
|
|
return bless [@_],$class; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item Treex::PML::Alt->new_from_ref (array_ref, reuse) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Create a new alternative consisting of values in a given array |
42
|
|
|
|
|
|
|
reference. If reuse is true, then the same array_ref scalar is reused |
43
|
|
|
|
|
|
|
to represent the Treex::PML::Alt object (i.e. blessed). Otherwise, a copy is |
44
|
|
|
|
|
|
|
created in the constructor. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
NOTE: Don't call this constructor directly, use Treex::PML::Factory->createAlt() instead! |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new_from_ref { |
51
|
0
|
|
|
0
|
1
|
|
my ($class,$array,$reuse) = @_; |
52
|
0
|
0
|
|
|
|
|
if ($reuse) { |
53
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($array,'ARRAY')) { |
54
|
0
|
|
|
|
|
|
return bless $array,$class; |
55
|
|
|
|
|
|
|
} else { |
56
|
0
|
|
|
|
|
|
croak("Usage: new_from_ref(ARRAY_REF,1) - arg 1 is not an ARRAY reference!"); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} else { |
59
|
0
|
|
|
|
|
|
return bless [@$array],$class; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item $alt->values () |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Retrurns a its values (i.e. the alternatives). |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub values { |
71
|
0
|
|
|
0
|
1
|
|
return @{$_[0]}; |
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item $alt->count () |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Retrurn number of values in the alternative. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub count { |
81
|
0
|
|
|
0
|
1
|
|
return scalar(@{$_[0]}); |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item $alt->add (@values) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Add given values to the alternative. Only values which are not already |
87
|
|
|
|
|
|
|
included in the alternative are added. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub add { |
92
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
93
|
0
|
|
|
|
|
|
$self->add_list(\@_); |
94
|
0
|
|
|
|
|
|
return $self; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item $alt->add_list ($list) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Add values of the given list to the alternative. Only values which are |
100
|
|
|
|
|
|
|
not already included in the alternative are added. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub add_list { |
105
|
0
|
0
|
|
0
|
1
|
|
die 'Usage: Treex::PML::Alt->add_list() (wrong number of arguments!)' |
106
|
|
|
|
|
|
|
if @_!=2; |
107
|
0
|
|
|
|
|
|
my $self = shift; |
108
|
0
|
|
|
|
|
|
my $list = shift; |
109
|
0
|
|
|
|
|
|
my %a; @a{ @$self } = (); |
|
0
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
push @{$self}, grep { exists($a{$_}) ? 0 : ($a{$_}=1) } @$list; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $self; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item $alt->delete_value ($value) |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Delete all occurences of value $value. Values are compared as strings. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub delete_value { |
121
|
0
|
0
|
|
0
|
1
|
|
die 'Usage: Treex::PML::Alt->delete_value($value) (wrong number of arguments!)' |
122
|
|
|
|
|
|
|
if @_!=2; |
123
|
0
|
|
|
|
|
|
my ($self,$value) = @_; |
124
|
0
|
|
|
|
|
|
@$self = grep { $_ ne $value } @$self; |
|
0
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return $self; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item $alt->delete_values ($value1,$value2,...) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Delete all occurences of values $value1, $value2,... Values are |
131
|
|
|
|
|
|
|
compared as strings. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub delete_values { |
136
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
137
|
0
|
|
|
|
|
|
my %d; %d = @_; |
|
0
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
@$self = grep { !exists($d{$_}) } @$self; |
|
0
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return $self; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item $list->empty () |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Remove all values from the alternative. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub empty { |
149
|
0
|
0
|
|
0
|
1
|
|
die 'Usage: Treex::PML::Alt->empty() (wrong number of arguments!)' |
150
|
|
|
|
|
|
|
if @_!=1; |
151
|
0
|
|
|
|
|
|
my $self = shift; |
152
|
0
|
|
|
|
|
|
@$self=(); |
153
|
0
|
|
|
|
|
|
return $self; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L, L, L, L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright (C) 2006-2010 by Petr Pajas |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
167
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.2 or, |
168
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |