new tokens

This commit is contained in:
team 1
2026-05-01 12:10:32 +02:00
parent f28deb9eff
commit 724afd4a26
8 changed files with 154 additions and 81 deletions

View File

@@ -612,27 +612,7 @@ final readonly class AgentRunner
private function containsStrongFollowUpReference(string $normalized): bool
{
$patterns = [
'/\bder\s+wert\b/u',
'/\bdieser\s+wert\b/u',
'/\bdiesen\s+wert\b/u',
'/\bdem\s+wert\b/u',
'/\bmit\s+welche(?:m|n|r)?\b/u',
'/\bwomit\b/u',
'/\bdamit\b/u',
'/\bdafuer\b/u',
'/\bdafür\b/u',
'/\bdazu\b/u',
'/\bdaraus\b/u',
'/\bwelche(?:r|s|m|n)?\s+indikator\b/u',
'/\bwelche(?:r|s|m|n)?\s+indikatortyp\b/u',
'/\bindikator\s+(?:dafuer|dafür|dazu|hierfuer|hierfür)\b/u',
'/\bwelche(?:r|s|m|n)?\s+bereich\b/u',
'/\bwelche(?:r|s|m|n)?\s+messbereich\b/u',
'/\bwelche(?:r|s|m|n)?\s+grenzwert\b/u',
];
foreach ($patterns as $pattern) {
foreach ($this->agentRunnerConfig->getFollowUpStrongReferencePatterns() as $pattern) {
if (preg_match($pattern, $normalized) === 1) {
return true;
}
@@ -643,14 +623,8 @@ final readonly class AgentRunner
private function containsExplicitCommercialFollowUpSignal(string $normalized): bool
{
$commercialSignals = [
'shop', 'preis', 'preise', 'kostet', 'kosten', 'kaufen', 'bestellen',
'warenkorb', 'lieferzeit', 'verfuegbar', 'verfügbar', 'lager', 'url',
'link', 'artikelnummer', 'sku', 'produktnummer',
];
foreach ($commercialSignals as $signal) {
if (str_contains($normalized, $signal)) {
foreach ($this->agentRunnerConfig->getFollowUpExplicitCommercialSignalTerms() as $signal) {
if (str_contains($normalized, mb_strtolower($signal, 'UTF-8'))) {
return true;
}
}
@@ -669,7 +643,7 @@ final readonly class AgentRunner
return [];
}
if (preg_match_all('/^Question:\s*(.+)$/mi', $history, $matches) !== 1) {
if (preg_match_all($this->agentRunnerConfig->getFollowUpHistoryQuestionPattern(), $history, $matches) !== 1) {
return [];
}
@@ -708,7 +682,7 @@ final readonly class AgentRunner
return [];
}
$answer = preg_replace('/^Question:\s*.*(?:\R|$)/u', '', $turn, 1) ?? '';
$answer = preg_replace($this->agentRunnerConfig->getFollowUpHistoryQuestionStripPattern(), '', $turn, 1) ?? '';
$answer = trim($answer);
if ($answer === '') {
@@ -738,7 +712,7 @@ final readonly class AgentRunner
return '';
}
$parts = preg_split('/(?=^Question:\s)/m', $history);
$parts = preg_split($this->agentRunnerConfig->getFollowUpHistoryTurnSplitPattern(), $history);
if ($parts === false || $parts === []) {
return '';
@@ -758,11 +732,7 @@ final readonly class AgentRunner
private function extractFirstTestomatModelAnchor(string $text): string
{
$pattern = '/\bTestomat(?:®)?\s+'
. '(?:\d{3,4}|EVO(?:\s+[A-Z]{2,6})?|ECO(?:[-\s]?(?:PLUS|C))?|DUO(?:\s+\d{3,4})?|LAB(?:\s+[A-Z]{2,6})?)'
. '\b/iu';
if (preg_match($pattern, $text, $matches) !== 1) {
if (preg_match($this->agentRunnerConfig->getFollowUpReferenceAnchorTestomatModelPattern(), $text, $matches) !== 1) {
return '';
}
@@ -774,7 +744,7 @@ final readonly class AgentRunner
private function extractFirstHardnessValueAnchor(string $text): string
{
if (preg_match('/\b\d+(?:[,.]\d+)?\s*°\s*dH\b/iu', $text, $matches) !== 1) {
if (preg_match($this->agentRunnerConfig->getFollowUpReferenceAnchorHardnessValuePattern(), $text, $matches) !== 1) {
return '';
}

View File

@@ -512,18 +512,7 @@ final readonly class CommerceQueryParser
return true;
}
return in_array($token, [
'shop',
'store',
'produkt',
'produkte',
'artikel',
'kaufen',
'kaufe',
'bestellen',
'bestelle',
'online',
], true);
return in_array($token, $this->config->getSearchControlTokens(), true);
}
private function isDirectProductQuery(string $prompt): bool

View File

@@ -5,9 +5,15 @@ declare(strict_types=1);
namespace App\Commerce;
use App\Commerce\Dto\CommerceReferenceContext;
use App\Config\CommerceReferenceResolverConfig;
final readonly class CommerceReferenceResolver
{
public function __construct(
private CommerceReferenceResolverConfig $config,
) {
}
/**
* @param array<int, array<string, mixed>> $shopResults
*/
@@ -84,20 +90,7 @@ final readonly class CommerceReferenceResolver
return null;
}
$patterns = [
'/\b(Testomat\s+2000\s+THCL)\b/ui',
'/\b(Testomat\s+808)\b/ui',
'/\b(Testomat\s+EVO\s+TH)\b/ui',
'/\b(Testomat\s+EVO\s+CALC)\b/ui',
'/\b(Testomat\s+ECO\s+PLUS)\b/ui',
'/\b(Testomat\s+ECO\s+C)\b/ui',
'/\b(Testomat\s+ECO)\b/ui',
'/\b(Testomat\s+LAB\s+CL)\b/ui',
'/\b(Testomat\s+LAB\s+MONO)\b/ui',
'/\b(Testomat\s+2000)\b/ui',
];
foreach ($patterns as $pattern) {
foreach ($this->config->getConversationProductPatterns() as $pattern) {
if (!preg_match($pattern, $text, $matches)) {
continue;
}
@@ -135,25 +128,9 @@ final readonly class CommerceReferenceResolver
return [];
}
$patterns = [
'indikator' => '/\bindikator(?:en)?\b/u',
'indikatoren' => '/\bindikator(?:en)?\b/u',
'reagenz' => '/\breagenz(?:ien)?\b/u',
'reagenzien' => '/\breagenz(?:ien)?\b/u',
'zubehör' => '/\bzubeh[oö]r\b/u',
'ersatzteil' => '/\bersatzteile?\b/u',
'ersatzteile' => '/\bersatzteile?\b/u',
'service-set' => '/\bservice(?:\s|-)?set\b/u',
'filter' => '/\bfilter\b/u',
'pumpenkopf' => '/\bpumpenkopf\b/u',
'motorblock' => '/\bmotorblock\b/u',
'mehrwertpaket' => '/\bmehrwertpaket\b/u',
'neotecmaster' => '/\bneotecmaster\b/u',
];
$terms = [];
foreach ($patterns as $canonical => $pattern) {
foreach ($this->config->getFocusTermPatterns() as $canonical => $pattern) {
if (preg_match($pattern, $normalized) === 1) {
$terms[] = $canonical;
}

View File

@@ -39,6 +39,47 @@ final class AgentRunnerConfig
return $this->getRequiredString('optimized_shop_query_trim_characters');
}
/**
* @return string[]
*/
public function getFollowUpStrongReferencePatterns(): array
{
return $this->getRequiredStringList('follow_up_context.strong_reference_patterns');
}
/**
* @return string[]
*/
public function getFollowUpExplicitCommercialSignalTerms(): array
{
return $this->getRequiredStringList('follow_up_context.explicit_commercial_signal_terms');
}
public function getFollowUpHistoryQuestionPattern(): string
{
return $this->getRequiredString('follow_up_context.history_question_pattern');
}
public function getFollowUpHistoryTurnSplitPattern(): string
{
return $this->getRequiredString('follow_up_context.history_turn_split_pattern');
}
public function getFollowUpHistoryQuestionStripPattern(): string
{
return $this->getRequiredString('follow_up_context.history_question_strip_pattern');
}
public function getFollowUpReferenceAnchorTestomatModelPattern(): string
{
return $this->getRequiredString('follow_up_context.reference_anchor.testomat_model_pattern');
}
public function getFollowUpReferenceAnchorHardnessValuePattern(): string
{
return $this->getRequiredString('follow_up_context.reference_anchor.hardness_value_pattern');
}
private function getRequiredInt(string $key): int
{
$value = $this->requiredValue($key);

View File

@@ -48,6 +48,12 @@ final class CommerceQueryParserConfig
return $this->stringList('filter_search_tokens');
}
/** @return string[] */
public function getSearchControlTokens(): array
{
return $this->stringList('search_control_tokens');
}
/** @return string[] */
private function whitespacePreservingStringList(string $path): array
{