Add README and extract_card.py
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
import json, sys
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
# Пример простого парсера: ищет ключевые слова в строках
|
||||||
|
|
||||||
|
def parse(text: str) -> Dict:
|
||||||
|
result = {
|
||||||
|
"title": None,
|
||||||
|
"subject": None,
|
||||||
|
"deadline_hint": None,
|
||||||
|
"deliverable_type": None,
|
||||||
|
"grading_hints": None,
|
||||||
|
}
|
||||||
|
for line in text.splitlines():
|
||||||
|
l=line.lower()
|
||||||
|
if "title" in l:
|
||||||
|
result["title"] = line.split(":",1)[-1].strip()
|
||||||
|
elif "subject" in l:
|
||||||
|
result["subject"] = line.split(":",1)[-1].strip()
|
||||||
|
elif "deadline" in l:
|
||||||
|
result["deadline_hint"] = line.split(":",1)[-1].strip()
|
||||||
|
elif "deliverable" in l:
|
||||||
|
result["deliverable_type"] = line.split(":",1)[-1].strip()
|
||||||
|
elif "grading" in l or "feedback" in l:
|
||||||
|
result["grading_hints"] = line.split(":",1)[-1].strip()
|
||||||
|
return result
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage: python extract_card.py <path_to_raw_text_file>")
|
||||||
|
sys.exit(1)
|
||||||
|
with open(sys.argv[1],"r",encoding="utf-8") as f:
|
||||||
|
text=f.read()
|
||||||
|
card=parse(text)
|
||||||
|
print(json.dumps(card,ensure_ascii=False,indent=2))
|
||||||
Reference in New Issue
Block a user