line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Print::Sense; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
346835
|
use base qw(Exporter); |
|
7
|
|
|
|
|
48
|
|
|
7
|
|
|
|
|
690
|
|
4
|
7
|
|
|
7
|
|
49
|
use strict; |
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
181
|
|
5
|
7
|
|
|
7
|
|
37
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
245
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
1380
|
use Error::Pure qw(err); |
|
7
|
|
|
|
|
23539
|
|
|
7
|
|
|
|
|
242
|
|
8
|
7
|
|
|
7
|
|
184
|
use Readonly; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
288
|
|
9
|
7
|
|
|
7
|
|
1878
|
use Wikibase::Datatype::Print::Statement; |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
315
|
|
10
|
7
|
|
|
7
|
|
46
|
use Wikibase::Datatype::Print::Utils qw(print_glosses print_statements); |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
317
|
|
11
|
7
|
|
|
7
|
|
43
|
use Wikibase::Datatype::Print::Value::Monolingual; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
1405
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(print); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.13; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub print { |
18
|
4
|
|
|
4
|
1
|
6195
|
my ($obj, $opts_hr) = @_; |
19
|
|
|
|
|
|
|
|
20
|
4
|
100
|
|
|
|
30
|
if (! $obj->isa('Wikibase::Datatype::Sense')) { |
21
|
1
|
|
|
|
|
5
|
err "Object isn't 'Wikibase::Datatype::Sense'."; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Id. |
25
|
3
|
|
|
|
|
36
|
my @ret = ( |
26
|
|
|
|
|
|
|
'Id: '.$obj->id, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Glosses. |
30
|
3
|
|
|
|
|
37
|
push @ret, print_glosses($obj, $opts_hr, |
31
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Value::Monolingual::print); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Statements. |
34
|
3
|
|
|
|
|
15
|
push @ret, print_statements($obj, $opts_hr, |
35
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Statement::print); |
36
|
|
|
|
|
|
|
|
37
|
3
|
100
|
|
|
|
18
|
return wantarray ? @ret : (join "\n", @ret); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding utf8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Wikibase::Datatype::Print::Sense - Wikibase sense pretty print helpers. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 SYNOPSIS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Sense qw(print); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
57
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SUBROUTINES |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 C<print> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
64
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Construct pretty print output for L<Wikibase::Datatype::Sense> |
67
|
|
|
|
|
|
|
object. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Returns string in scalar context. |
70
|
|
|
|
|
|
|
Returns list of lines in array context. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 ERRORS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
print(): |
75
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Sense'. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 EXAMPLE |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=for comment filename=create_and_print_sense.pl |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use strict; |
82
|
|
|
|
|
|
|
use warnings; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use Unicode::UTF8 qw(decode_utf8 encode_utf8); |
85
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Sense; |
86
|
|
|
|
|
|
|
use Wikibase::Datatype::Sense; |
87
|
|
|
|
|
|
|
use Wikibase::Datatype::Snak; |
88
|
|
|
|
|
|
|
use Wikibase::Datatype::Statement; |
89
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Item; |
90
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Monolingual; |
91
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::String; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# One sense for Czech noun 'pes'. |
94
|
|
|
|
|
|
|
# https://www.wikidata.org/wiki/Lexeme:L469 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Statements. |
97
|
|
|
|
|
|
|
my $statement_item = Wikibase::Datatype::Statement->new( |
98
|
|
|
|
|
|
|
# item for this sense (P5137) dog (Q144) |
99
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Snak->new( |
100
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
101
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
102
|
|
|
|
|
|
|
'value' => 'Q144', |
103
|
|
|
|
|
|
|
), |
104
|
|
|
|
|
|
|
'property' => 'P5137', |
105
|
|
|
|
|
|
|
), |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
my $statement_image = Wikibase::Datatype::Statement->new( |
108
|
|
|
|
|
|
|
# image (P5137) 'Canadian Inuit Dog.jpg' |
109
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Snak->new( |
110
|
|
|
|
|
|
|
'datatype' => 'commonsMedia', |
111
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::String->new( |
112
|
|
|
|
|
|
|
'value' => 'Canadian Inuit Dog.jpg', |
113
|
|
|
|
|
|
|
), |
114
|
|
|
|
|
|
|
'property' => 'P18', |
115
|
|
|
|
|
|
|
), |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Object. |
119
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Sense->new( |
120
|
|
|
|
|
|
|
'glosses' => [ |
121
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
122
|
|
|
|
|
|
|
'language' => 'en', |
123
|
|
|
|
|
|
|
'value' => 'domesticated mammal related to the wolf', |
124
|
|
|
|
|
|
|
), |
125
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
126
|
|
|
|
|
|
|
'language' => 'cs', |
127
|
|
|
|
|
|
|
'value' => decode_utf8('psovitá šelma chovaná jako domácí zvíře'), |
128
|
|
|
|
|
|
|
), |
129
|
|
|
|
|
|
|
], |
130
|
|
|
|
|
|
|
'id' => 'ID', |
131
|
|
|
|
|
|
|
'statements' => [ |
132
|
|
|
|
|
|
|
$statement_item, |
133
|
|
|
|
|
|
|
$statement_image, |
134
|
|
|
|
|
|
|
], |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Print. |
138
|
|
|
|
|
|
|
print encode_utf8(scalar Wikibase::Datatype::Print::Sense::print($obj))."\n"; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Output: |
141
|
|
|
|
|
|
|
# Id: ID |
142
|
|
|
|
|
|
|
# Glosses: |
143
|
|
|
|
|
|
|
# domesticated mammal related to the wolf (en) |
144
|
|
|
|
|
|
|
# psovitá šelma chovaná jako domácí zvíře (cs) |
145
|
|
|
|
|
|
|
# Statements: |
146
|
|
|
|
|
|
|
# P5137: Q144 (normal) |
147
|
|
|
|
|
|
|
# P18: Canadian Inuit Dog.jpg (normal) |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L<Error::Pure>, |
152
|
|
|
|
|
|
|
L<Exporter>, |
153
|
|
|
|
|
|
|
L<Readonly>, |
154
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Statement>, |
155
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Utils>, |
156
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Value::Monolingual>. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=over |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Sense> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Wikibase sense datatype. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 REPOSITORY |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L<http://skim.cz> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
© 2020-2023 Michal Josef Špaček |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
BSD 2-Clause License |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 VERSION |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
0.13 |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|