42 lines
1.3 KiB
Dart
42 lines
1.3 KiB
Dart
import 'courses/courses.dart';
|
|
|
|
class WritingCheckResult {
|
|
const WritingCheckResult({required this.complete, required this.message});
|
|
|
|
final bool complete;
|
|
final String message;
|
|
}
|
|
|
|
/// A deliberately small offline checker for teaching tasks. The rule and the
|
|
/// hint come from the segment's writing task in the course JSON; it
|
|
/// checks only the essential information and never claims to grade
|
|
/// pronunciation or nuanced grammar.
|
|
class WritingFeedback {
|
|
const WritingFeedback._();
|
|
|
|
static WritingCheckResult check(String segmentId, String input) {
|
|
final activity = activityBySegmentId(segmentId);
|
|
final rule = activity.writingRequiredTerms;
|
|
final complete = rule.isEmpty
|
|
? RegExp(r"[a-z]+(?:'[a-z]+)?")
|
|
.allMatches(normalizeAnswer(input))
|
|
.map((match) => match.group(0))
|
|
.toSet()
|
|
.length >=
|
|
2
|
|
: matchesRule(input, rule);
|
|
if (complete) {
|
|
return const WritingCheckResult(
|
|
complete: true,
|
|
message: '这句已经表达完整。继续在对话里用一次吧。',
|
|
);
|
|
}
|
|
return WritingCheckResult(
|
|
complete: false,
|
|
message: activity.writingHint.isNotEmpty
|
|
? activity.writingHint
|
|
: '再补充一个完整英文句子。',
|
|
);
|
|
}
|
|
}
|