|
@@ -34,6 +34,8 @@ template_dict = {
|
|
|
"9.15": ["某年省间交易电量双边交易电量是多少?"],
|
|
|
"9.16": ["某年省间交易电量集中交易电量是多少?"],
|
|
|
"9.17": ["某年省间交易电量挂牌交易电量是多少?"],
|
|
|
+ "16.1": ["当月送出均价最高的是哪个省?","当年送出均价最高的是哪个省?"],
|
|
|
+ "16.2": ["当月送出均价最低的是哪个省?","当年送出均价最低的是哪个省?"],
|
|
|
"17.1": ["那个省送出电量最高?是多少?"],
|
|
|
"17.2": ["那个省受入电量最高?是多少?"],
|
|
|
"17.3": ["那个省送出电量最低?是多少?"],
|
|
@@ -209,6 +211,15 @@ def extract_time_location(question: str) -> Tuple[List[Dict], List[str]]:
|
|
|
prev_month = current_month - 1 if current_month > 1 else 12
|
|
|
time_results.append({'year': prev_year, 'month': prev_month, 'label': '上个月', 'raw': '上个月'})
|
|
|
used_keywords.add('上个月')
|
|
|
+ # ✅ 添加:当年
|
|
|
+ if '当年' in question and '当年' not in used_keywords:
|
|
|
+ time_results.append({'year': current_year, 'label': '当年', 'raw': '当年'})
|
|
|
+ used_keywords.add('当年')
|
|
|
+
|
|
|
+ # ✅ 添加:当月
|
|
|
+ if '当月' in question and '当月' not in used_keywords:
|
|
|
+ time_results.append({'year': current_year, 'month': current_month, 'label': '当月', 'raw': '当月'})
|
|
|
+ used_keywords.add('当月')
|
|
|
|
|
|
# 季度和半年
|
|
|
for term, (start_month, end_month) in season_mapping.items():
|
|
@@ -235,7 +246,7 @@ def extract_time_location(question: str) -> Tuple[List[Dict], List[str]]:
|
|
|
def classify_by_time_type(query, time_info):
|
|
|
if not time_info:
|
|
|
# 无时间信息时,返回指定模板 19-23
|
|
|
- return ['19', '20', '21', '22', '23', '17.1', '17.2', '17.3', '17.4']
|
|
|
+ return ['19', '20', '21', '22', '23', '17.1', '17.2', '17.3', '17.4', '18.1', '18.2', '18.3', '18.4']
|
|
|
|
|
|
time = time_info[0]
|
|
|
|
|
@@ -245,21 +256,21 @@ def classify_by_time_type(query, time_info):
|
|
|
|
|
|
# 情况 2:有 year 和 month,精确到月
|
|
|
if 'year' in time and 'month' in time:
|
|
|
- return ['2'] # 某年某月交易电量
|
|
|
+ return ['2','16.1','16.2'] # 某年某月交易电量
|
|
|
|
|
|
# 情况 3:仅 year,全年
|
|
|
if 'year' in time and 'month' not in time:
|
|
|
- return ['1','8.1','8.2','8.3','8.4','9.1','9.2','9.3','9.4','9.5','9.6','9.7','9.8','9.9','9.10','9.11','9.12','9.13','9.14','9.15','9.16','9.17'] # 某年全年累计交易电量
|
|
|
+ return ['1','8.1','8.2','8.3','8.4','9.1','9.2','9.3','9.4','9.5','9.6','9.7','9.8','9.9','9.10','9.11','9.12','9.13','9.14','9.15','9.16','9.17','16.1','16.2'] # 某年全年累计交易电量
|
|
|
def match_template_with_time_filter(query, template_dict, tokenizer, extract_time_location_func):
|
|
|
"""
|
|
|
先基于时间信息筛选候选模板,再进行TF-IDF匹配。
|
|
|
"""
|
|
|
# 提取时间
|
|
|
time_info, _ = extract_time_location_func(query)
|
|
|
-
|
|
|
+ print(time_info)
|
|
|
# 通过时间判断候选模板 key
|
|
|
candidate_keys = classify_by_time_type(query, time_info)
|
|
|
-
|
|
|
+ print(candidate_keys)
|
|
|
# 构造候选子模板字典
|
|
|
filtered_template_dict = {k: template_dict[k] for k in candidate_keys}
|
|
|
# 使用你原来的 TF-IDF 匹配函数
|
|
@@ -473,36 +484,26 @@ def find_key_recursively(data, target_key):
|
|
|
# query = "当月省间交易完成的交易是多少?"
|
|
|
# query = "2024年1月到2月累计交易电量是多少?"
|
|
|
# query = "2023年省间交易电量新能源交易电量是多少??"
|
|
|
-# # query = "但同样阿贾克斯大口径的话我可合金外壳设计文件突然发?"
|
|
|
+# query = "但同样阿贾克斯大口径的话我可合金外壳设计文件突然发?"
|
|
|
|
|
|
|
|
|
-# query = "2023年省间交易电量新能源交易电量是多少??"
|
|
|
-# # query = "但同样阿贾克斯大口径的话我可合金外壳设计文件突然发?"
|
|
|
+query = "当月送出均价最高的是哪个省??"
|
|
|
|
|
|
-# json_folder = "templatesJson"
|
|
|
+json_folder = "templatesJson"
|
|
|
|
|
|
-#
|
|
|
-# json_folder = "templatesJson"
|
|
|
-# #
|
|
|
-# #
|
|
|
-# result = process_query(query, template_dict, json_folder)
|
|
|
-#
|
|
|
-
|
|
|
-
|
|
|
-# 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"]
|