Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.
fix(grounding): read the year after an abbreviated month with a period
HenryNdubuaku217d8b2da620
diff --git a/needle/__init__.py b/needle/__init__.pyindex 9f906a6..c389371 100644--- a/needle/__init__.py+++ b/needle/__init__.py@@ -430,7 +430,7 @@ def _resolve_ref(node, root):def _source_years(text):months = (r"(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|"r"jun(?:e)?|jul(?:y)?|aug(?:ust)?|sep(?:t(?:ember)?)?|"- r"oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)")+ r"oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)\.?")patterns = [# The number after a day and month is its year, unless it is the hour of# a time ("5 June 19:30", "June 5 7 pm"): no ISO argument can carrydiff --git a/tests/test_grounding.py b/tests/test_grounding.pyindex c05d584..982f5b2 100644--- a/tests/test_grounding.py+++ b/tests/test_grounding.py@@ -410,3 +410,25 @@ def test_extract_accepts_a_date_followed_by_a_time(stub):invoice = needle.extract("Invoice from Acme Corp due March 3 14:00", Invoice)assert invoice.due_date == datetime.date(2026, 3, 3)++[email protected](("text", "expected"), [+ ("due Dec. 25, 2026", {2026}),+ ("due 25 Dec. 2026", {2026}),+ ("due Sept. 12, 2025", {2025}),+ ("due 12 Sept. 2025", {2025}),+ ("due Sep. 2025", {2025}),+])+def test_an_abbreviated_month_with_a_period_still_gives_its_year(text, expected):+ import needle++ assert needle._source_years(text) == expected+++def test_extract_accepts_dates_written_with_abbreviated_months_and_periods(stub):+ import needle++ stub.envelopes = [_call("2026-12-25")]+ invoice = needle.extract("Invoice from Acme, issued Jun 5, 2025 and due Dec. 25, 2026", Invoice)++ assert invoice.due_date == datetime.date(2026, 12, 25)