Wikibase::Datatype::Struct::Form - Wikibase form structure serialization.
use Wikibase::Datatype::Struct::Form 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::Form 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 form to object.
Returns Wikibase::Datatype::Form instance.
obj2struct(): Base URI is required. Object doesn't exist. Object isn't 'Wikibase::Datatype::Form'.
use strict; use warnings; use Data::Printer; use Wikibase::Datatype::Form; use Wikibase::Datatype::Statement; use Wikibase::Datatype::Struct::Form qw(obj2struct); 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::Form->new( 'grammatical_features' => [ Wikibase::Datatype::Value::Item->new( 'value' => 'Q163012', ), Wikibase::Datatype::Value::Item->new( 'value' => 'Q163014', ), ], 'id' => 'ID', 'representations' => [ Wikibase::Datatype::Value::Monolingual->new( 'language' => 'en', 'value' => 'Representation en', ), Wikibase::Datatype::Value::Monolingual->new( 'language' => 'cs', 'value' => 'Representation cs', ), ], 'statements' => [ $statement, ], ); # Get structure. my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/'); # Dump to output. p $struct_hr; # Output: # \ { # 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" # } # ] # }, # grammaticalFeatures [ # [0] "Q163012", # [1] "Q163014" # ], # id "ID", # represenations { # cs { # language "cs", # value "Representation cs" # }, # en { # language "en", # value "Representation en" # } # } # }
use strict; use warnings; use Data::Printer; use Wikibase::Datatype::Struct::Form qw(struct2obj); # Item structure. my $struct_hr = { 'grammaticalFeatures' => [ 'Q163012', 'Q163014', ], 'id' => 'ID', 'representations' => { 'cs' => { 'language' => 'cs', 'value' => 'Representation cs', }, 'en' => { 'language' => 'en', 'value' => 'Representation en', }, }, '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::Form { # Parents Mo::Object # public methods (6) : BUILD, can (UNIVERSAL), DOES (UNIVERSAL), check_array_object (Mo::utils), isa (UNIVERSAL), VERSION (UNIVERSAL) # private methods (1) : __ANON__ (Mo::is) # internals: { # grammatical_features [ # [0] Wikibase::Datatype::Value::Item, # [1] Wikibase::Datatype::Value::Item # ], # id "ID", # represenations undef, # statements [ # [0] Wikibase::Datatype::Statement # ] # } # }
Error::Pure, Exporter, Readonly, Wikibase::Datatype::Form, Wikibase::Datatype::Struct::Language, Wikibase::Datatype::Struct::Statement, Wikibase::Datatype::Value::Item.
Wikibase structure serialization.
Wikibase form datatype.
https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2020-2022 Michal Josef Špaček
BSD 2-Clause License
0.09
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.