Browse Source

djl演示版本

dujunlong 2 months ago
parent
commit
590dbb0290

+ 1 - 1
.idea/insertMysql.iml

@@ -2,7 +2,7 @@
 <module type="PYTHON_MODULE" version="4">
   <component name="NewModuleRootManager">
     <content url="file://$MODULE_DIR$" />
-    <orderEntry type="jdk" jdkName="Python 3.9 (BJKG)" jdkType="Python SDK" />
+    <orderEntry type="jdk" jdkName="VAE" jdkType="Python SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
 </module>

+ 1 - 1
.idea/misc.xml

@@ -3,5 +3,5 @@
   <component name="Black">
     <option name="sdkName" value="Python 3.9" />
   </component>
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (BJKG)" project-jdk-type="Python SDK" />
+  <component name="ProjectRootManager" version="2" project-jdk-name="VAE" project-jdk-type="Python SDK" />
 </project>

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


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


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


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


+ 1 - 1
final/ByRules/answer.py

@@ -153,7 +153,7 @@ def match_template_keywords(question: str) -> Tuple[str, str]:
     return "未知模板", "未知关键词"
 # 将地点映射成相应的代码
 def map_location_to_unit(location: str) -> str:
-    mapping_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../省间关系映射.json'))
+    mapping_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../sjgxys.json'))
     if not os.path.exists(mapping_path):
         print(f"映射文件未找到: {mapping_path}")
         return '未知单位'

+ 21 - 2
final/ByRules/app.py

@@ -1,3 +1,5 @@
+import sys
+
 from flask import Flask, request, jsonify
 
 from commonUtil import fill_template, fill_template_auto
@@ -10,10 +12,27 @@ app = Flask(__name__)
 # TEMPLATE_FOLDER = "templatesJson"
 # DATA_FOLDER = "..\Json\json_data"
 
+# def resource_path(relative_path):
+#     """适配开发环境 + PyInstaller,支持从项目根目录查找资源"""
+#     if getattr(sys, 'frozen', False):
+#         base_path = sys._MEIPASS
+#     else:
+#         # 向上两层回退到项目根目录:适配 ByRules 子目录结构
+#         base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
+#     return os.path.join(base_path, relative_path)
+#
+# MAPPING_FILE = resource_path("final/Json/sjgxys.json")
+# TEMPLATE_FOLDER = resource_path("final/ByRules/templatesJson")
+# DATA_FOLDER = resource_path("final/Json/json_data")
+
+
+
 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_FOLDER = os.path.join(BASE_DIR, "..", "Json", "sjgxys")
+
+MAPPING_FILE = os.path.join(MAPPING_FOLDER, "sjgxys.json")
 
 
 @app.route('/process_query', methods=['POST'])

+ 1 - 1
final/ByRules/app.spec

