main
黄海 5 months ago
parent 6a6a9b4cf0
commit daa55427ad

@ -4,6 +4,7 @@ import re
from Util import *
from Config import *
class K2_Neo4jExecutor:
def __init__(self, uri, auth):
self.graph = Graph(uri, auth=auth)
@ -57,7 +58,7 @@ class K2_Neo4jExecutor:
return stats
if __name__ == '__main__':
def init():
executor = K2_Neo4jExecutor(
uri=NEO4J_URI,
auth=NEO4J_AUTH
@ -85,3 +86,6 @@ if __name__ == '__main__':
f = "优化.cypher"
executor.execute_cypher_file(f)
if __name__ == '__main__':
init()

@ -1,21 +1,43 @@
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')
# 测试用例
test_content = '''
题目一个长方体的长是8厘米宽是5厘米高是3厘米求它的表面积是多少平方厘米
'''
try:
kg = KnowledgeGraph(test_content)
success, cypher = kg.run()
res = executor.execute_cypher_text(cypher)
print("恭喜,执行数据插入完成!")
except Exception as e:
print(f"程序初始化失败: {str(e)}")
# 验证分割结果
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)}")

@ -0,0 +1,32 @@
### 三年级
1. 【购物计算】小明用50元买了3本笔记本每本8元还剩多少钱
- 答案50 - 3×8 = 26元
2. 【乘法应用】学校食堂每天消耗15袋大米一周5天需要准备多少袋
- 答案15×5 = 75袋
3. 【周长计算】一个正方形花坛边长3米要在四周围栅栏需要多长的栅栏
- 答案3×4 = 12米
### 四年级
4. 【四则运算】图书馆原有图书1250本上午借出368本下午归还195本现有多少本
- 答案1250 - 368 + 195 = 1077本
5. 【面积问题】长方形果园长25米宽比长短7米这个果园的面积是多少
- 答案25×(25-7) = 450平方米
6. 【时间问题】甲乙两车从相距240公里的两地同时出发相向而行甲车时速60公里乙车时速40公里几小时后相遇
- 答案240÷(60+40) = 2.4小时
### 五年级
7. 【分数运算】果汁店第一天卖出3/4吨橙汁第二天卖出1/2吨苹果汁两天共卖出多少吨
- 答案3/4 + 1/2 = 5/4吨
8. 【小数应用】文具店钢笔单价12.5元买4支送1支买20支实际要付多少钱
- 答案:(20÷5)×4×12.5 = 200元
9. 【体积计算】长方体游泳池长25米宽12米深1.8米,这个游泳池最多能装多少立方米水?
- 答案25×12×1.8 = 540立方米
10. 【比例问题】妈妈给小明和妹妹36元零花钱按5:4分配小明能得多少元
- 答案36÷(5+4)×5 = 20元

@ -1,15 +0,0 @@
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;
MERGE (kp1:KnowledgePoint {id: "KP_e99a18", name: "周长计算", level: "小学"});
MERGE (kp2:KnowledgePoint {id: "KP_5d4140", name: "图形拼接", level: "小学"});
MERGE (ab1:AbilityPoint {id: "AB_e99a18", name: "图形理解", category: "空间想象"});
MERGE (ab2:AbilityPoint {id: "AB_5d4140", name: "数学运算", category: "计算"});
MERGE (q:Question {id: "66c060a1", content: "通过7个小长方形拼成的大长方形的周长计算", difficulty: 2});
MATCH (q:Question {id: "66c060a1"}), (kp1:KnowledgePoint {id: "KP_e99a18"})
MERGE (q)-[:TESTS_KNOWLEDGE {weight: 0.8}]->(kp1);
MATCH (q:Question {id: "66c060a1"}), (kp2:KnowledgePoint {id: "KP_5d4140"})
MERGE (q)-[:TESTS_KNOWLEDGE {weight: 0.6}]->(kp2);
MATCH (q:Question {id: "66c060a1"}), (ab1:AbilityPoint {id: "AB_e99a18"})
MERGE (q)-[:REQUIRES_ABILITY {weight: 0.7}]->(ab1);
MATCH (q:Question {id: "66c060a1"}), (ab2:AbilityPoint {id: "AB_5d4140"})
MERGE (q)-[:REQUIRES_ABILITY {weight: 0.9}]->(ab2);
Loading…
Cancel
Save