| 1 | package Wikibase::Datatype::Struct::Lexeme; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Readonly; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Wikibase::Datatype::Form; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Wikibase::Datatype::Lexeme; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Wikibase::Datatype::Struct::Form; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Wikibase::Datatype::Struct::Language; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Wikibase::Datatype::Struct::Sense; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Wikibase::Datatype::Struct::Statement; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use Wikibase::Datatype::Value::Item; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 8 | Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 8 | our $VERSION = 0.15; | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | 8 | ▶ | sub obj2struct { | ||||||||||||||||||||||||||||
|
Subroutine
obj2struct: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 22 | 8 | my ($obj, $base_uri) = @_; | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | if (! defined $obj) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 25 | 1 | err "Object doesn't exist."; | |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | if (! $obj->isa('Wikibase::Datatype::Lexeme')) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 28 | 1 | err "Object isn't 'Wikibase::Datatype::Lexeme'."; | |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | if (! defined $base_uri) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 31 | 1 | err 'Base URI is required.'; | |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | 5 | my $struct_hr = { | |||||||||||||||||||||||||||||
| 35 | 'type' => 'lexeme', | ||||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | # Forms. | ||||||||||||||||||||||||||||||
| 39 | 5 | foreach my $form (@{$obj->forms}) { | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | $struct_hr->{'forms'} //= []; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$struct_hr->{"forms"} //= []
MC/DC0%0/1
$struct_hr->{"forms"} //= []
$struct_hr->{"forms"}
Truth table50%1/2
A
A= $struct_hr->{"forms"}
| |||||||||||||||||||||||||||||||
| 41 | 1 | push @{$struct_hr->{'forms'}}, | |||||||||||||||||||||||||||||
| 42 | Wikibase::Datatype::Struct::Form::obj2struct($form, $base_uri); | ||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | # Id. | ||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | if (defined $obj->id) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 47 | 1 | $struct_hr->{'id'} = $obj->id; | |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | # Last revision id. | ||||||||||||||||||||||||||||||
| 51 | 5 | ▶ | if (defined $obj->lastrevid) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 52 | 1 | $struct_hr->{'lastrevid'} = $obj->lastrevid; | |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | # Language. | ||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | if (defined $obj->language) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 57 | 1 | $struct_hr->{'language'} = $obj->language; | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | # Lemmas. | ||||||||||||||||||||||||||||||
| 61 | 5 | foreach my $lemma (@{$obj->lemmas}) { | |||||||||||||||||||||||||||||
| 62 | 1 | $struct_hr->{'lemmas'}->{$lemma->language} | |||||||||||||||||||||||||||||
| 63 | = Wikibase::Datatype::Struct::Language::obj2struct($lemma); | ||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||
| 66 | # Lexical category. | ||||||||||||||||||||||||||||||
| 67 | 5 | ▶ | if (defined $obj->lexical_category) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 68 | 1 | $struct_hr->{'lexicalCategory'} = $obj->lexical_category; | |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||
| 71 | # Modified date. | ||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | if (defined $obj->modified) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 73 | 1 | $struct_hr->{'modified'} = $obj->modified; | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | # Namespace. | ||||||||||||||||||||||||||||||
| 77 | 5 | ▶ | if (defined $obj->ns) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 78 | 4 | $struct_hr->{'ns'} = $obj->ns; | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | # Page id. | ||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | if (defined $obj->page_id) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 83 | 1 | $struct_hr->{'pageid'} = $obj->page_id; | |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | # Senses. | ||||||||||||||||||||||||||||||
| 87 | 5 | foreach my $sense (@{$obj->senses}) { | |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | $struct_hr->{'senses'} //= []; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$struct_hr->{"senses"} //= []
MC/DC0%0/1
$struct_hr->{"senses"} //= []
$struct_hr->{"senses"}
Truth table50%1/2
A
A= $struct_hr->{"senses"}
| |||||||||||||||||||||||||||||||
| 89 | 1 | push @{$struct_hr->{'senses'}}, | |||||||||||||||||||||||||||||
| 90 | Wikibase::Datatype::Struct::Sense::obj2struct($sense, $base_uri); | ||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | # Statements. | ||||||||||||||||||||||||||||||
| 94 | 5 | foreach my $statement (@{$obj->statements}) { | |||||||||||||||||||||||||||||
| 95 | 3 | ▶ | $struct_hr->{'claims'}->{$statement->snak->property} //= []; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$struct_hr->{"claims"}{$statement->snak->property} //= []
MC/DC100%1/1
$struct_hr->{"claims"}{$statement->snak->property} //= []
$struct_hr->{"claims"}{$statement->snak->property}
Truth table100%2/2
A
A= $struct_hr->{"claims"}{$statement->snak->property}
| |||||||||||||||||||||||||||||||
| 96 | 3 | push @{$struct_hr->{'claims'}->{$statement->snak->property}}, | |||||||||||||||||||||||||||||
| 97 | Wikibase::Datatype::Struct::Statement::obj2struct($statement, $base_uri); | ||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | # Title. | ||||||||||||||||||||||||||||||
| 101 | 5 | ▶ | if (defined $obj->title) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 102 | 1 | $struct_hr->{'title'} = $obj->title; | |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | 5 | return $struct_hr; | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | 6 | ▶ | sub struct2obj { | ||||||||||||||||||||||||||||
|
Subroutine
struct2obj: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 109 | 6 | my $struct_hr = shift; | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | 6 | ▶ | if (! exists $struct_hr->{'type'} || $struct_hr->{'type'} ne 'lexeme') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "lexeme"
MC/DC100%2/2
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "lexeme"
not exists $struct_hr->{"type"}
$struct_hr->{"type"} ne "lexeme"
Truth table100%3/3
not(A) or B
A= not exists $struct_hr->{"type"}B= $struct_hr->{"type"} ne "lexeme"
| |||||||||||||||||||||||||||||||
| 112 | 2 | err "Structure isn't for 'lexeme' type."; | |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | # Forms. | ||||||||||||||||||||||||||||||
| 116 | 4 | my $forms_ar = []; | |||||||||||||||||||||||||||||
| 117 | 4 | foreach my $form_hr (@{$struct_hr->{'forms'}}) { | |||||||||||||||||||||||||||||
| 118 | 1 | push @{$forms_ar}, Wikibase::Datatype::Struct::Form::struct2obj($form_hr); | |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | # Lemmas. | ||||||||||||||||||||||||||||||
| 122 | 4 | my $lemmas_ar = []; | |||||||||||||||||||||||||||||
| 123 | 4 | foreach my $lang (keys %{$struct_hr->{'lemmas'}}) { | |||||||||||||||||||||||||||||
| 124 | 1 | push @{$lemmas_ar}, Wikibase::Datatype::Struct::Language::struct2obj( | |||||||||||||||||||||||||||||
| 125 | 1 | $struct_hr->{'lemmas'}->{$lang}, | |||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||
| 129 | # Senses. | ||||||||||||||||||||||||||||||
| 130 | 4 | my $senses_ar = []; | |||||||||||||||||||||||||||||
| 131 | 4 | foreach my $sense_hr (@{$struct_hr->{'senses'}}) { | |||||||||||||||||||||||||||||
| 132 | 1 | push @{$senses_ar}, Wikibase::Datatype::Struct::Sense::struct2obj($sense_hr); | |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | # Statements. | ||||||||||||||||||||||||||||||
| 136 | 4 | my $statements_ar = []; | |||||||||||||||||||||||||||||
| 137 | 4 | foreach my $property (keys %{$struct_hr->{'claims'}}) { | |||||||||||||||||||||||||||||
| 138 | 1 | foreach my $claim_hr (@{$struct_hr->{'claims'}->{$property}}) { | |||||||||||||||||||||||||||||
| 139 | 1 | push @{$statements_ar}, Wikibase::Datatype::Struct::Statement::struct2obj( | |||||||||||||||||||||||||||||
| 140 | $claim_hr, | ||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | my $obj = Wikibase::Datatype::Lexeme->new( | ||||||||||||||||||||||||||||||
| 146 | 'forms' => $forms_ar, | ||||||||||||||||||||||||||||||
| 147 | 'id' => $struct_hr->{'id'}, | ||||||||||||||||||||||||||||||
| 148 | 'language' => $struct_hr->{'language'}, | ||||||||||||||||||||||||||||||
| 149 | defined $struct_hr->{'lastrevid'} ? ('lastrevid' => $struct_hr->{'lastrevid'}) : (), | ||||||||||||||||||||||||||||||
| 150 | 'lemmas' => $lemmas_ar, | ||||||||||||||||||||||||||||||
| 151 | defined $struct_hr->{'lexicalCategory'} ? ('lexical_category' => $struct_hr->{'lexicalCategory'}) : (), | ||||||||||||||||||||||||||||||
| 152 | defined $struct_hr->{'modified'} ? ('modified' => $struct_hr->{'modified'}) : (), | ||||||||||||||||||||||||||||||
| 153 | defined $struct_hr->{'ns'} ? ('ns' => $struct_hr->{'ns'}) : (), | ||||||||||||||||||||||||||||||
| 154 | defined $struct_hr->{'pageid'} ? ('page_id' => $struct_hr->{'pageid'}) : (), | ||||||||||||||||||||||||||||||
| 155 | 'senses' => $senses_ar, | ||||||||||||||||||||||||||||||
| 156 | 'statements' => $statements_ar, | ||||||||||||||||||||||||||||||
| 157 | 4 | ▶ | defined $struct_hr->{'title'} ? ('title' => $struct_hr->{'title'}) : (), | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||
| 160 | 4 | return $obj; | |||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | 8 | 1; | |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||||