Wikibase::Datatype::Struct::Sense - Wikibase sense structure serialization.
use Wikibase::Datatype::Struct::Sense qw(obj2struct struct2obj); my $struct_hr = obj2struct($obj, $base_uri); my $obj = struct2obj($struct_hr);
This conversion is between objects defined in Wikibase::Datatype and structures serialized via JSON to MediaWiki.
obj2struct
my $struct_hr = obj2struct($obj, $base_uri);
Convert Wikibase::Datatype::Sense instance to structure. $base_uri is base URI of Wikibase system (e.g. http://test.wikidata.org/entity/).
$base_uri
Returns reference to hash with structure.
struct2obj
my $obj = struct2obj($struct_hr);
Convert structure of sense to object.
Returns Wikibase::Datatype::Sense instance.
obj2struct(): Base URI is required. Object doesn't exist. Object isn't 'Wikibase::Datatype::Sense'.
use strict; use warnings; use Data::Printer; use Wikibase::Datatype::Sense; use Wikibase::Datatype::Snak; use Wikibase::Datatype::Statement; use Wikibase::Datatype::Struct::Sense qw(obj2struct); 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 structure. my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/'); # Dump to output. p $struct_hr; # Output: # \ { # glosses { # cs { # language "cs", # value "Glosse cs" # }, # en { # language "en", # value "Glosse en" # } # }, # id "ID", # claims { # P31 [ # [0] { # mainsnak { # datatype "wikibase-item", # datavalue { # type "wikibase-entityid", # value { # entity-type "item", # id "Q5", # numeric-id 5 # } # }, # property "P31", # snaktype "value" # }, # rank "normal", # type "statement" # } # ] # } # }
use strict; use warnings; use Data::Printer; use Wikibase::Datatype::Struct::Sense qw(struct2obj); # Item structure. my $struct_hr = { 'glosses' => { 'cs' => { 'language' => 'cs', 'value' => 'Glosse cs', }, 'en' => { 'language' => 'en', 'value' => 'Glosse en', }, }, 'id' => 'ID', 'claims' => { 'P31' => [{ 'mainsnak' => { 'datatype' => 'wikibase-item', 'datavalue' => { 'type' => 'wikibase-entityid', 'value' => { 'entity-type' => 'item', 'id' => 'Q5', 'numeric-id' => 5, }, }, 'property' => 'P31', 'snaktype' => 'value', }, 'rank' => 'normal', 'type' => 'statement', }], }, }; # Get object. my $obj = struct2obj($struct_hr); # Dump object. p $obj; # Output: # Wikibase::Datatype::Sense { # Parents Mo::Object # public methods (7) : BUILD, can (UNIVERSAL), DOES (UNIVERSAL), check_array_object (Mo::utils), check_number_of_items (Mo::utils), isa (UNIVERSAL), VERSION (UNIVERSAL) # private methods (1) : __ANON__ (Mo) # internals: { # glosses [ # [0] Wikibase::Datatype::Value::Monolingual, # [1] Wikibase::Datatype::Value::Monolingual # ], # id "ID", # statements [ # [0] Wikibase::Datatype::Statement # ] # } # }
Error::Pure, Exporter, Readonly, Wikibase::Datatype::Sense, Wikibase::Datatype::Struct::Language, Wikibase::Datatype::Struct::Statement.
Wikibase structure serialization.
Wikibase sense datatype.
https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2020-2023 Michal Josef Špaček
BSD 2-Clause License
0.11
To install Wikibase::Datatype::Struct, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Wikibase::Datatype::Struct
CPAN shell
perl -MCPAN -e shell install Wikibase::Datatype::Struct
For more information on module installation, please visit the detailed CPAN module installation guide.