|
|
@ -420,9 +420,41 @@ FString USTTManagerBase::CheckForWordReplacement(const FString& InputText) |
|
|
|
|
|
|
|
|
for(const FSTTWordReplacement& Replacement : ProcessorConfig->BaseSettings.STTReplacements) |
|
|
for(const FSTTWordReplacement& Replacement : ProcessorConfig->BaseSettings.STTReplacements) |
|
|
{ |
|
|
{ |
|
|
for(const FString TranscribedWord : Replacement.TranscribedWords) |
|
|
for(const FString& TranscribedWord : Replacement.TranscribedWords) |
|
|
{ |
|
|
{ |
|
|
ResultString = ResultString.Replace(*TranscribedWord, *Replacement.ReplacementWord, ESearchCase::IgnoreCase); |
|
|
if (TranscribedWord.IsEmpty()) |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
const int32 MatchLen = TranscribedWord.Len(); |
|
|
|
|
|
FString Output; |
|
|
|
|
|
Output.Reserve(ResultString.Len()); |
|
|
|
|
|
|
|
|
|
|
|
int32 SearchStart = 0; |
|
|
|
|
|
while (SearchStart <= ResultString.Len() - MatchLen) |
|
|
|
|
|
{ |
|
|
|
|
|
const int32 FoundIdx = ResultString.Find(TranscribedWord, ESearchCase::IgnoreCase, ESearchDir::FromStart, SearchStart); |
|
|
|
|
|
if (FoundIdx == INDEX_NONE) |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
// Check word boundaries: reject if immediately preceded or followed by an alpha character
|
|
|
|
|
|
const bool bPrecededByAlpha = (FoundIdx > 0) && FChar::IsAlpha(ResultString[FoundIdx - 1]); |
|
|
|
|
|
const bool bFollowedByAlpha = (FoundIdx + MatchLen < ResultString.Len()) && FChar::IsAlpha(ResultString[FoundIdx + MatchLen]); |
|
|
|
|
|
|
|
|
|
|
|
if (bPrecededByAlpha || bFollowedByAlpha) |
|
|
|
|
|
{ |
|
|
|
|
|
Output += ResultString.Mid(SearchStart, FoundIdx - SearchStart + 1); |
|
|
|
|
|
SearchStart = FoundIdx + 1; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
Output += ResultString.Mid(SearchStart, FoundIdx - SearchStart); |
|
|
|
|
|
Output += Replacement.ReplacementWord; |
|
|
|
|
|
SearchStart = FoundIdx + MatchLen; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Output += ResultString.Mid(SearchStart); |
|
|
|
|
|
ResultString = MoveTemp(Output); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return ResultString; |
|
|
return ResultString; |
|
|
|