37 lines
1.4 KiB
PHP
37 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Communication;
|
|
|
|
use App\Enums\MessageIntent;
|
|
|
|
/**
|
|
* Rule-based intent of a message (V2.1). Deterministic and medium-independent; an AI classifier can later implement the
|
|
* same interface of work (E-035). Whatever the rules do not clearly recognise is {@see MessageIntent::Unclear}.
|
|
*/
|
|
class IntentClassifier
|
|
{
|
|
public function classify(string $text, bool $assignedToCase): MessageIntent
|
|
{
|
|
$text = mb_strtolower($text);
|
|
$has = fn (array $words): bool => (bool) preg_match('/('.implode('|', $words).')/u', $text);
|
|
|
|
if ($assignedToCase && $has(['umbuchen', 'verschieb', 'stornieren', 'stornierung', 'später anreisen', 'früher anreisen', 'ändern'])) {
|
|
return MessageIntent::ChangeRequest;
|
|
}
|
|
if ($assignedToCase && $has(['ankunft', 'uhr', 'personen', 'kennzeichen', 'adresse', 'telefon', 'handynummer'])) {
|
|
return MessageIntent::ProvideData;
|
|
}
|
|
if ($assignedToCase) {
|
|
return MessageIntent::CaseReply;
|
|
}
|
|
if ($has(['frei', 'verfügbar', 'buchen', 'reservieren', 'anreise', 'zeitraum', 'vom \d'])) {
|
|
return MessageIntent::StayInquiry;
|
|
}
|
|
if ($has(['\?', 'hund', 'haustier', 'parkplatz', 'wlan', 'preis', 'kosten', 'wie weit', 'strand', 'ausstattung'])) {
|
|
return MessageIntent::GeneralQuestion;
|
|
}
|
|
|
|
return MessageIntent::Unclear;
|
|
}
|
|
}
|