Skip to content
Astera Technology

Keep spoken code digits separate from a quantity

Speech-normalised text turns one zero five into either15 or a count105.

Download complete case notes and answer keys ↓

Define the local evaluation task

A synthetic transcript uses exactly code followed by one to eight spoken digit words, then semicolon quantity followed by one digit word. Allowed words are zero through nine in lowercase English. Code digits are concatenated as text, preserving leading zero; quantity is one integer. Any other transcript grammar is held.

  1. Match code and quantity slots
  2. Convert code digit words to text digits
  3. Convert the quantity word separately

Unrecognised words or ambiguous segmentation retain the transcript for review.

Use the filled cases

Original synthetic input and literal answer key
CaseSupplied inputExpected structured outputDecision and reason
Three code digits and quantity{"line":"code one zero five; quantity two"}{"code":"105","quantity":2}One zero five identifies the text code; two is the quantity.
Code begins with zero{"line":"code zero one; quantity zero"}{"code":"01","quantity":0}Code 01 remains two characters; the observed quantity is zero.
Unsupported number word{"line":"code ten; quantity two"}{"error":"grammar"}Ten is not an allowed single digit word, so do not guess its segmentation.
Download editable CSV ↓

Work the unsupported-ten case. Which output is required, and why?

Show the worked answer

{"error":"grammar"} — Ten is not an allowed single digit word, so do not guess its segmentation.

Run the self-contained evaluator

Save as .mjs and run with Node.js; supplied fixtures only
import assert from 'node:assert/strict';

function evaluate(x){
 const words=['zero','one','two','three','four','five','six','seven','eight','nine'];
 const m=/^code ([a-z ]+); quantity ([a-z]+)$/.exec(x.line);if(!m)return {error:'grammar'};
 const digits=m[1].split(' ');if(digits.length<1||digits.length>8||digits.some(w=>!words.includes(w))||!words.includes(m[2]))return {error:'grammar'};
 return {code:digits.map(w=>words.indexOf(w)).join(''),quantity:words.indexOf(m[2])};
}

const cases = [
  {
    "id": "three-code-digits",
    "input": {
      "line": "code one zero five; quantity two"
    },
    "expected": {
      "code": "105",
      "quantity": 2
    }
  },
  {
    "id": "leading-zero-code",
    "input": {
      "line": "code zero one; quantity zero"
    },
    "expected": {
      "code": "01",
      "quantity": 0
    }
  },
  {
    "id": "unsupported-ten",
    "input": {
      "line": "code ten; quantity two"
    },
    "expected": {
      "error": "grammar"
    }
  }
];
for (const c of cases) assert.deepEqual(evaluate(c.input), c.expected, c.id);
console.log(JSON.stringify({checked:cases.length,caseIds:cases.map(c=>c.id)}));
Download runnable example ↓

Add a separate accepted grammar when testing another language or number style. This exercise parses supplied text only; it neither transcribes audio nor measures speech-recognition accuracy.

Related resources