From 813f8704bbf11c122941a68288dc1aa6f1a13442 Mon Sep 17 00:00:00 2001 From: roberts Date: Mon, 30 Mar 2026 13:47:52 -0500 Subject: [PATCH] =?UTF-8?q?Smarter=20craft=20command=20parsing=20=E2=80=94?= =?UTF-8?q?=20stops=20at=20prepositions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Craft regex captures full text, then parser extracts item name - Strips filler words (a, an, some, the) - Stops at prepositions (with, from, using, in, for) - Takes max 3 words for item name - "craft sticks with wood" → "sticks" - "craft a wooden pickaxe" → "wooden_pickaxe" Co-Authored-By: Claude Opus 4.6 (1M context) --- dougbot/core/command_parser.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/dougbot/core/command_parser.py b/dougbot/core/command_parser.py index 0e3bb7b..050dfdb 100644 --- a/dougbot/core/command_parser.py +++ b/dougbot/core/command_parser.py @@ -57,7 +57,7 @@ class CommandParser: ] CRAFT_PATTERNS = [ - r"(?:craft|make|build|create)\s+(?:a\s+|an\s+|some\s+|me\s+)?(\w+)", + r"(?:craft|make|build|create)\s+(.+)", ] MINE_PATTERNS = [ @@ -165,9 +165,23 @@ class CommandParser: for pattern in self.CRAFT_PATTERNS: match = re.search(pattern, msg, re.IGNORECASE) if match: - item = match.group(1).strip() if match.lastindex else "" - # Normalize item name - item = item.replace(" ", "_").lower() + raw_item = match.group(1).strip() if match.lastindex else "" + # Extract item name: take first 1-3 non-filler words before any preposition + filler = {"a", "an", "some", "me", "the", "this", "that", "please"} + stop_words = {"with", "from", "using", "in", "on", "at", "for", "out", "of"} + words = [] + for w in raw_item.split(): + wl = w.lower().rstrip(".,!?") + if wl in filler: + continue + if wl in stop_words: + break # Stop at prepositions + words.append(wl) + if len(words) >= 3: + break + if not words: + return None + item = "_".join(words) return ParsedCommand( action="craft", target=item,