@@ -5,7 +5,7 @@ a = Analysis(
     ['app.py'],
     pathex=[],
     binaries=[],
-    datas=[('../Json/json_data', 'Json/json_data'), ('../Json/json_Schema', 'Json/json_Schema'), ('../Json/省间关系映射.json', 'Json/省间关系映射.json'), ('templatesJson', 'templatesJson')],
+    datas=[('../Json/json_data', 'Json/json_data'), ('../Json/json_Schema', 'Json/json_Schema'), ('../Json/sjgxys', 'Json/sjgxys'), ('templatesJson', 'templatesJson')],
     hiddenimports=[],
     hookspath=[],
     hooksconfig={},

+ 8 - 1
final/ByRules/buid.bat

@@ -1 +1,8 @@
-pyinstaller --noconfirm --onefile app.py --add-data "../Json/json_data;Json/json_data" --add-data "../Json/json_Schema;Json/json_Schema" --add-data "../Json/省间关系映射.json;Json/省间关系映射.json" --add-data "templatesJson;templatesJson"
+pyinstaller --noconfirm --onefile app.py --add-data "../Json/json_data;Json/json_data" --add-data "../Json/json_Schema;Json/json_Schema" --add-data "../Json/省间关系映射.json;Json/省间关系映射.json" --add-data "templatesJson;templatesJson"
+
+
+pyinstaller --noconfirm --onefile app.py --add-data "../Json/json_data;Json/json_data" --add-data "../Json/json_Schema;Json/json_Schema" --add-data "../Json/sjgxys.json;Json/sjgxys.json" --add-data "templatesJson;templatesJson"
+
+
+
+pyinstaller --noconfirm --onefile app.py --add-data "../Json/json_data;final/Json/json_data" --add-data "../Json/json_Schema;final/Json/json_Schema" --add-data "../Json/sjgxys.json;final/Json/sjgxys.json" --add-data "templatesJson;final/ByRules/templatesJson"

+ 5 - 2
final/ByRules/commonUtil.py

@@ -39,9 +39,12 @@ def fill_template_auto(template: str, result, keys: list = None) -> str:
         if placeholder_count != 1:
             raise ValueError("字符串只能替换一个占位符 `&`")
         values = [result]
-
+    # elif isinstance(result, None):
+    #     # values = ['未找到数据哦~']
+    #     return '未找到数据哦~'
     else:
-        raise TypeError("不支持的 result 类型")
+        return '未找到数据哦~'
+        # raise TypeError("不支持的 result 类型")
 
     # 拼接最终字符串
     output = ''

+ 1 - 1
final/ByRules/similarity_answer.py

@@ -126,7 +126,7 @@ def extract_time_location(question: str) -> Tuple[List[Dict], List[str]]:
     return time_results, locations
 # 将地点映射成相应的代码
 def map_location_to_unit(location: str) -> str:
-    mapping_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../省间关系映射.json'))
+    mapping_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../sjgxys.json'))
     if not os.path.exists(mapping_path):
         print(f"映射文件未找到: {mapping_path}")
         return '未知单位'

+ 5 - 3
final/ByRules/similarity_answer_json.py

@@ -52,10 +52,11 @@ template_dict = {
     "23": ["省间交易当年参与交易的家次有多少?"],
     "24": ["某年送出电量前五名是谁?"],
     "25": ["某年受入电量前五名是谁?"],
+    "26": ["某年送出电量第五名是谁?"],
 }
 # 将地点映射成相应的代码
 def map_location_to_unit(location: str) -> str:
-    mapping_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../省间关系映射.json'))
+    mapping_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../sjgxys.json'))
     if not os.path.exists(mapping_path):
         print(f"映射文件未找到: {mapping_path}")
         return '未知单位'
@@ -243,13 +244,14 @@ def extract_time_location(question: str) -> Tuple[List[Dict], List[str]]:
     # 中文数字转阿拉伯数字映射(可扩展)
     chinese_digit_map = {
         '一': 1, '二': 2, '三': 3, '四': 4, '五': 5,
-        '六': 6, '七': 7, '八': 8, '九': 9, '十': 10
+        '六': 6, '七': 7, '八': 8, '九': 9, '十': 10,
+        '两':2
     }
 
     # question = "2022年受入电量前五名是谁"
 
     # 匹配“前五”或“top 5”等形式
-    rank_match = re.search(r'(前|top\s*)(\d+|[一二三四五六七八九十])', question, re.IGNORECASE)
+    rank_match = re.search(r'(前|top\s*)(\d+|[一二三四五六七八九十])', question, re.IGNORECASE)
 
     # rank_match = re.search(
     #     r'(前|top\s*|第\s*)(\d+|[一二三四五六七八九十])\s*(名)?',

+ 11 - 0
final/ByRules/templatesJson/26.json

@@ -0,0 +1,11 @@
+{
+  "dataJsonName": "sjjy1_B05_output",
+  "type": "topN",
+  "value_key": "受入电量",
+  "name_key": "单位",
+  "top_n": 5,
+  "content": "送出电量排名分别为:&",
+  "play": "讲述文本",
+  "name": "省间交易",
+  "qcode": "25"
+}

+ 1 - 1
final/ByRules/util.py

@@ -307,7 +307,7 @@ if __name__ == '__main__':
     #
     # folder = "../Json/json_data"
     # filename = "sjjy1_B04_output.json"
-    # mapping_file = "../Json/省间关系映射.json"
+    # mapping_file = "../Json/sjgxys.json"
     # # conditions = {"年": 2025}
     # conditions = {}
     # result = find_max_or_min_value(

+ 2 - 0
final/Json/json_data/sjjy1_B06_output.json

@@ -1,4 +1,6 @@
 {
+  "年": 2025,
+  "月": 6,
   "正在组织": "601.0",
   "当月完成": "316.0",
   "当年完成": "1499.0",

+ 0 - 0
final/Json/省间关系映射.json → final/Json/sjgxys/sjgxys.json