Smarter craft command parsing — stops at prepositions
- 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) <noreply@anthropic.com>
This commit is contained in:
parent
09464043bf
commit
813f8704bb
1 changed files with 18 additions and 4 deletions
|
|
@ -57,7 +57,7 @@ class CommandParser:
|
||||||
]
|
]
|
||||||
|
|
||||||
CRAFT_PATTERNS = [
|
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 = [
|
MINE_PATTERNS = [
|
||||||
|
|
@ -165,9 +165,23 @@ class CommandParser:
|
||||||
for pattern in self.CRAFT_PATTERNS:
|
for pattern in self.CRAFT_PATTERNS:
|
||||||
match = re.search(pattern, msg, re.IGNORECASE)
|
match = re.search(pattern, msg, re.IGNORECASE)
|
||||||
if match:
|
if match:
|
||||||
item = match.group(1).strip() if match.lastindex else ""
|
raw_item = match.group(1).strip() if match.lastindex else ""
|
||||||
# Normalize item name
|
# Extract item name: take first 1-3 non-filler words before any preposition
|
||||||
item = item.replace(" ", "_").lower()
|
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(
|
return ParsedCommand(
|
||||||
action="craft",
|
action="craft",
|
||||||
target=item,
|
target=item,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue