Skip to content

Commit 884cea6

Browse files
Fix metric inference for distance queries - prioritize distance over steps when 'distance' keyword is present
1 parent 4512dc2 commit 884cea6

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

examples/whisper.android/app/src/main/java/com/whispercppdemo/intent/SlotExtractor.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,21 +2262,12 @@ class SlotExtractor {
22622262
private fun inferMetricFromContext(text: String): String? {
22632263
// Pre-compiled regex patterns for better performance
22642264
val inferencePatterns = mapOf(
2265-
"steps" to listOf(
2266-
Regex("\\b(?:walk|walked|walking|stroll|strolling|strolled|hike|hiking|hiked|trek|trekking|trekked|march|marching|marched|wander|wandering|wandered|amble|ambling|ambled|pace|pacing|paced)\\b(?!\\s+(?:distance|far|km|miles?|kilometers?))", RegexOption.IGNORE_CASE),
2267-
Regex("\\bhow\\s+(?:much|many).*(?:walk|walked|stroll|hike|move|moved|step)\\b", RegexOption.IGNORE_CASE),
2268-
Regex("\\bsteps?\\b|\\bfootsteps?\\b|\\bfoot\\s+steps?\\b", RegexOption.IGNORE_CASE),
2269-
Regex("\\b(?:count|counting|total|number).*(?:steps?|walk)\\b", RegexOption.IGNORE_CASE),
2270-
Regex("\\b(?:daily|today'?s|my)\\s+(?:steps?|walk|walking)\\b", RegexOption.IGNORE_CASE),
2271-
Regex("\\bstep\\s+(?:count|counter|goal|target|total)\\b", RegexOption.IGNORE_CASE),
2272-
Regex("\\bhow\\s+(?:active|much\\s+activity)\\b", RegexOption.IGNORE_CASE),
2273-
Regex("\\bmovement\\b|\\bactivity\\s+level\\b", RegexOption.IGNORE_CASE),
2274-
Regex("\\bgait\\b|\\btread\\b|\\bstride\\b", RegexOption.IGNORE_CASE)
2275-
),
22762265
"distance" to listOf(
2277-
Regex("\\bhow\\s+far\\b|\\bhow\\s+much\\s+distance\\b|\\bhow\\s+long\\s+(?:of\\s+)?(?:a\\s+)?distance\\b", RegexOption.IGNORE_CASE),
2278-
Regex("\\b(?:walk|walked|walking|run|ran|running|jog|jogged|jogging|hike|hiked|hiking)\\s+(?:distance|far|length)\\b", RegexOption.IGNORE_CASE),
2266+
Regex("\\bhow\\s+(?:much|many)\\s+distance\\b", RegexOption.IGNORE_CASE),
2267+
Regex("\\bhow\\s+far\\b|\\bhow\\s+long\\s+(?:of\\s+)?(?:a\\s+)?distance\\b", RegexOption.IGNORE_CASE),
22792268
Regex("\\bdistance.*(?:walk|walked|run|ran|travel|travelled|traveled|cover|covered)\\b", RegexOption.IGNORE_CASE),
2269+
Regex("\\bhow\\s+(?:much|many).*distance.*(?:walk|walked|run|ran|travel|travelled|traveled|cover|covered)\\b", RegexOption.IGNORE_CASE),
2270+
Regex("\\b(?:walk|walked|walking|run|ran|running|jog|jogged|jogging|hike|hiked|hiking)\\s+(?:distance|far|length)\\b", RegexOption.IGNORE_CASE),
22802271
Regex("\\bkilometers?\\b|\\bkilometres?\\b|\\bmiles?\\b|\\bkm\\b|\\bmi\\b|\\bmeters?\\b|\\bmetres?\\b", RegexOption.IGNORE_CASE),
22812272
Regex("\\bhow\\s+(?:much|many)\\s+(?:km|miles?|meters?)\\b", RegexOption.IGNORE_CASE),
22822273
Regex("\\b(?:total|overall|entire)\\s+distance\\b", RegexOption.IGNORE_CASE),
@@ -2285,6 +2276,17 @@ class SlotExtractor {
22852276
Regex("\\bjourney\\s+length\\b|\\btrip\\s+distance\\b", RegexOption.IGNORE_CASE),
22862277
Regex("\\bhow\\s+long\\s+(?:of\\s+)?(?:a\\s+)?(?:walk|run|hike)\\b", RegexOption.IGNORE_CASE)
22872278
),
2279+
"steps" to listOf(
2280+
Regex("\\b(?:walk|walked|walking|stroll|strolling|strolled|hike|hiking|hiked|trek|trekking|trekked|march|marching|marched|wander|wandering|wandered|amble|ambling|ambled|pace|pacing|paced)\\b(?!\\s+(?:distance|far|km|miles?|kilometers?))", RegexOption.IGNORE_CASE),
2281+
Regex("\\bhow\\s+(?:much|many)(?!.*distance).*(?:walk|walked|stroll|hike|move|moved|step)\\b", RegexOption.IGNORE_CASE),
2282+
Regex("\\bsteps?\\b|\\bfootsteps?\\b|\\bfoot\\s+steps?\\b", RegexOption.IGNORE_CASE),
2283+
Regex("\\b(?:count|counting|total|number).*(?:steps?|walk)(?!.*distance)\\b", RegexOption.IGNORE_CASE),
2284+
Regex("\\b(?:daily|today'?s|my)\\s+(?:steps?|walk|walking)\\b", RegexOption.IGNORE_CASE),
2285+
Regex("\\bstep\\s+(?:count|counter|goal|target|total)\\b", RegexOption.IGNORE_CASE),
2286+
Regex("\\bhow\\s+(?:active|much\\s+activity)\\b", RegexOption.IGNORE_CASE),
2287+
Regex("\\bmovement\\b|\\bactivity\\s+level\\b", RegexOption.IGNORE_CASE),
2288+
Regex("\\bgait\\b|\\btread\\b|\\bstride\\b", RegexOption.IGNORE_CASE)
2289+
),
22882290
"heart rate" to listOf(
22892291
Regex("\\bheart\\s+rate\\b|\\bheartrate\\b|\\bheart\\s+beat\\b|\\bheartbeat\\b", RegexOption.IGNORE_CASE),
22902292
Regex("\\bpulse\\b|\\bpulse\\s+rate\\b|\\bheart\\s+rhythm\\b", RegexOption.IGNORE_CASE),

examples/whisper.swiftui/whisper.swiftui.demo/Intent/SlotExtractor.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,20 +2269,22 @@ class SlotExtractor {
22692269
private func inferMetricFromContext(text: String) -> String? {
22702270
// Pre-compiled regex patterns for better performance
22712271
let inferencePatterns: [String: [String]] = [
2272-
"steps": [
2273-
"\\b(?:walk|walked|walking)\\b(?!\\s+distance)",
2274-
"\\bhow\\s+much.*(?:walk|walked)\\b",
2275-
"\\bsteps?\\b",
2276-
"\\bpace|paces|stride|strides|footsteps?\\b",
2277-
"\\bmove|moved|movement|activity\\b"
2278-
],
22792272
"distance": [
2273+
"\\bhow\\s+(?:much|many)\\s+distance\\b",
22802274
"\\bhow\\s+far\\b",
2281-
"\\b(?:walk|walked|walking)\\s+(?:distance|far)\\b",
22822275
"\\bdistance.*(?:walk|walked)\\b",
2276+
"\\bhow\\s+(?:much|many).*distance.*(?:walk|walked|run|ran|travel|travelled|traveled|cover|covered)\\b",
2277+
"\\b(?:walk|walked|walking)\\s+(?:distance|far)\\b",
22832278
"\\bkilometers?\\b|\\bmiles?\\b|\\bkm\\b",
22842279
"\\btravelled?|traveled|covered|journey|route|path\\b"
22852280
],
2281+
"steps": [
2282+
"\\b(?:walk|walked|walking)\\b(?!\\s+distance)",
2283+
"\\bhow\\s+(?:much|many)(?!.*distance).*(?:walk|walked)\\b",
2284+
"\\bsteps?\\b",
2285+
"\\bpace|paces|stride|strides|footsteps?\\b",
2286+
"\\bmove|moved|movement|activity\\b"
2287+
],
22862288
"heart rate": [
22872289
"\\bheart\\s+rate\\b|\\bheartrate\\b|\\bpulse\\b|\\bhr\\b|\\bbpm\\b",
22882290
"\\bcardiac|cardio|cardiovascular\\b",

0 commit comments

Comments
 (0)