| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*- | ||||||||||||
| 2 | |||||||||||||
| 3 | package Lingua::NLD::Word2Num; | ||||||||||||
| 4 | # ABSTRACT: Word to number conversion in Dutch | ||||||||||||
| 5 | |||||||||||||
| 6 | 1 | ▶ | use 5.16.0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | # {{{ use block | ||||||||||||
| 11 | |||||||||||||
| 12 | 1 | ▶ | use Export::Attrs; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 1 | ▶ | use Parse::RecDescent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | # }}} | ||||||||||||
| 16 | # {{{ variable declarations | ||||||||||||
| 17 | 1 | our $VERSION = '0.2603270'; | |||||||||||
| 18 | 1 | my $parser = nld_numerals(); | |||||||||||
| 19 | |||||||||||||
| 20 | # }}} | ||||||||||||
| 21 | # {{{ w2n convert text to number | ||||||||||||
| 22 | |||||||||||||
| 23 | sub w2n :Export { | ||||||||||||
| 24 | 9 | ▶ | 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 | 8 | $input = lc $input; | |||||||||||
| 27 | 8 | $input =~ s/,//g; | |||||||||||
| 28 | 8 | $input =~ s/ //g; | |||||||||||
| 29 | |||||||||||||
| 30 | 8 | return $parser->numeral($input); | |||||||||||
| 31 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | |||||||||||||
| 33 | # }}} | ||||||||||||
| 34 | # {{{ nld_numerals create parser for numerals | ||||||||||||
| 35 | |||||||||||||
| 36 | sub nld_numerals { | ||||||||||||
| 37 | 1 | ▶ | return Parse::RecDescent->new(q{ | ||||||||||
|
Subroutine
nld_numerals: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 38 | numeral: <rulevar: local $number = 0> | ||||||||||||
| 39 | numeral: million { return $item[1]; } # root parse. go from maximum to minimum value | ||||||||||||
| 40 | | millenium { return $item[1]; } | ||||||||||||
| 41 | | century { return $item[1]; } | ||||||||||||
| 42 | | decade { return $item[1]; } | ||||||||||||
| 43 | | { return undef; } | ||||||||||||
| 44 | |||||||||||||
| 45 | number: 'negentien' { $return = 19; } # try to find a word from 0 to 19 | ||||||||||||
| 46 | | 'achtien' { $return = 18; } | ||||||||||||
| 47 | | 'zeventien' { $return = 17; } | ||||||||||||
| 48 | | 'zestien' { $return = 16; } | ||||||||||||
| 49 | | 'vijftien' { $return = 15; } | ||||||||||||
| 50 | | 'veertien' { $return = 14; } | ||||||||||||
| 51 | | 'dertien' { $return = 13; } | ||||||||||||
| 52 | | 'twaalf' { $return = 12; } | ||||||||||||
| 53 | | 'elf' { $return = 11; } | ||||||||||||
| 54 | | 'tien' { $return = 10; } | ||||||||||||
| 55 | | 'negen' { $return = 9; } | ||||||||||||
| 56 | | 'acht' { $return = 8; } | ||||||||||||
| 57 | | 'zeven' { $return = 7; } | ||||||||||||
| 58 | | 'zes' { $return = 6; } | ||||||||||||
| 59 | | 'vijf' { $return = 5; } | ||||||||||||
| 60 | | 'vier' { $return = 4; } | ||||||||||||
| 61 | | 'drie' { $return = 3; } | ||||||||||||
| 62 | | 'twee' { $return = 2; } | ||||||||||||
| 63 | | /(een|één)/ { $return = 1; } | ||||||||||||
| 64 | | 'nul' { $return = 0; } | ||||||||||||
| 65 | |||||||||||||
| 66 | tens: 'twintig' { $return = 20; } # try to find a word that represents | ||||||||||||
| 67 | | 'dertig' { $return = 30; } # values 20,30,..,90 | ||||||||||||
| 68 | | 'veertig' { $return = 40; } | ||||||||||||
| 69 | | 'vijftig' { $return = 50; } | ||||||||||||
| 70 | | 'zestig' { $return = 60; } | ||||||||||||
| 71 | | 'zeventig' { $return = 70; } | ||||||||||||
| 72 | | 'tachtig' { $return = 80; } | ||||||||||||
| 73 | | 'negentig' { $return = 90; } | ||||||||||||
| 74 | |||||||||||||
| 75 | decade: number(?) 'en' tens(?) number(?) # try to find words that represents values | ||||||||||||
| 76 | { $return = 0; # from 0 to 99 | ||||||||||||
| 77 | for (@item) { | ||||||||||||
| 78 | $return += $$_[0] if (ref $_ && defined $$_[0]); | ||||||||||||
| 79 | } | ||||||||||||
| 80 | } | ||||||||||||
| 81 | | tens(?) number(?) | ||||||||||||
| 82 | { $return = -1; | ||||||||||||
| 83 | for (@item) { | ||||||||||||
| 84 | if (ref $_ && defined $$_[0]) { | ||||||||||||
| 85 | $return += $$_[0] if ($return != -1); | ||||||||||||
| 86 | $return = $$_[0] if ($return == -1); | ||||||||||||
| 87 | } | ||||||||||||
| 88 | } | ||||||||||||
| 89 | $return = undef if ($return == -1); | ||||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | century: number(?) 'honderd' decade(?) # try to find words that represents values | ||||||||||||
| 93 | { $return = 0; # from 100 to 999 | ||||||||||||
| 94 | for (@item) { | ||||||||||||
| 95 | if (ref $_ && defined $$_[0]) { | ||||||||||||
| 96 | $return += $$_[0]; | ||||||||||||
| 97 | } elsif ($_ eq "honderd") { | ||||||||||||
| 98 | $return = ($return>0) ? $return * 100 : 100; | ||||||||||||
| 99 | } | ||||||||||||
| 100 | } | ||||||||||||
| 101 | $return ||= undef; | ||||||||||||
| 102 | } | ||||||||||||
| 103 | |||||||||||||
| 104 | millenium: century(?) decade(?) 'duizend' century(?) decade(?) # try to find words that represents values | ||||||||||||
| 105 | { $return = 0; # from 1.000 to 999.999 | ||||||||||||
| 106 | for (@item) { | ||||||||||||
| 107 | if (ref $_ && defined $$_[0]) { | ||||||||||||
| 108 | $return += $$_[0]; | ||||||||||||
| 109 | } elsif ($_ eq "duizend") { | ||||||||||||
| 110 | $return = ($return>0) ? $return * 1000 : 1000; | ||||||||||||
| 111 | } | ||||||||||||
| 112 | } | ||||||||||||
| 113 | $return ||= undef; | ||||||||||||
| 114 | } | ||||||||||||
| 115 | |||||||||||||
| 116 | million: millenium(?) century(?) decade(?) # try to find words that represents values | ||||||||||||
| 117 | 'miljoen' # from 1.000.000 to 999.999.999.999 | ||||||||||||
| 118 | millenium(?) century(?) decade(?) | ||||||||||||
| 119 | { $return = 0; | ||||||||||||
| 120 | for (@item) { | ||||||||||||
| 121 | if (ref $_ && defined $$_[0]) { | ||||||||||||
| 122 | $return += $$_[0]; | ||||||||||||
| 123 | } elsif ($_ eq "miljoen") { | ||||||||||||
| 124 | $return = ($return>0) ? $return * 1000000 : 1000000; | ||||||||||||
| 125 | } | ||||||||||||
| 126 | } | ||||||||||||
| 127 | $return ||= undef; | ||||||||||||
| 128 | } | ||||||||||||
| 129 | }); | ||||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | # }}} | ||||||||||||
| 133 | |||||||||||||
| 134 | 1 | 1; | |||||||||||
| 135 | |||||||||||||
| 136 | __END__ | ||||||||||||