dujunlong 2 months ago
parent
commit
59ece1d9c3

BIN
final/ByRules/__pycache__/similarity_answer_json.cpython-38.pyc


+ 3 - 3
final/ByRules/app.py

@@ -1,6 +1,6 @@
 from flask import Flask, request, jsonify
 
-from final.ByRules.commonUtil import fill_template, fill_template_auto
+from commonUtil import fill_template, fill_template_auto
 from similarity_answer_json import *
 from util import *
 import os
@@ -12,8 +12,8 @@ app = Flask(__name__)
 
 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
 TEMPLATE_FOLDER = os.path.join(BASE_DIR, "templatesJson")
-DATA_FOLDER = os.path.join(BASE_DIR, "..", "Json", "json_data")
-MAPPING_FILE = os.path.join(BASE_DIR,"..", "Json", "省间关系映射.json")
+DATA_FOLDER = os.path.join(BASE_DIR, ".", "Json", "json_data")
+MAPPING_FILE = os.path.join(BASE_DIR,".", "Json", "省间关系映射.json")
 
 
 @app.route('/process_query', methods=['POST'])

+ 17 - 19
final/ByRules/similarity_answer_json.py

@@ -4,8 +4,6 @@ import jieba
 import os
 import json
 
-from final.ByRules.util import calculate_sum_by_time_range
-
 
 def jieba_tokenizer(text):
     return list(jieba.cut(text))
@@ -471,25 +469,25 @@ query = "2023年累计省间交易电量是多少??"
 # query = "2024年12月交易电量是多少?"
 # # query = "但同样阿贾克斯大口径的话我可合金外壳设计文件突然发?"
 
-query = "2023年省间交易电量新能源交易电量是多少??"
-# query = "但同样阿贾克斯大口径的话我可合金外壳设计文件突然发?"
-
-json_folder = "templatesJson"
+# query = "2023年省间交易电量新能源交易电量是多少??"
+# # query = "但同样阿贾克斯大口径的话我可合金外壳设计文件突然发?"
 #
+# json_folder = "templatesJson"
+# #
+# #
+# result = process_query(query, template_dict, json_folder)
 #
-result = process_query(query, template_dict, json_folder)
-
-print("匹配的模板 key:", result["matched_key"])
-print("最相似的模板句:", result["matched_template"])
-print("相似度分数:", result["similarity_score"])
-print("类型:", result["type"])
-print("关键词:", result["keywords"])
-print("查询字段:", result["target"])
-print("模型名字", result["name"])
-print("条件", result["conditions"])
-print("返回的内容是:", result["content"])
-print("问句是:", result["query"])
-print("动作是:", result["play"])
+# print("匹配的模板 key:", result["matched_key"])
+# print("最相似的模板句:", result["matched_template"])
+# print("相似度分数:", result["similarity_score"])
+# print("类型:", result["type"])
+# print("关键词:", result["keywords"])
+# print("查询字段:", result["target"])
+# print("模型名字", result["name"])
+# print("条件", result["conditions"])
+# print("返回的内容是:", result["content"])
+# print("问句是:", result["query"])
+# print("动作是:", result["play"])
 #
 # type = result["type"]
 # content = result["content"]

+ 25 - 25
final/ByRules/util.py

@@ -290,22 +290,22 @@ if __name__ == '__main__':
     # value = smart_find_value(folder, filename, conditions, target_field)
     # print("查询结果:", value)
     #
-    folder = "../Json/json_data"
-    filename = "sjjy1_B04_output.json"
-    mapping_file = "../Json/省间关系映射.json"
-    # conditions = {"年": 2025}
-    conditions = {}
-    result = find_max_or_min_value(
-        folder_path=folder,
-        file_name=filename,
-        value_key="送出电量",   # 要比较的数值字段
-        name_key="单位",  # 待寻找的字段(例如:年、月、单位)(哪一“年”、“月”,哪个“省”)
-        mapping_file=mapping_file,
-        find_max=True,  # 找最大值,
-        conditions=conditions
-    )
-
-    print("送出电量最高的省份:", result)
+    # folder = "../Json/json_data"
+    # filename = "sjjy1_B04_output.json"
+    # mapping_file = "../Json/省间关系映射.json"
+    # # conditions = {"年": 2025}
+    # conditions = {}
+    # result = find_max_or_min_value(
+    #     folder_path=folder,
+    #     file_name=filename,
+    #     value_key="送出电量",   # 要比较的数值字段
+    #     name_key="单位",  # 待寻找的字段(例如:年、月、单位)(哪一“年”、“月”,哪个“省”)
+    #     mapping_file=mapping_file,
+    #     find_max=True,  # 找最大值,
+    #     conditions=conditions
+    # )
+    #
+    # print("送出电量最高的省份:", result)
     #
     # folder = "Json/json_data"
     # filename = "2.json"
@@ -339,15 +339,15 @@ if __name__ == '__main__':
     #
     # print(result)
 
-    # diff = compare_or_calculate_fields(
-    #     folder_path="Json/json_data",
-    #     file_name="sjjy1_B02_output.json",
-    #     conditions={"年": 2025, "月": 3},
-    #     key1="受入",
-    #     key2="送出",
-    #     mode="value"    # 默认是text
-    # )
-    # print("受入和送出差价为:", diff)  # 输出:37.89
+    diff = compare_or_calculate_fields(
+        folder_path="../Json/json_data",
+        file_name="sjjy1_B02_output.json",
+        conditions={"年": 2025, "月": 3},
+        key1="受入",
+        key2="送出",
+        mode="value"    # 默认是text\可选value
+    )
+    print("受入和送出差价为:", diff)  # 输出:37.89
 
 
     # folder = "Json/json_data"