From daa55427ad74bf44edb88de6b35a693e5bfdacec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Tue, 18 Feb 2025 14:22:46 +0800 Subject: [PATCH] 'commit' --- AI/Neo4j/K2_Neo4jExecutor.py | 6 ++- AI/Neo4j/K3_Start.py | 44 +++++++++++++----- AI/Neo4j/ShiTi.md | 32 +++++++++++++ .../K2_Neo4jExecutor.cpython-310.pyc | Bin 2878 -> 2987 bytes AI/Neo4j/knowledge_graph.cypher | 15 ------ 5 files changed, 70 insertions(+), 27 deletions(-) create mode 100644 AI/Neo4j/ShiTi.md delete mode 100644 AI/Neo4j/knowledge_graph.cypher diff --git a/AI/Neo4j/K2_Neo4jExecutor.py b/AI/Neo4j/K2_Neo4jExecutor.py index 035757f6..861a3a7f 100644 --- a/AI/Neo4j/K2_Neo4jExecutor.py +++ b/AI/Neo4j/K2_Neo4jExecutor.py @@ -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() diff --git a/AI/Neo4j/K3_Start.py b/AI/Neo4j/K3_Start.py index 106d83f4..1951f8e3 100644 --- a/AI/Neo4j/K3_Start.py +++ b/AI/Neo4j/K3_Start.py @@ -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)}") diff --git a/AI/Neo4j/ShiTi.md b/AI/Neo4j/ShiTi.md new file mode 100644 index 00000000..4a621bb1 --- /dev/null +++ b/AI/Neo4j/ShiTi.md @@ -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元 \ No newline at end of file diff --git a/AI/Neo4j/__pycache__/K2_Neo4jExecutor.cpython-310.pyc b/AI/Neo4j/__pycache__/K2_Neo4jExecutor.cpython-310.pyc index 8222e275ec28eea9203da5e5413c12547e8c7d85..d0ca6eee2feba61e02cb9c66ee6c34158bb4e8d0 100644 GIT binary patch delta 624 zcmbVKy-Ncz6wk}$?sBPB>~IcN5X4HwMX6&!5k(zT{8+ji+8k29ifIZCEgf_fl;9vD z=-}j7XJ>J95ad?>00##*H90>JC-FUgzvTV$^72S>?O%2bl#@w@v{`*utIY&Lk0$tO zmJUWVDs$*?AlJ>quHPv_^Kpv{i>1I delta 494 zcmZ22zE4aipO=@50SJozZcd-Z&A{*bpZK#l_t7mG1Y)G?_~WlLepW-97TWld#I zAT-IX2H>6k=i&+`OJy zo{^Df^LZ8%CT>k&SQJSCi7Jc9jI0Wi_1Nbz-kN-t-H}mgGC#-6$$8uolMisPYO;gE zi~~q;FmNymv51Kku>d)@IO5}T6EpMT<29LzK(a-wlM}c^CV%8~oovmO#3XoYvJ1B= zqsin2T+)UdsTHZor6u`Aw^);NQWJ}cKyguI2qKI@X0a8e7MJFf6sdwZ%;~8mlZ&{O Y1x$cE9!3r@Dar0O6Ny{{R30 diff --git a/AI/Neo4j/knowledge_graph.cypher b/AI/Neo4j/knowledge_graph.cypher deleted file mode 100644 index 22afbdc1..00000000 --- a/AI/Neo4j/knowledge_graph.cypher +++ /dev/null @@ -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); \ No newline at end of file