fix: 输入校验忽略多个连续空格与大小写;统一中英文引号与空白规范化
This commit is contained in:
@@ -13,13 +13,20 @@ class ReviewCheckResult {
|
||||
class ReviewFeedback {
|
||||
const ReviewFeedback._();
|
||||
|
||||
static String _normalize(String input) => input
|
||||
.toLowerCase()
|
||||
.replaceAll('’', "'")
|
||||
.replaceAll('‘', "'")
|
||||
.replaceAll(RegExp(r'\s+'), ' ')
|
||||
.trim();
|
||||
|
||||
static ReviewCheckResult check(ReviewItem item, String input) {
|
||||
final text = input.toLowerCase().replaceAll('’', "'");
|
||||
final text = _normalize(input);
|
||||
final tokens = RegExp(
|
||||
r"[a-z]+(?:'[a-z]+)?",
|
||||
).allMatches(text).map((match) => match.group(0)!).toSet();
|
||||
bool has(String token) => tokens.contains(token);
|
||||
bool phrase(String value) => text.contains(value);
|
||||
bool has(String token) => tokens.contains(_normalize(token));
|
||||
bool phrase(String value) => text.contains(_normalize(value));
|
||||
bool hasAny(Iterable<String> values) => values.any(has);
|
||||
final introduction =
|
||||
phrase("i'm") || phrase('i am') || phrase('my name is');
|
||||
@@ -68,9 +75,8 @@ class ReviewFeedback {
|
||||
'A0-P19' => phrase('do you like'),
|
||||
'A0-P20' =>
|
||||
phrase('please say that again') || phrase('please speak slowly'),
|
||||
_ when item.id.startsWith('A0-W') => tokens.contains(
|
||||
item.target.toLowerCase(),
|
||||
),
|
||||
_ when item.id.startsWith('A0-W') =>
|
||||
tokens.contains(_normalize(item.target)) || phrase(item.target),
|
||||
_ => tokens.length >= 2,
|
||||
};
|
||||
return ReviewCheckResult(
|
||||
|
||||
Reference in New Issue
Block a user