File Coverage

blib/lib/Wikibase/Datatype/Lexeme.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 38 39 97.4


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Lexeme;
2              
3 18     18   305066 use strict;
  18         40  
  18         1299  
4 18     18   104 use warnings;
  18         39  
  18         1626  
5              
6 18     18   9787 use Error::Pure qw(err);
  18         273927  
  18         578  
7 18     18   11604 use Mo qw(build default is);
  18         12877  
  18         118  
8 18     18   63651 use Mo::utils qw(check_number);
  18         63219  
  18         493  
9 18     18   13137 use Mo::utils::Array qw(check_array_object);
  18         52982  
  18         542  
10 18     18   14194 use Wikibase::Datatype::Utils qw(check_entity);
  18         101  
  18         513  
11              
12             our $VERSION = 0.39;
13              
14             has forms => (
15             default => [],
16             is => 'ro',
17             );
18              
19             has id => (
20             is => 'ro',
21             );
22              
23             has language => (
24             is => 'ro',
25             );
26              
27             has lastrevid => (
28             is => 'ro',
29             );
30              
31             has lemmas => (
32             default => [],
33             is => 'ro',
34             );
35              
36             has lexical_category => (
37             is => 'ro',
38             );
39              
40             has modified => (
41             is => 'ro',
42             );
43              
44             has ns => (
45             default => 146,
46             is => 'ro',
47             );
48              
49             has page_id => (
50             is => 'ro',
51             );
52              
53             has senses => (
54             default => [],
55             is => 'ro',
56             );
57              
58             has statements => (
59             default => [],
60             is => 'ro',
61             );
62              
63             has title => (
64             is => 'ro',
65             );
66              
67             sub BUILD {
68 27     27 0 3914256 my $self = shift;
69              
70             # Check forms.
71 27         179 check_array_object($self, 'forms', 'Wikibase::Datatype::Form');
72              
73             # Check lemmas.
74 27         911 check_array_object($self, 'lemmas', 'Wikibase::Datatype::Value::Monolingual');
75              
76             # Check lexical category.
77 27         804 check_entity($self, 'lexical_category');
78              
79             # Check language.
80 27         103 check_entity($self, 'language');
81              
82             # Check page id.
83 27         179 check_number($self, 'page_id');
84              
85             # Check senses.
86 27         547 check_array_object($self, 'senses', 'Wikibase::Datatype::Sense');
87              
88             # Check statements.
89 27         657 check_array_object($self, 'statements', 'Wikibase::Datatype::Statement');
90              
91 27         530 return;
92             }
93              
94             1;
95              
96             __END__
97              
98             =pod
99              
100             =encoding utf8
101              
102             =head1 NAME
103              
104             Wikibase::Datatype::Lexeme - Wikibase lexeme datatype.
105              
106             =head1 SYNOPSIS
107              
108             use Wikibase::Datatype::Lexeme;
109              
110             my $obj = Wikibase::Datatype::Lexeme->new(%params);
111             my $forms_ar = $obj->forms;
112             my $id = $obj->id;
113             my $language = $obj->language;
114             my $lastrevid = $obj->lastrevid;
115             my $lemmas_ar = $obj->lemmas;
116             my $lexical_category = $obj->lexical_category;
117             my $modified = $obj->modified;
118             my $ns = $obj->ns;
119             my $page_id = $obj->page_id;
120             my $senses_ar = $obj->senses;
121             my $statements_ar = $obj->statements;
122             my $title = $obj->title;
123              
124             =head1 DESCRIPTION
125              
126             This datatype is item class for representing claim.
127              
128             =head1 METHODS
129              
130             =head2 C<new>
131              
132             my $obj = Wikibase::Datatype::Lexeme->new(%params);
133              
134             Constructor.
135              
136             Returns instance of object.
137              
138             =over 8
139              
140             =item * C<forms>
141              
142             Forms.
143             Reference to array with Wikibase::Datatype::Form instances.
144             Parameter is optional.
145              
146             =item * C<id>
147              
148             Id.
149             Parameter is optional.
150              
151             =item * C<language>
152              
153             Language. Link to QID.
154             Parameter is optional.
155              
156             =item * C<lastrevid>
157              
158             Last revision ID.
159             Parameter is optional.
160              
161             =item * C<lemmas>
162              
163             Lemmas.
164             Reference to array with Wikibase::Datatype::Value::Monolingual instances.
165             Parameter is optional.
166              
167             =item * C<lexical_category>
168              
169             Lexical category. Link to QID.
170             Parameter is optional.
171              
172             =item * C<modified>
173              
174             Date of modification.
175             Parameter is optional.
176              
177             =item * C<ns>
178              
179             Namespace.
180             Default value is 146.
181              
182             =item * C<page_id>
183              
184             Page id. Numeric value.
185             Parameter is optional.
186              
187             =item * C<senses>
188              
189             Senses.
190             Reference to array with Wikibase::Datatype::Sense instances.
191             Parameter is optional.
192              
193             =item * C<statements>
194              
195             Item statements.
196             Reference to array with Wikibase::Datatype::Statement instances.
197             Parameter is optional.
198              
199             =item * C<title>
200              
201             Lexeme title.
202             Parameter is optional.
203              
204             =back
205              
206             =head2 C<forms>
207              
208             my $forms_ar = $obj->forms;
209              
210             Get forms.
211              
212             Returns reference to array with Wikibase::Datatype::Form instances.
213              
214             =head2 C<id>
215              
216             my $id = $obj->id;
217              
218             Get id.
219              
220             Returns string.
221              
222             =head2 C<language>
223              
224             my $language = $obj->language;
225              
226             Get language.
227              
228             Returns string with QID.
229              
230             =head2 C<lastrevid>
231              
232             my $lastrevid = $obj->lastrevid;
233              
234             Get last revision ID.
235              
236             Returns string.
237              
238             =head2 C<lemmas>
239              
240             my $lemmas_ar = $obj->lemmas;
241              
242             Get lemmas.
243              
244             Returns reference to array with Wikibase::Datatype::Value::Monolingual instances.
245              
246             =head2 C<lexical_category>
247              
248             my $lexical_category = $obj->lexical_category;
249              
250             Get lexical category.
251              
252             Returns string with QID.
253              
254             =head2 C<modified>
255              
256             my $modified = $obj->modified;
257              
258             Get date of modification.
259              
260             Returns string.
261              
262             =head2 C<ns>
263              
264             my $ns = $obj->ns;
265              
266             Get namespace.
267              
268             Returns number.
269              
270             =head2 C<page_id>
271              
272             my $page_id = $obj->page_id;
273              
274             Get page id.
275              
276             Returns number.
277              
278             =head2 C<senses>
279              
280             my $senses_ar = $obj->senses;
281              
282             Get senses.
283              
284             Returns reference to array with Wikibase::Datatype::Sense instances.
285              
286             =head2 C<statements>
287              
288             my $statements_ar = $obj->statements;
289              
290             Get statements.
291              
292             Returns reference to array with Wikibase::Datatype::Statement instances.
293              
294             =head2 C<title>
295              
296             my $title = $obj->title;
297              
298             Get title.
299              
300             Returns string.
301              
302             =head1 ERRORS
303              
304             new():
305             From Wikibase::Datatype::Utils::check_entity():
306             Parameter 'language' must begin with 'Q' and number after it.";
307             Parameter 'lexical_category' must begin with 'Q' and number after it.";
308              
309             From Mo::utils::Array::check_array_object():
310             Parameter 'forms' must be a array.
311             Value: %s
312             Reference: %s
313             Parameter 'forms' with array must contain 'Wikibase::Datatype::Form' objects.
314             Value: %s
315             Reference: %s
316             Parameter 'lemmas' must be a array.
317             Value: %s
318             Reference: %s
319             Parameter 'lemmas' with array must contain 'Wikibase::Datatype::Value::Monolingual' objects.
320             Value: %s
321             Reference: %s
322             Parameter 'senses' must be a array.
323             Value: %s
324             Reference: %s
325             Parameter 'senses' with array must contain 'Wikibase::Datatype::Sense' objects.
326             Value: %s
327             Reference: %s
328             Parameter 'statements' must be a array.
329             Value: %s
330             Reference: %s
331             Parameter 'statements' with array must contain 'Wikibase::Datatype::Statement' objects.
332             Value: %s
333             Reference: %s
334              
335             =head1 EXAMPLE
336              
337             =for comment filename=create_and_print_lexeme.pl
338              
339             use strict;
340             use warnings;
341              
342             use Wikibase::Datatype::Lexeme;
343             use Wikibase::Datatype::Reference;
344             use Wikibase::Datatype::Snak;
345             use Wikibase::Datatype::Statement;
346             use Wikibase::Datatype::Value::Item;
347             use Wikibase::Datatype::Value::Monolingual;
348             use Wikibase::Datatype::Value::String;
349             use Wikibase::Datatype::Value::Time;
350              
351             # Statements.
352             my $statement1 = Wikibase::Datatype::Statement->new(
353             # instance of (P31) human (Q5)
354             'snak' => Wikibase::Datatype::Snak->new(
355             'datatype' => 'wikibase-item',
356             'datavalue' => Wikibase::Datatype::Value::Item->new(
357             'value' => 'Q5',
358             ),
359             'property' => 'P31',
360             ),
361             'property_snaks' => [
362             # of (P642) alien (Q474741)
363             Wikibase::Datatype::Snak->new(
364             'datatype' => 'wikibase-item',
365             'datavalue' => Wikibase::Datatype::Value::Item->new(
366             'value' => 'Q474741',
367             ),
368             'property' => 'P642',
369             ),
370             ],
371             'references' => [
372             Wikibase::Datatype::Reference->new(
373             'snaks' => [
374             # stated in (P248) Virtual International Authority File (Q53919)
375             Wikibase::Datatype::Snak->new(
376             'datatype' => 'wikibase-item',
377             'datavalue' => Wikibase::Datatype::Value::Item->new(
378             'value' => 'Q53919',
379             ),
380             'property' => 'P248',
381             ),
382              
383             # VIAF ID (P214) 113230702
384             Wikibase::Datatype::Snak->new(
385             'datatype' => 'external-id',
386             'datavalue' => Wikibase::Datatype::Value::String->new(
387             'value' => '113230702',
388             ),
389             'property' => 'P214',
390             ),
391              
392             # retrieved (P813) 7 December 2013
393             Wikibase::Datatype::Snak->new(
394             'datatype' => 'time',
395             'datavalue' => Wikibase::Datatype::Value::Time->new(
396             'value' => '+2013-12-07T00:00:00Z',
397             ),
398             'property' => 'P813',
399             ),
400             ],
401             ),
402             ],
403             );
404             my $statement2 = Wikibase::Datatype::Statement->new(
405             # sex or gender (P21) male (Q6581097)
406             'snak' => Wikibase::Datatype::Snak->new(
407             'datatype' => 'wikibase-item',
408             'datavalue' => Wikibase::Datatype::Value::Item->new(
409             'value' => 'Q6581097',
410             ),
411             'property' => 'P21',
412             ),
413             'references' => [
414             Wikibase::Datatype::Reference->new(
415             'snaks' => [
416             # stated in (P248) Virtual International Authority File (Q53919)
417             Wikibase::Datatype::Snak->new(
418             'datatype' => 'wikibase-item',
419             'datavalue' => Wikibase::Datatype::Value::Item->new(
420             'value' => 'Q53919',
421             ),
422             'property' => 'P248',
423             ),
424              
425             # VIAF ID (P214) 113230702
426             Wikibase::Datatype::Snak->new(
427             'datatype' => 'external-id',
428             'datavalue' => Wikibase::Datatype::Value::String->new(
429             'value' => '113230702',
430             ),
431             'property' => 'P214',
432             ),
433              
434             # retrieved (P813) 7 December 2013
435             Wikibase::Datatype::Snak->new(
436             'datatype' => 'time',
437             'datavalue' => Wikibase::Datatype::Value::Time->new(
438             'value' => '+2013-12-07T00:00:00Z',
439             ),
440             'property' => 'P813',
441             ),
442             ],
443             ),
444             ],
445             );
446              
447             # Object.
448             my $obj = Wikibase::Datatype::Lexeme->new(
449             'id' => 'L469',
450             'lemmas' => [
451             Wikibase::Datatype::Value::Monolingual->new(
452             'language' => 'cs',
453             'value' => 'pes',
454             ),
455             ],
456             'statements' => [
457             $statement1,
458             $statement2,
459             ],
460             'title' => 'Lexeme:L469',
461             );
462              
463             # Print out.
464             print "Title: ".$obj->title."\n";
465             print 'Id: '.$obj->id."\n";
466             print "Statements:\n";
467             foreach my $statement (@{$obj->statements}) {
468             print "\tStatement:\n";
469             print "\t\t".$statement->snak->property.' -> '.$statement->snak->datavalue->value."\n";
470             print "\t\tQualifers:\n";
471             foreach my $property_snak (@{$statement->property_snaks}) {
472             print "\t\t\t".$property_snak->property.' -> '.
473             $property_snak->datavalue->value."\n";
474             }
475             print "\t\tReferences:\n";
476             foreach my $reference (@{$statement->references}) {
477             print "\t\t\tReference:\n";
478             foreach my $reference_snak (@{$reference->snaks}) {
479             print "\t\t\t".$reference_snak->property.' -> '.
480             $reference_snak->datavalue->value."\n";
481             }
482             }
483             }
484              
485             # Output:
486             # Title: Lexeme:L469
487             # Id: L469
488             # Statements:
489             # Statement:
490             # P31 -> Q5
491             # Qualifers:
492             # P642 -> Q474741
493             # References:
494             # Reference:
495             # P248 -> Q53919
496             # P214 -> 113230702
497             # P813 -> +2013-12-07T00:00:00Z
498             # Statement:
499             # P21 -> Q6581097
500             # Qualifers:
501             # References:
502             # Reference:
503             # P248 -> Q53919
504             # P214 -> 113230702
505             # P813 -> +2013-12-07T00:00:00Z
506              
507             =head1 DEPENDENCIES
508              
509             L<Error::Pure>,
510             L<Mo>,
511             L<Mo::utils>,
512             L<Mo::utils::Array>,
513             L<Wikibase::Datatype::Utils>.
514              
515             =head1 SEE ALSO
516              
517             =over
518              
519             =item L<Wikibase::Datatype>
520              
521             Wikibase datatypes.
522              
523             =back
524              
525             =head1 REPOSITORY
526              
527             L<https://github.com/michal-josef-spacek/Wikibase-Datatype>
528              
529             =head1 AUTHOR
530              
531             Michal Josef Špaček L<mailto:skim@cpan.org>
532              
533             L<http://skim.cz>
534              
535             =head1 LICENSE AND COPYRIGHT
536              
537             © 2020-2025 Michal Josef Špaček
538              
539             BSD 2-Clause License
540              
541             =head1 VERSION
542              
543             0.39
544              
545             =cut