summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Tan <s22505@ykpaoschool.cn>2023-03-07 20:19:22 +0800
committerAlbert Tan <s22505@ykpaoschool.cn>2023-03-07 20:19:22 +0800
commit92280a138399fb070b713fd14cb04af317be5658 (patch)
tree628a30fa126d55f2545562e8952ee025b11389a7
parenta0e11a7b74fd7960c21961685fbca640e0329399 (diff)
downloadreview_it-92280a138399fb070b713fd14cb04af317be5658.tar.gz
review_it-92280a138399fb070b713fd14cb04af317be5658.zip
v1.1
-rw-r--r--review_it.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/review_it.py b/review_it.py
index 0d0b044..7d70e11 100644
--- a/review_it.py
+++ b/review_it.py
@@ -1,11 +1,9 @@
'''
Updated:
-- Subtitles added
-- Support all files with the same major version
-- Slightly better output lines
+- More flexibility when judging whether answer is correct
To be updated:
-- Better ways of reminding input
+- Better ways to check syntax
- Let user judge whether answer is correct
- Zero / single / plural in final output
- Remove unnecessary spaces or line breaks in input file
@@ -13,6 +11,7 @@ To be updated:
- Answer judged correct if contains keyword
- Use something better than a dictionary to store incorrect answers
- Title also printed if answer in the section is incorrect
+- Consider to use json input file
- Graphic user interface
- Another program to help create related input file
- Optimize
@@ -21,19 +20,30 @@ To be updated:
try:
import re
+ import difflib
def check_string(line):
return bool(re.match("[!#-~] [\w\d\s]*", line))
+ def compare_string(answer, response):
+ diff = difflib.ndiff(answer, response)
+ diff_count = 0
+ for line in diff:
+ if line[0] != " ":
+ diff_count += 1
+ return 1 - (diff_count / len(response))
+
+
file_name = input("Enter file name (with postfix) >> ")
if file_name == "":
- file_name = "test_1.0.rvwt"
+ file_name = "test_1.1.rvwt"
with open(file_name) as f:
data = f.readlines()
count_prompts = 0
count_correct = 0
+ correct_param = 0.66
incorrect = []
@@ -66,6 +76,9 @@ try:
if response.lower() == answer.lower():
print("Correct")
count_correct += 1
+ elif compare_string(response.lower(), answer.lower()) >= correct_param:
+ print(f"Probably correct: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)*100}%")
+ count_correct += 1
else:
print(f"Incorrect: answer is '{answer}'")
incorrect.append((prompt, answer))
@@ -89,4 +102,4 @@ except Exception as e:
except KeyboardInterrupt:
print("\nProcess quitted")
except BaseException as e:
- print("\n" + str(e))
+ print("\nException: " + str(e))