From 348206469b5570fbad46b22f1dc156c8c60ef7d2 Mon Sep 17 00:00:00 2001 From: Claudiu Ceia Date: Fri, 22 Jul 2022 12:19:02 +0300 Subject: [PATCH] fix(temperature): end parser --- src/Temperature.ts | 4 ++-- tests/Temperature.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Temperature.ts b/src/Temperature.ts index f95448a..634f23e 100644 --- a/src/Temperature.ts +++ b/src/Temperature.ts @@ -12,7 +12,7 @@ import { space, skip1, } from "combine/mod.ts"; -import { EntityLanguage, __ } from "./common.ts"; +import { EntityLanguage, __, dot } from "./common.ts"; import { ent, Entity } from "./Entity.ts"; import { Quantity, QuantityEntity } from "./Quantity.ts"; @@ -122,5 +122,5 @@ export const Temperature = createLanguage({ a ) ), - parser: (s) => any(s.BelowZero, s.Celsius, s.Fahrenheit, s.Unspecified), + parser: (s) => dot(any(s.BelowZero, s.Celsius, s.Fahrenheit, s.Unspecified)), }); diff --git a/tests/Temperature.test.ts b/tests/Temperature.test.ts index 8e0ba64..fb3a26a 100644 --- a/tests/Temperature.test.ts +++ b/tests/Temperature.test.ts @@ -128,3 +128,26 @@ Deno.test("below zero", () => { ]); } }); + +Deno.test("No false positive for temperature", () => { + const res = Duckling().extract({ + text: `In 1837 Charles Babbage first described his Analytical Engine`, + index: 0, + }); + + assertEquals(res.success, true); + + if (res.success) { + assertEquals(res.value, [ + { + end: 7, + kind: "quantity", + start: 3, + text: "1837", + value: { + amount: 1837, + }, + }, + ]); + } +});