| 399 | return "" |
| 400 | # return ret[0] |
| 401 | def insert_origin_relations(working_dir): |
| 402 | dbname=os.path.basename(working_dir) |
| 403 | db = pymysql.connect(host='localhost',port=4321, user='root', |
| 404 | passwd='123',database=dbname, charset='utf8mb4') |
| 405 | cursor = db.cursor() |
| 406 | # relation_path=os.path.join(f"datasets/{dbname}","relation.jsonl") |
| 407 | # relation_path=os.path.join(f"/data/zyz/reproduce/HiRAG/eval/datasets/{dbname}/test") |
| 408 | relation_path=os.path.join(f"hi_ex/{dbname}","relation.jsonl") |
| 409 | # relation_path=os.path.join(f"32b/{dbname}","relation.jsonl") |
| 410 | with open(relation_path,"r")as f: |
| 411 | val=[] |
| 412 | for relation_l in f: |
| 413 | relation=json.loads(relation_l) |
| 414 | src_tgt=relation['src_tgt'] |
| 415 | tgt_src=relation['tgt_src'] |
| 416 | if len(src_tgt)>190 or len(tgt_src)>190: |
| 417 | print(f"src_tgt or tgt_src too long: {src_tgt} {tgt_src}") |
| 418 | continue |
| 419 | description=relation['description'] |
| 420 | weight=relation['weight'] |
| 421 | level=0 |
| 422 | val.append((src_tgt,tgt_src,description,weight,level)) |
| 423 | sql = "INSERT INTO relations(src_tgt, tgt_src, description, weight,level) VALUES (%s,%s,%s,%s,%s)" |
| 424 | try: |
| 425 | # 执行sql语句 |
| 426 | cursor.executemany(sql,tuple(val)) |
| 427 | # 提交到数据库执行 |
| 428 | db.commit() |
| 429 | except Exception as e: |
| 430 | # 发生错误时回滚 |
| 431 | db.rollback() |
| 432 | print(e) |
| 433 | print("insert relations error") |
| 434 | if __name__ == "__main__": |
| 435 | working_dir='exp/compare_hirag_opt1_commonkg_32b/mix' |
| 436 | # build_vector_search() |