# -*- coding: utf-8 -*- # @Author: Gree # @Date: 2021-06-02 11:16:23 # @Last Modified by: Gree # @Last Modified time: 2021-06-02 11:26:10 import re import pandas as pd class AirconditionerCheck: """空调语料自动化分类的检查""" def airconditioner_check(self, row): """ airconditioner_check 函数: input: output: generator features: 空调语料自动化分类的检查 step1: 检查 airconditioner 的语料字段 domain、intent、response_text 是否正确 ✅ """ # 获取 domain domain = row['domain'] # 获取 query query = row['query'] # 获取 intent intent = row['intent'] # 获取 response_text response_text = row['response_text'] # 异常捕获 try: # 正则表达式匹配数据规律 query_result = re.search(r'.*?(空调|模式|制冷|制热|送风|把自动|停止风|打开加热|智能风|为自动|下出风|自清洁|环绕风|开风随|请休息|打开健康|抽湿|休息吧|温度提高5度格力金贝|无风感|祛湿).*', query) except Exception as e: print("The error of getting query_result in the module of airconditioner_check():", e) # 异常捕获 try: # 条件判断 if query_result is not None and '音量' not in query and '海洋风' not in query and '天气' not in query and '加热' not in query and '休息吧' not in query and '关闭空调关闭语音' not in query and query != '空调温度' and query != '把空调温度' and query != '下出风' and query != '格力空调最小音量': # 判断空调关键字是否落在 query if '空调' in query: row['domain_is_right'] = 'yes' if 'control' in intent: row['intent_is_right'] = 'yes' else: row['intent_is_right'] = 'no' if response_text == '': row['response_is_right'] = 'yes' else: pass else: row['domain_is_right'] = 'no' if 'control' in intent: row['intent_is_right'] = 'yes' else: row['intent_is_right'] = 'no' if response_text == '': row['response_is_right'] = 'yes' else: pass # 生成器 yield { 'date_time': row['date_time'], 'request_id': row['request_id'], 'mac_wifi': row['mac_wifi'], 'user_id': row['user_id'], 'query': query, 'domain': domain, 'intent': intent, 'response_text': response_text, 'domain_is_right': row['domain_is_right'], 'intent_is_right': row['intent_is_right'], 'response_is_right': row['response_is_right'] } else: # 生成器 yield { 'date_time': row['date_time'], 'request_id': row['request_id'], 'mac_wifi': row['mac_wifi'], 'user_id': row['user_id'], 'query': query, 'domain': domain, 'intent': intent, 'response_text': response_text, 'domain_is_right': "", 'intent_is_right': "", 'response_is_right': "" } except Exception as e: print("The error of getting generator in the module of airconditioner_check():", e)