The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Wikibase::Datatype::Sense - Wikibase sense datatype.

SYNOPSIS

 use Wikibase::Datatype::Sense;

 my $obj = Wikibase::Datatype::Sense->new(%params);
 my $glosses_ar = $obj->glosses;
 my $id = $obj->id;
 my $statements_ar = $obj->statements;

DESCRIPTION

This datatype is snak class for representing relation between property and value.

METHODS

new

 my $obj = Wikibase::Datatype::Snak->new(%params);

Constructor.

Retruns instance of object.

  • glosses

    Item glosses. One per language. Reference to array with Wikibase::Datatype::Value::Monolingual instances. Parameter is optional.

  • id

    Id. Parameter is optional.

  • statements

    Item statements. Reference to array with Wikibase::Datatype::Statement instances. Parameter is optional.

glosses

 my $glosses_ar = $obj->glosses;

Get glosses.

Returns reference to array with Wikibase::Datatype::Value::Monolingual instances.

id

 my $id = $obj->id;

Get id.

Returns string.

statements

 my $statements_ar = $obj->statements;

Get statements.

Returns reference to array with Wikibase::Datatype::Statement instances.

ERRORS

 new():
         From Mo::utils::check_array_object():
                Glosse isn't 'Wikibase::Datatype::Value::Monolingual' object.
                Parameter 'glosses' must be a array.
                Parameter 'statements' must be a array.
                Statement isn't 'Wikibase::Datatype::Statement' object.
         From Mo::utils::check_number_of_items():
                Glosse for language '%s' has multiple values.

EXAMPLE

 use strict;
 use warnings;

 use Wikibase::Datatype::Sense;
 use Wikibase::Datatype::Snak;
 use Wikibase::Datatype::Statement;
 use Wikibase::Datatype::Value::Item;
 use Wikibase::Datatype::Value::Monolingual;

 # Statement.
 my $statement = Wikibase::Datatype::Statement->new(
         # instance of (P31) human (Q5)
         'snak' => Wikibase::Datatype::Snak->new(
                  'datatype' => 'wikibase-item',
                  'datavalue' => Wikibase::Datatype::Value::Item->new(
                          'value' => 'Q5',
                  ),
                  'property' => 'P31',
         ),
 );

 # Object.
 my $obj = Wikibase::Datatype::Sense->new(
         'glosses' => [
                 Wikibase::Datatype::Value::Monolingual->new(
                          'language' => 'en',
                          'value' => 'Glosse en',
                 ),
                 Wikibase::Datatype::Value::Monolingual->new(
                          'language' => 'cs',
                          'value' => 'Glosse cs',
                 ),
         ],
         'id' => 'ID',
         'statements' => [
                 $statement,
         ],
 );

 # Get id.
 my $id = $obj->id;

 # Get glosses.
 my @glosses = map { $_->value.' ('.$_->language.')' } @{$obj->glosses};

 # Get statements.
 my $statements_count = @{$obj->statements};

 # Print out.
 print "Id: $id\n";
 print "Glosses:\n";
 map { print "\t$_\n"; } @glosses;
 print "Number of statements: $statements_count\n";

 # Output:
 # Id: ID
 # Glosses:
 #         Glosse en (en)
 #         Glosse cs (cs)
 # Number of statements: 1

DEPENDENCIES

Mo, Mo::utils.

SEE ALSO

Wikibase::Datatype

Wikibase datatypes.

REPOSITORY

https://github.com/michal-josef-spacek/Wikibase-Datatype

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© Michal Josef Špaček 2020-2021

BSD 2-Clause License

VERSION

0.07