optimize sale sintent

This commit is contained in:
team2
2026-03-03 08:11:24 +01:00
parent 1f93238bf4
commit 9d288b0b08

View File

@@ -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,
@@ -124,7 +159,7 @@ final class SalesIntentLite
'ä' => 'ae',
'ö' => 'oe',
'ü' => 'ue',
'ß'=>'ss'
'ß' => 'ss',
]);
}
}