Example

Textual Numbers

English number words.

Parse English written numbers into a semantic hierarchy.

What it shows

  • Units, teens, and tens are the base values.
  • Larger numbers compose hundreds, thousands, millions, and remainders.
  • The result preserves the structure of each number phrase.

Try changing twenty-seven to twenty seven.

Specs

spec.yml
$flags: 'WORD_BOUNDARY'

Number:
  BelowMillion:
    BelowThousand:
      BelowHundred:
        Unit:
          Zero: 'zero'
          One: 'one'
          Two: 'two'
          Three: 'three'
          Four: 'four'
          Five: 'five'
          Six: 'six'
          Seven: 'seven'
          Eight: 'eight'
          Nine: 'nine'
        TwoDigit:
          TenToNineteen:
            Ten: 'ten'
            Eleven: 'eleven'
            Twelve: 'twelve'
            Thirteen: 'thirteen'
            Fourteen: 'fourteen'
            Fifteen: 'fifteen'
            Sixteen: 'sixteen'
            Seventeen: 'seventeen'
            Eighteen: 'eighteen'
            Nineteen: 'nineteen'
          Tens:
            Twenty: 'twenty'
            Thirty: 'thirty'
            Forty: 'forty'
            Fifty: 'fifty'
            Sixty: 'sixty'
            Seventy: 'seventy'
            Eighty: 'eighty'
            Ninety: 'ninety'
          Compound:
            $fields:
              tens: Tens
              unit: Unit
            $patterns: '#{tens}(-| )#{unit}'
      Hundred:
        $fields:
          hundreds: Unit
          remainder: BelowHundred
        $patterns: '#{hundreds} hundred( and #{remainder})?'
    Thousand:
      $fields:
        thousands: BelowThousand
        remainder: BelowThousand
      $patterns: '#{thousands} thousand( #{remainder})?'
  Million:
    $fields:
      millions: BelowThousand
      remainder: BelowMillion
    $patterns: '#{millions} million( #{remainder})?'
Try it liveOpen Textual Numbers in StudioTweak the spec, paste your own input, and see the parse tree update in real time.

Or browse other examples →