|
| 1 | +package org.dicio.skill.standard |
| 2 | + |
| 3 | +import io.kotest.core.spec.style.StringSpec |
| 4 | +import io.kotest.matchers.shouldNotBe |
| 5 | +import org.dicio.skill.skill.Specificity |
| 6 | +import org.dicio.skill.standard.construct.WordConstruct |
| 7 | +import org.dicio.skill.standard.construct.CompositeConstruct |
| 8 | +import org.dicio.skill.standard.util.MatchHelper |
| 9 | + |
| 10 | +/** |
| 11 | + * Regression test: StandardRecognizerData.score(MatchHelper, input) must work |
| 12 | + * without ctx.standardMatchHelper being set. This is needed when skills call |
| 13 | + * score() during generateOutput (e.g. CalculatorSkill matching operators). |
| 14 | + */ |
| 15 | +class StandardRecognizerDataTest : StringSpec({ |
| 16 | + |
| 17 | + "score with explicit MatchHelper does not require ctx" { |
| 18 | + // Build a simple recognizer that matches the word "plus" |
| 19 | + val construct = CompositeConstruct( |
| 20 | + listOf(WordConstruct("plus", false, false, 1.0f)) |
| 21 | + ) |
| 22 | + val data = StandardRecognizerData( |
| 23 | + specificity = Specificity.HIGH, |
| 24 | + converter = { input, sentenceId, _ -> sentenceId }, |
| 25 | + sentencesWithId = listOf(Pair("plus_sentence", construct)), |
| 26 | + ) |
| 27 | + |
| 28 | + val helper = MatchHelper(parserFormatter = null, userInput = "plus") |
| 29 | + val (score, result) = data.score(helper, "plus") |
| 30 | + |
| 31 | + score shouldNotBe null |
| 32 | + result shouldNotBe null |
| 33 | + } |
| 34 | + |
| 35 | + "score with explicit MatchHelper returns low score for non-matching input" { |
| 36 | + val construct = CompositeConstruct( |
| 37 | + listOf(WordConstruct("plus", false, false, 1.0f)) |
| 38 | + ) |
| 39 | + val data = StandardRecognizerData( |
| 40 | + specificity = Specificity.HIGH, |
| 41 | + converter = { input, sentenceId, _ -> sentenceId }, |
| 42 | + sentencesWithId = listOf(Pair("plus_sentence", construct)), |
| 43 | + ) |
| 44 | + |
| 45 | + val helper = MatchHelper(parserFormatter = null, userInput = "banana") |
| 46 | + val (score, _) = data.score(helper, "banana") |
| 47 | + |
| 48 | + // should score poorly since "banana" doesn't match "plus" |
| 49 | + assert(score.scoreIn01Range() < 0.5f) |
| 50 | + } |
| 51 | +}) |
0 commit comments