Skip to content

Inline quantity detection fails or loses unit symbols around punctuation #100

Description

@LukaHummel

Version

@cooklang/cooklang 0.18.7 through the TypeScript/WASM binding.

Reproduction

import { CooklangParser, quantity_display } from '@cooklang/cooklang';

const parser = new CooklangParser();
const [recipe] = parser.parse(
  'Position an #oven rack{} in the center and preheat the #oven{} to 230°C, or 200°C with convection.'
);

console.log(recipe.inlineQuantities.map(quantity_display));
console.log(recipe.sections[0].content[0]);

The result contains only:

["200 °C"]

The relevant step items leave 230°C, inside a text item, while 200°C becomes an inlineQuantity.

Removing the comma makes both temperatures parse:

Position an #oven rack{} in the center and preheat the #oven{} to 230°C or 200°C with convection.

Expected behavior

Both 230°C and 200°C should be recognized as inline quantities regardless of adjacent sentence punctuation, and the recognized unit should preserve its degree symbol.

Additional context

In v0.18.7, find_inline_quantity reads a whitespace-delimited candidate, so the first unit is looked up as °C, and rejected.

PR #99 is related and handles punctuation by trimming non-alphabetic characters from both ends of the unit. That appears to also trim the leading ° from °C, leaving C. It may be safer to remove only trailing punctuation or otherwise retain the original matched unit symbol.

This produces inconsistent structured output and downstream rendering for two temperatures in the same instruction.

Related: #99

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions