You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

from K1_KnowledgeGraph import *
from K2_Neo4jExecutor import *
# 切割试题
def split_questions(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# 使用正则表达式匹配题目块(包含答案)
pattern = r'(\d+\.\s+【.*?】.*?(?=\n\d+\.|\Z))'
questions = re.findall(pattern, content, re.DOTALL)
# 清洗每个题目块的空白字符
cleaned_questions = [q.strip() for q in questions]
return cleaned_questions[:10] # 确保只返回前10题
if __name__ == '__main__':
# 清库
init()
# 准备执行
executor = K2_Neo4jExecutor(
uri=NEO4J_URI,
auth=NEO4J_AUTH
)
# 使用示例
question_blocks = split_questions('ShiTi.md')
# 验证分割结果
for i, block in enumerate(question_blocks, 1):
print(f"{i}题块:")
print("-" * 50)
try:
kg = KnowledgeGraph(block)
success, cypher = kg.run()
print(cypher)
res = executor.execute_cypher_text(cypher)
print("恭喜,执行数据插入完成!")
except Exception as e:
print(f"程序初始化失败: {str(e)}")