The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Wikibase::Datatype::Print::Sense - Wikibase sense pretty print helpers.

SYNOPSIS

use Wikibase::Datatype::Print::Sense qw(print);

my $pretty_print_string = print($obj, $opts_hr);
my @pretty_print_lines = print($obj, $opts_hr);

SUBROUTINES

print

my $pretty_print_string = print($obj, $opts_hr);
my @pretty_print_lines = print($obj, $opts_hr);

Construct pretty print output for Wikibase::Datatype::Sense object.

Returns string in scalar context. Returns list of lines in array context.

ERRORS

print():
        From Wikibase::Datatype::Print::Utils::defaults():
                Defined text keys are bad.
        Object isn't 'Wikibase::Datatype::Sense'.

EXAMPLE

use strict;
use warnings;

use Unicode::UTF8 qw(decode_utf8 encode_utf8);
use Wikibase::Datatype::Print::Sense;
use Wikibase::Datatype::Sense;
use Wikibase::Datatype::Snak;
use Wikibase::Datatype::Statement;
use Wikibase::Datatype::Value::Item;
use Wikibase::Datatype::Value::Monolingual;
use Wikibase::Datatype::Value::String;

# One sense for Czech noun 'pes'.
# https://www.wikidata.org/wiki/Lexeme:L469

# Statements.
my $statement_item = Wikibase::Datatype::Statement->new(
        # item for this sense (P5137) dog (Q144)
        'snak' => Wikibase::Datatype::Snak->new(
                 'datatype' => 'wikibase-item',
                 'datavalue' => Wikibase::Datatype::Value::Item->new(
                         'value' => 'Q144',
                 ),
                 'property' => 'P5137',
        ),
);
my $statement_image = Wikibase::Datatype::Statement->new(
        # image (P5137) 'Canadian Inuit Dog.jpg'
        'snak' => Wikibase::Datatype::Snak->new(
                 'datatype' => 'commonsMedia',
                 'datavalue' => Wikibase::Datatype::Value::String->new(
                         'value' => 'Canadian Inuit Dog.jpg',
                 ),
                 'property' => 'P18',
        ),
);

# Object.
my $obj = Wikibase::Datatype::Sense->new(
        'glosses' => [
                Wikibase::Datatype::Value::Monolingual->new(
                         'language' => 'en',
                         'value' => 'domesticated mammal related to the wolf',
                ),
                Wikibase::Datatype::Value::Monolingual->new(
                         'language' => 'cs',
                         'value' => decode_utf8('psovitá šelma chovaná jako domácí zvíře'),
                ),
        ],
        'id' => 'ID',
        'statements' => [
                $statement_item,
                $statement_image,
        ],
);

# Print.
print encode_utf8(scalar Wikibase::Datatype::Print::Sense::print($obj))."\n";

# Output:
# Id: ID
# Glosses:
#   domesticated mammal related to the wolf (en)
#   psovitá šelma chovaná jako domácí zvíře (cs)
# Statements:
#   P5137: Q144 (normal)
#   P18: Canadian Inuit Dog.jpg (normal)

DEPENDENCIES

Error::Pure, Exporter, Readonly, Wikibase::Datatype::Print::Statement, Wikibase::Datatype::Print::Utils, Wikibase::Datatype::Print::Value::Monolingual.

SEE ALSO

Wikibase::Datatype::Sense

Wikibase sense datatype.

REPOSITORY

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

AUTHOR

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

http://skim.cz

LICENSE AND COPYRIGHT

© 2020-2024 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.17