|
|
|
@ -55,41 +55,51 @@ class EnglishEssayAnalyzer:
|
|
|
|
|
|
|
|
|
|
current_category = None
|
|
|
|
|
buffer = ""
|
|
|
|
|
for chunk in self.analyze_stream(essay): # 现在可以正确调用
|
|
|
|
|
category_pattern = re.compile(r'(\d+\.\s.*?)(:)') # 改进正则表达式
|
|
|
|
|
|
|
|
|
|
for chunk in self.analyze_stream(essay):
|
|
|
|
|
print(chunk, end='', flush=True)
|
|
|
|
|
buffer += chunk
|
|
|
|
|
|
|
|
|
|
# 分类检测逻辑
|
|
|
|
|
if re.match(r'^\d+\.\s', buffer):
|
|
|
|
|
if ':' in buffer:
|
|
|
|
|
parts = buffer.split(':', 1)
|
|
|
|
|
current_category = parts[0].strip()
|
|
|
|
|
buffer = parts[1]
|
|
|
|
|
|
|
|
|
|
# 初始化当前分类
|
|
|
|
|
if '语法' in current_category:
|
|
|
|
|
analysis['grammar_errors'].append('')
|
|
|
|
|
elif '用词' in current_category:
|
|
|
|
|
analysis['vocabulary_issues'].append('')
|
|
|
|
|
elif '逻辑' in current_category:
|
|
|
|
|
analysis['structure_problems'].append('')
|
|
|
|
|
elif '改进' in current_category:
|
|
|
|
|
analysis['suggestions'].append('')
|
|
|
|
|
|
|
|
|
|
# 内容填充
|
|
|
|
|
# 改进的分类检测逻辑
|
|
|
|
|
match = category_pattern.search(buffer)
|
|
|
|
|
if match:
|
|
|
|
|
current_category = match.group(1).strip()
|
|
|
|
|
buffer = buffer[match.end():] # 移除已匹配的部分
|
|
|
|
|
|
|
|
|
|
# 根据分类初始化条目
|
|
|
|
|
if '语法' in current_category:
|
|
|
|
|
analysis['grammar_errors'].append('')
|
|
|
|
|
elif '用词' in current_category:
|
|
|
|
|
analysis['vocabulary_issues'].append('')
|
|
|
|
|
elif '逻辑' in current_category:
|
|
|
|
|
analysis['structure_problems'].append('')
|
|
|
|
|
elif '改进' in current_category:
|
|
|
|
|
analysis['suggestions'].append('')
|
|
|
|
|
|
|
|
|
|
# 内容填充逻辑(改进版)
|
|
|
|
|
if current_category:
|
|
|
|
|
target_list = None
|
|
|
|
|
if '语法' in current_category:
|
|
|
|
|
analysis['grammar_errors'][-1] += chunk
|
|
|
|
|
target_list = analysis['grammar_errors']
|
|
|
|
|
elif '用词' in current_category:
|
|
|
|
|
analysis['vocabulary_issues'][-1] += chunk
|
|
|
|
|
target_list = analysis['vocabulary_issues']
|
|
|
|
|
elif '逻辑' in current_category:
|
|
|
|
|
analysis['structure_problems'][-1] += chunk
|
|
|
|
|
target_list = analysis['structure_problems']
|
|
|
|
|
elif '改进' in current_category:
|
|
|
|
|
analysis['suggestions'][-1] += chunk
|
|
|
|
|
target_list = analysis['suggestions']
|
|
|
|
|
|
|
|
|
|
if target_list and target_list:
|
|
|
|
|
target_list[-1] += chunk
|
|
|
|
|
|
|
|
|
|
# 后处理
|
|
|
|
|
# 后处理(增强版)
|
|
|
|
|
for key in analysis:
|
|
|
|
|
analysis[key] = [text.strip() for text in analysis[key] if text.strip()]
|
|
|
|
|
# 分割条目并清理空白
|
|
|
|
|
cleaned = []
|
|
|
|
|
for text in analysis[key]:
|
|
|
|
|
items = [t.strip() for t in re.split(r'\n(?=\d+\.)', text) if t.strip()]
|
|
|
|
|
cleaned.extend(items)
|
|
|
|
|
analysis[key] = cleaned
|
|
|
|
|
|
|
|
|
|
return analysis
|
|
|
|
|
|
|
|
|
|