| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- | ||
| 2 | package Lingua::YID::Word2Num; | ||
| 3 | # ABSTRACT: Word to number conversion in Yiddish | ||
| 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 | 0 | ▶ | use Export::Attrs; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | use Parse::RecDescent; | ||
| 13 | |||
| 14 | # }}} | ||
| 15 | # {{{ var block | ||
| 16 | our $VERSION = '0.2603300'; | ||
| 17 | my $parser = yid_numerals(); | ||
| 18 | |||
| 19 | # }}} | ||
| 20 | |||
| 21 | # {{{ w2n convert text to number | ||
| 22 | |||
| 23 | sub w2n :Export { | ||
| 24 | my $input = shift // return; | ||
| 25 | |||
| 26 | return $parser->numeral($input); | ||
| 27 | } | ||
| 28 | |||
| 29 | # }}} | ||
| 30 | # {{{ yid_numerals create parser for yiddish numerals | ||
| 31 | |||
| 32 | sub yid_numerals { | ||
| 33 | return Parse::RecDescent->new(q{ | ||
| 34 | <autoaction: { $item[1] } > | ||
| 35 | |||
| 36 | numeral: mega | ||
| 37 | | kOhOd | ||
| 38 | | { } | ||
| 39 | |||
| 40 | number: /דרײַצן/ { 13 } | ||
| 41 | | /פערצן/ { 14 } | ||
| 42 | | /פופצן/ { 15 } | ||
| 43 | | /זעכצן/ { 16 } | ||
| 44 | | /זיבעצן/ { 17 } | ||
| 45 | | /אַכצן/ { 18 } | ||
| 46 | | /נײַנצן/ { 19 } | ||
| 47 | | /נול/ { 0 } | ||
| 48 | | /אײנס?/ { 1 } | ||
| 49 | | /צװײ/ { 2 } | ||
| 50 | | /דרײַ/ { 3 } | ||
| 51 | | /פֿיר/ { 4 } | ||
| 52 | | /פֿינף/ { 5 } | ||
| 53 | | /זעקס/ { 6 } | ||
| 54 | | /זיבן/ { 7 } | ||
| 55 | | /אכט/ { 8 } | ||
| 56 | | /נײַן/ { 9 } | ||
| 57 | | /צען/ { 10 } | ||
| 58 | | /עלף/ { 11 } | ||
| 59 | | /צוועלף/ { 12 } | ||
| 60 | |||
| 61 | tens: /צוואַנציק/ { 20 } | ||
| 62 | | /דרײַסיק/ { 30 } | ||
| 63 | | /פערציק/ { 40 } | ||
| 64 | | /פופציק/ { 50 } | ||
| 65 | | /זעכציק/ { 60 } | ||
| 66 | | /זיבעציק/ { 70 } | ||
| 67 | | /אַכציק/ { 80 } | ||
| 68 | | /נײַנציק/ { 90 } | ||
| 69 | |||
| 70 | deca: /און/ deca { $item[2] } | ||
| 71 | | number /און/ tens { $item[1] + $item[3] } | ||
| 72 | | tens | ||
| 73 | | number | ||
| 74 | |||
| 75 | hecto: number /הונדערט/ deca { $item[1] * 100 + $item[3] } | ||
| 76 | | number /הונדערט/ { $item[1] * 100 } | ||
| 77 | | /הונדערט/ { 100 } | ||
| 78 | |||
| 79 | hOd: hecto | ||
| 80 | | deca | ||
| 81 | |||
| 82 | kilo: hOd /טויזנט/ hOd { $item[1] * 1000 + $item[3] } | ||
| 83 | | hOd /טויזנט/ { $item[1] * 1000 } | ||
| 84 | |||
| 85 | kOhOd: kilo | ||
| 86 | | hOd | ||
| 87 | |||
| 88 | mega: hOd /מיליאָן/ kOhOd { $item[1] * 1_000_000 + $item[3] } | ||
| 89 | | hOd /מיליאָן/ { $item[1] * 1_000_000 } | ||
| 90 | }); | ||
| 91 | } | ||
| 92 | |||
| 93 | # }}} | ||
| 94 | # {{{ ordinal2cardinal convert ordinal text to cardinal text | ||
| 95 | |||
| 96 | sub ordinal2cardinal :Export { | ||
| 97 | my $input = shift // return; | ||
| 98 | |||
| 99 | # Inverse of Yiddish ordinal morphology: restore cardinal from ordinal text. | ||
| 100 | # Parser expects: אײנס (1), צװײ (2), דרײַ (3), זיבן (7), אכט (8) | ||
| 101 | |||
| 102 | # Irregulars (standalone or as final element of compound) | ||
| 103 | $input =~ s{ערשטער\z}{אײנס}xms and return $input; | ||
| 104 | $input =~ s{צווייטער\z}{צװײ}xms and return $input; | ||
| 105 | $input =~ s{דריטער\z}{דרײַ}xms and return $input; | ||
| 106 | $input =~ s{זעקסטער\z}{זעקס}xms and return $input; # 6th: stem 's' consumed by -סטער | ||
| 107 | $input =~ s{זיבעטער\z}{זיבן}xms and return $input; | ||
| 108 | $input =~ s{אַכטער\z}{אכט}xms and return $input; | ||
| 109 | |||
| 110 | # Teens: ordinal stem differs from parser expectation | ||
| 111 | $input =~ s{פֿירצנטער\z}{פערצן}xms and return $input; # 14th: פֿירצן→פערצן for parser | ||
| 112 | $input =~ s{דרײַצנטער\z}{דרײַצן}xms and return $input; # 13th | ||
| 113 | $input =~ s{פֿינפצנטער\z}{פופצן}xms and return $input; # 15th: פֿינפצן→פופצן for parser | ||
| 114 | $input =~ s{זעכצנטער\z}{זעכצן}xms and return $input; # 16th | ||
| 115 | $input =~ s{זיבעצנטער\z}{זיבעצן}xms and return $input; # 17th | ||
| 116 | $input =~ s{אכטצנטער\z}{אַכצן}xms and return $input; # 18th: אכטצן→אַכצן for parser | ||
| 117 | $input =~ s{נײַנצנטער\z}{נײַנצן}xms and return $input; # 19th | ||
| 118 | |||
| 119 | # Regular: strip סטער (20+) | ||
| 120 | $input =~ s{סטער\z}{}xms and return $input; | ||
| 121 | |||
| 122 | # Regular: strip טער (4-19) | ||
| 123 | $input =~ s{טער\z}{}xms and return $input; | ||
| 124 | |||
| 125 | return; # not an ordinal | ||
| 126 | } | ||
| 127 | |||
| 128 | # }}} | ||
| 129 | |||
| 130 | 1; | ||
| 131 | |||
| 132 | __END__ | ||