|
|
@@ -63,7 +63,7 @@ async def execute_reg(log_id:str,tag_category_id:str,phrase: str)-> list:
|
|
|
from aitag_tag_info tti left join aitag_tag_category ttc
|
|
|
on tti.category_id = ttc.id
|
|
|
where ttc.is_delete=0 and tti.is_delete=0 and ttc.state = 0 and tti.state = 0 and tti.tag_level = ttc.visibility_level
|
|
|
- and '{phrase}' ~ tti.reg
|
|
|
+ and '{phrase}' ~ tti.reg and tti.reg is not null and length(tti.reg) > 0
|
|
|
"""
|
|
|
if tag_category_id:
|
|
|
sql += f""" and ttc.id = '{tag_category_id}'"""
|
|
|
@@ -124,11 +124,17 @@ def start_tagging(id:str, instucde: Optional[str] = None):
|
|
|
)
|
|
|
return is_marine
|
|
|
|
|
|
+def generate_html(phrase, matched_rule, tag_name):
|
|
|
+ highlighted_phrase = re.sub(matched_rule, r'<strong>\g<0></strong>', phrase)
|
|
|
+ html_output = f"映射文本【{highlighted_phrase}】与映射规则【{matched_rule}】匹配,映射为标签【{tag_name}】"
|
|
|
+ return html_output
|
|
|
+
|
|
|
# 定义预设规则匹配函数
|
|
|
def defined_rule_match(phrase: str):
|
|
|
+ phrase = re.sub(r'职业.*?(?=投向)', '', phrase)
|
|
|
result = []
|
|
|
try:
|
|
|
- sql = """select tag_type,tag_nm,defined_rule from aitag_predefined_rules where %s ~ defined_rule """
|
|
|
+ sql = """select DISTINCT on (tag_type,tag_nm) tag_type,tag_nm, defined_rule from aitag_predefined_rules where %s ~ defined_rule and defined_rule is not null and tag_nm is not null order by tag_type,tag_nm,defined_rule desc"""
|
|
|
rules = dao.query(sql, (phrase,))
|
|
|
print(rules)
|
|
|
if rules and len(rules) > 0:
|
|
|
@@ -138,7 +144,7 @@ def defined_rule_match(phrase: str):
|
|
|
if tag_info and len(tag_info) > 0:
|
|
|
result.append({
|
|
|
"id": tag_info[0][0],
|
|
|
- "desc": f"映射文本【{phrase}】与映射规则【{matched[2]}】匹配,映射为标签【{tag_info[0][2]}】",
|
|
|
+ "desc": generate_html(phrase, matched[2], tag_info[0][2]),
|
|
|
"passr": True,
|
|
|
"tag_code": tag_info[0][4],
|
|
|
"tag_name": tag_info[0][2],
|
|
|
@@ -181,6 +187,7 @@ async def run_ai_pipeline(log_id: str, tag_category_id: str, phrase: str, instuc
|
|
|
if result:
|
|
|
try:
|
|
|
tags = dao.query_dict(""" select id,tag_nm as tag_name,tag_code, tag_path,category_id,tag_prompt from aitag_tag_info where id in %s """, (tuple(result),))
|
|
|
+ logger.info(f"筛选结果: {tags}")
|
|
|
result = await reflect_check(phrase,is_marine, tags)
|
|
|
except Exception as e:
|
|
|
logger.error(f"LLM reflection check failed: {e}")
|