This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
fromK1_KnowledgeGraphimport*
fromNeo4j.K2_Neo4jExecutorimport*
# 切割试题
defsplit_questions(file_path):
withopen(file_path,'r',encoding='utf-8')asf:
content=f.read()
# 使用正则表达式匹配题目块(包含答案)
pattern=r'(\d+\.\s+【.*?】.*?(?=\n\d+\.|\Z))'
questions=re.findall(pattern,content,re.DOTALL)
# 清洗每个题目块的空白字符
cleaned_questions=[q.strip()forqinquestions]
returncleaned_questions[:10]# 确保只返回前10题
if__name__=='__main__':
# 清库
init()
# 准备执行
executor=K2_Neo4jExecutor(
uri=NEO4J_URI,
auth=NEO4J_AUTH
)
# 新增数据库约束(确保节点必须带ID)
init_script="""
CREATE CONSTRAINT IF NOT EXISTS FOR (kp:KnowledgePoint) REQUIRE kp.id IS UNIQUE;
CREATE CONSTRAINT IF NOT EXISTS FOR (ab:AbilityPoint) REQUIRE ab.id IS UNIQUE;
CREATE CONSTRAINT IF NOT EXISTS FOR (q:Question) REQUIRE q.id IS UNIQUE;