diff --git a/src/Intent/SalesIntentLite.php b/src/Intent/SalesIntentLite.php index ae5e114..b623f94 100644 --- a/src/Intent/SalesIntentLite.php +++ b/src/Intent/SalesIntentLite.php @@ -13,10 +13,29 @@ final class SalesIntentLite public const IMPLEMENTATION = 'implementation'; public const ROI = 'roi'; + /** + * Mindestabstand zwischen Top1 und Top2, + * damit ein Intent wirklich dominant ist. + */ + private const DOMINANCE_DELTA = 2; + + /** + * Mindestscore, damit überhaupt ein Nicht-Discovery-Intent + * akzeptiert wird. + */ + private const MIN_SCORE_THRESHOLD = 3; + public function detect(string $originalPrompt): array { $p = $this->normalize($originalPrompt); + if ($p === '') { + return [ + 'intent' => self::DISCOVERY, + 'score' => 0, + ]; + } + $scores = [ self::PRICING => 0, self::COMPARISON => 0, @@ -26,7 +45,7 @@ final class SalesIntentLite ]; // ------------------------------------------------------------ - // PRICING (stark gewichten) + // PRICING // ------------------------------------------------------------ foreach ([ 'preis','preise','kosten','lizenz','lizenzmodell', @@ -39,13 +58,12 @@ final class SalesIntentLite } // ------------------------------------------------------------ - // COMPARISON (wichtiger für Katalog-Block) + // COMPARISON // ------------------------------------------------------------ foreach ([ '/\bvergleich(en)?\b/u', '/\bvs\b/u', '/\bgegenueber\b/u', - '/\boder\b/u', '/\balternative(n)?\b/u', '/\bunterschied(e)?\b/u', '/\bbesser\b/u' @@ -69,7 +87,7 @@ final class SalesIntentLite } // ------------------------------------------------------------ - // IMPLEMENTATION (Intent-Verben stärker) + // IMPLEMENTATION // ------------------------------------------------------------ foreach ([ 'implementierung','implementieren', @@ -85,7 +103,7 @@ final class SalesIntentLite } // ------------------------------------------------------------ - // ROI (weniger generisch) + // ROI // ------------------------------------------------------------ foreach ([ 'roi','rentabilitaet','rentabilität', @@ -98,18 +116,35 @@ final class SalesIntentLite } } + // ------------------------------------------------------------ + // Entscheidung + // ------------------------------------------------------------ + arsort($scores); - $topIntent = array_key_first($scores); - $topScore = $scores[$topIntent] ?? 0; + $intents = array_keys($scores); + $values = array_values($scores); - if ($topScore <= 0) { + $topIntent = $intents[0] ?? self::DISCOVERY; + $topScore = $values[0] ?? 0; + $secondScore = $values[1] ?? 0; + + // Kein relevanter Score → Discovery + if ($topScore < self::MIN_SCORE_THRESHOLD) { return [ 'intent' => self::DISCOVERY, 'score' => 0, ]; } + // Keine klare Dominanz → Discovery + if (($topScore - $secondScore) < self::DOMINANCE_DELTA) { + return [ + 'intent' => self::DISCOVERY, + 'score' => $topScore, + ]; + } + return [ 'intent' => $topIntent, 'score' => $topScore, @@ -121,10 +156,10 @@ final class SalesIntentLite $s = mb_strtolower($s); return strtr($s, [ - 'ä'=>'ae', - 'ö'=>'oe', - 'ü'=>'ue', - 'ß'=>'ss' + 'ä' => 'ae', + 'ö' => 'oe', + 'ü' => 'ue', + 'ß' => 'ss', ]); } } \ No newline at end of file