| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- | ||||||||||||
| 2 | package Lingua::CYM::Word2Num; | ||||||||||||
| 3 | # ABSTRACT: Word to number conversion in Welsh (Cymraeg) | ||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use 5.16.0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | # {{{ use block | ||||||||||||
| 10 | |||||||||||||
| 11 | 1 | ▶ | use Export::Attrs; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use Parse::RecDescent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | # }}} | ||||||||||||
| 15 | # {{{ var block | ||||||||||||
| 16 | 1 | our $VERSION = '0.2603270'; | |||||||||||
| 17 | 1 | my $parser = cym_numerals(); | |||||||||||
| 18 | |||||||||||||
| 19 | # }}} | ||||||||||||
| 20 | |||||||||||||
| 21 | # {{{ w2n convert text to number | ||||||||||||
| 22 | |||||||||||||
| 23 | sub w2n :Export { | ||||||||||||
| 24 | 14 | ▶ | my $input = shift // return; | ||||||||||
|
Subroutine
w2n: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
shift() // (return)
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 25 | |||||||||||||
| 26 | 13 | return $parser->numeral($input); | |||||||||||
| 27 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | |||||||||||||
| 29 | # }}} | ||||||||||||
| 30 | # {{{ cym_numerals create parser for Welsh numerals | ||||||||||||
| 31 | |||||||||||||
| 32 | sub cym_numerals { | ||||||||||||
| 33 | 1 | ▶ | return Parse::RecDescent->new(q{ | ||||||||||
|
Subroutine
cym_numerals: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 34 | <autoaction: { $item[1] } > | ||||||||||||
| 35 | |||||||||||||
| 36 | numeral: mega | ||||||||||||
| 37 | | kOhOd | ||||||||||||
| 38 | | { } | ||||||||||||
| 39 | |||||||||||||
| 40 | # Basic digits | ||||||||||||
| 41 | number: 'dim' { 0 } | ||||||||||||
| 42 | | 'sero' { 0 } | ||||||||||||
| 43 | | 'un' { 1 } | ||||||||||||
| 44 | | 'dau' { 2 } | ||||||||||||
| 45 | | 'dwy' { 2 } | ||||||||||||
| 46 | | 'tri' { 3 } | ||||||||||||
| 47 | | 'tair' { 3 } | ||||||||||||
| 48 | | 'pedwar' { 4 } | ||||||||||||
| 49 | | 'pedair' { 4 } | ||||||||||||
| 50 | | 'pump' { 5 } | ||||||||||||
| 51 | | 'pum' { 5 } | ||||||||||||
| 52 | | 'chwech' { 6 } | ||||||||||||
| 53 | | 'chwe' { 6 } | ||||||||||||
| 54 | | 'saith' { 7 } | ||||||||||||
| 55 | | 'wyth' { 8 } | ||||||||||||
| 56 | | 'naw' { 9 } | ||||||||||||
| 57 | | 'deg' { 10 } | ||||||||||||
| 58 | |||||||||||||
| 59 | # Tens: "dau ddeg", "tri deg", "pedwar deg", "pum deg", etc. | ||||||||||||
| 60 | tens: 'dau' 'ddeg' { 20 } | ||||||||||||
| 61 | | 'tri' 'deg' { 30 } | ||||||||||||
| 62 | | 'pedwar' 'deg' { 40 } | ||||||||||||
| 63 | | 'pum' 'deg' { 50 } | ||||||||||||
| 64 | | 'chwe' 'deg' { 60 } | ||||||||||||
| 65 | | 'saith' 'deg' { 70 } | ||||||||||||
| 66 | | 'wyth' 'deg' { 80 } | ||||||||||||
| 67 | | 'naw' 'deg' { 90 } | ||||||||||||
| 68 | |||||||||||||
| 69 | # Teens: "un deg un" = 11, "un deg dau" = 12, etc. | ||||||||||||
| 70 | teens: 'un' 'deg' number { 10 + $item[3] } | ||||||||||||
| 71 | |||||||||||||
| 72 | deca: teens | ||||||||||||
| 73 | | tens number { $item[1] + $item[2] } | ||||||||||||
| 74 | | tens | ||||||||||||
| 75 | | number | ||||||||||||
| 76 | |||||||||||||
| 77 | # Hundreds: cant, dau gant, tri chant, pedwar cant, pum cant, etc. | ||||||||||||
| 78 | hecto: 'naw' 'cant' deca { 900 + $item[3] } | ||||||||||||
| 79 | | 'naw' 'cant' { 900 } | ||||||||||||
| 80 | | 'wyth' 'cant' deca { 800 + $item[3] } | ||||||||||||
| 81 | | 'wyth' 'cant' { 800 } | ||||||||||||
| 82 | | 'saith' 'cant' deca { 700 + $item[3] } | ||||||||||||
| 83 | | 'saith' 'cant' { 700 } | ||||||||||||
| 84 | | 'chwe' 'chant' deca { 600 + $item[3] } | ||||||||||||
| 85 | | 'chwe' 'chant' { 600 } | ||||||||||||
| 86 | | 'pum' 'cant' deca { 500 + $item[3] } | ||||||||||||
| 87 | | 'pum' 'cant' { 500 } | ||||||||||||
| 88 | | 'pedwar' 'cant' deca { 400 + $item[3] } | ||||||||||||
| 89 | | 'pedwar' 'cant' { 400 } | ||||||||||||
| 90 | | 'tri' 'chant' deca { 300 + $item[3] } | ||||||||||||
| 91 | | 'tri' 'chant' { 300 } | ||||||||||||
| 92 | | 'dau' 'gant' deca { 200 + $item[3] } | ||||||||||||
| 93 | | 'dau' 'gant' { 200 } | ||||||||||||
| 94 | | 'cant' deca { 100 + $item[2] } | ||||||||||||
| 95 | | 'cant' { 100 } | ||||||||||||
| 96 | |||||||||||||
| 97 | hOd: hecto | ||||||||||||
| 98 | | deca | ||||||||||||
| 99 | |||||||||||||
| 100 | # Thousands: mil, dau mil, tri mil, etc. | ||||||||||||
| 101 | kilo: hOd 'mil' hOd { $item[1] * 1000 + $item[3] } | ||||||||||||
| 102 | | hOd 'mil' { $item[1] * 1000 } | ||||||||||||
| 103 | | 'mil' hOd { 1000 + $item[2] } | ||||||||||||
| 104 | | 'mil' { 1000 } | ||||||||||||
| 105 | |||||||||||||
| 106 | kOhOd: kilo | ||||||||||||
| 107 | | hOd | ||||||||||||
| 108 | |||||||||||||
| 109 | mega: hOd 'miliwn' kOhOd { $item[1] * 1_000_000 + $item[3] } | ||||||||||||
| 110 | | hOd 'miliwn' { $item[1] * 1_000_000 } | ||||||||||||
| 111 | }); | ||||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | # }}} | ||||||||||||
| 115 | |||||||||||||
| 116 | # {{{ capabilities declare supported features | ||||||||||||
| 117 | |||||||||||||
| 118 | sub capabilities { | ||||||||||||
| 119 | return { | ||||||||||||
| 120 | 0 | ▶ | cardinal => 1, | ||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 121 | ordinal => 0, | ||||||||||||
| 122 | }; | ||||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | # }}} | ||||||||||||
| 126 | |||||||||||||
| 127 | 1 | 1; | |||||||||||
| 128 | |||||||||||||
| 129 | __END__ | ||||||||||||