| 1 | package Lingua::Deva::Aksara; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 6 | ▶ | use v5.12.1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 6 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 6 | ▶ | use Lingua::Deva::Maps qw( %Vowels %Consonants %Finals ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | =encoding UTF-8 | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | Lingua::Deva::Aksara - Object representation of a Devanagari "syllable" | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | use v5.12.1; | ||||||||||||||||||||
| 19 | use strict; | ||||||||||||||||||||
| 20 | use charnames ':full'; | ||||||||||||||||||||
| 21 | use Lingua::Deva::Aksara; | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | my $a = Lingua::Deva::Aksara->new( | ||||||||||||||||||||
| 24 | onset => ['dh', 'r'], | ||||||||||||||||||||
| 25 | vowel => 'au', | ||||||||||||||||||||
| 26 | final => "h\N{COMBINING DOT BELOW}", | ||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||
| 28 | $a->vowel( 'ai' ); | ||||||||||||||||||||
| 29 | say 'valid' if $a->is_valid(); | ||||||||||||||||||||
| 30 | say @{ $a->get_rhyme() }; # prints 'aiḥ' | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | I<Akṣara> is the Sanskrit term for the basic unit above the character level in | ||||||||||||||||||||
| 35 | the Devanagari script. A C<Lingua::Deva::Aksara> object is a Perl | ||||||||||||||||||||
| 36 | representation of such a unit. | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | C<Lingua::Deva::Aksara> objects serve as an intermediate format for the | ||||||||||||||||||||
| 39 | conversion facilities in L<Lingua::Deva>. Onset, vowel, and final tokens are | ||||||||||||||||||||
| 40 | stored in separate fields. I<Tokens> are in Latin script; if the Aksara in | ||||||||||||||||||||
| 41 | question was created through the L<l_to_aksaras()|Lingua::Deva/l_to_aksaras> | ||||||||||||||||||||
| 42 | or L<d_to_aksaras()|Lingua::Deva/d_to_aksaras> method of a C<Lingua::Deva> | ||||||||||||||||||||
| 43 | object, then the tokens are in the transliteration format associated with that | ||||||||||||||||||||
| 44 | object. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head2 Methods | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =over 4 | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =item new() | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | Constructor. Can take optional initial data as its argument. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | use Lingua::Deva::Aksara; | ||||||||||||||||||||
| 55 | Lingua::Deva::Aksara->new( onset => ['gh', 'r'] ); | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 476125 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 60 | 476125 | my $class = shift; | |||||||||||||||||||
| 61 | 476125 | my $self = { @_ }; | |||||||||||||||||||
| 62 | 476125 | return bless $self, $class; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | =item onset() | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | Accessor method for the array of onset tokens of this Aksara. | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | my $a = Lingua::Deva::Aksara->new(); | ||||||||||||||||||||
| 70 | $a->onset( ['d', 'r'] ); # sets onset tokens to ['d', 'r'] | ||||||||||||||||||||
| 71 | $a->onset(); # returns a reference to ['d', 'r'] | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | Returns undefined when there is no onset. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 341117 | ▶ | sub onset { | ||||||||||||||||||
|
Subroutine
onset: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 78 | 341117 | my $self = shift; | |||||||||||||||||||
| 79 | 341117 | ▶ | $self->{onset} = shift if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 341117 | return $self->{onset}; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =item vowel() | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | Accessor method for the vowel token of this Aksara. Returns undefined when | ||||||||||||||||||||
| 86 | there is no vowel. | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 412222 | ▶ | sub vowel { | ||||||||||||||||||
|
Subroutine
vowel: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 91 | 412222 | my $self = shift; | |||||||||||||||||||
| 92 | 412222 | ▶ | $self->{vowel} = shift if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 412222 | return $self->{vowel}; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =item final() | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | Accessor method for the final token of this Aksara. Returns undefined when | ||||||||||||||||||||
| 99 | there is no final. | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =cut | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 44075 | ▶ | sub final { | ||||||||||||||||||
|
Subroutine
final: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 104 | 44075 | my $self = shift; | |||||||||||||||||||
| 105 | 44075 | ▶ | $self->{final} = shift if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 44075 | return $self->{final}; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =item get_rhyme() | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | Returns the rhyme of this Aksara. This is a reference to an array consisting | ||||||||||||||||||||
| 112 | of vowel and final. Undefined if there is no rhyme. | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | The Aksara is assumed to be well-formed. | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 231002 | ▶ | sub get_rhyme { | ||||||||||||||||||
|
Subroutine
get_rhyme: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 119 | 231002 | my $self = shift; | |||||||||||||||||||
| 120 | 231002 | ▶ | if ($self->{final}) { return [ $self->{vowel}, $self->{final} ] } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | 209001 | ▶ | if ($self->{vowel}) { return [ $self->{vowel} ] } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | 7001 | return; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =item is_valid() | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | Checks the formal validity of this Aksara. This method first checks if the | ||||||||||||||||||||
| 128 | Aksara conforms to the structure C<(C+(VF?)?)|(VF?)>, where the letters | ||||||||||||||||||||
| 129 | represent onset consonants, vowel, and final. Then it checks whether the | ||||||||||||||||||||
| 130 | onset, vowel, and final fields contain only appropriate tokens. | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | In order to do validation against a different transliteration scheme than the | ||||||||||||||||||||
| 133 | default one, a reference to a customized C<Lingua::Deva> instance can be | ||||||||||||||||||||
| 134 | passed along. | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | $d; # Lingua::Deva object with custom transliteration | ||||||||||||||||||||
| 137 | say $a->is_valid($d); | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | An Aksara constructed through L<Lingua::Deva>'s public interface is already | ||||||||||||||||||||
| 140 | well-formed (ie. in accordance with the particular transliteration used) and | ||||||||||||||||||||
| 141 | no validity check is necessary. | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 119003 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||
| 146 | 119003 | my ($self, $deva) = @_; | |||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | my ($C, $V, $F) = ref($deva) eq 'Lingua::Deva' | ||||||||||||||||||||
| 149 | ? ($deva->{C}, $deva->{V}, $deva->{F}) | ||||||||||||||||||||
| 150 | 119003 | ▶ | : (\%Consonants, \%Vowels, \%Finals); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | # Check Aksara structure | ||||||||||||||||||||
| 153 | 119003 | ▶ | my $s = @{ $self->{onset} // [] } ? 'C' : ''; | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"onset"} // []
MC/DC100%1/1
$self->{"onset"} // []
$self->{"onset"}
Truth table100%2/2
A
A= $self->{"onset"}
| |||||||||||||||||||||
| 154 | 119003 | ▶ | $s .= $self->{vowel} ? 'V' : ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 155 | 119003 | ▶ | $s .= $self->{final} ? 'F' : ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | 119003 | ▶ | return 0 if $s =~ m/^(C?F|)$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | # After this point empty strings and arrays have been rejected | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | # Check Aksara tokens | ||||||||||||||||||||
| 161 | 119003 | ▶ | if (defined $self->{onset}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 162 | 110003 | for my $o (@{ $self->{onset} }) { | |||||||||||||||||||
| 163 | 138004 | ▶ | return 0 if not defined $C->{$o}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 164 | } | ||||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | 119002 | ▶ | if (defined $self->{vowel}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 167 | 112002 | ▶ | return 0 if not defined $V->{ $self->{vowel} }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | 119002 | ▶ | if (defined $self->{final}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 170 | 11002 | ▶ | return 0 if not defined $F->{ $self->{final} }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 119002 | return 1; | |||||||||||||||||||
| 174 | } | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =back | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | 6 | 1; | |||||||||||||||||||