文本控件筛选器

文本控件筛选是一种根据控件文本筛选控件的方法。代理在当前步骤的计划通常包含一些关键字或短语。此方法根据控件文本与代理计划中的关键字或短语的匹配程度来筛选控件。

配置

要激活文本控件筛选,您需要在 config_dev.yaml 文件中的 CONTROL_FILTER 列表中添加 TEXT。下面是 config_dev.yaml 文件中详细的文本控件筛选器配置:

  • CONTROL_FILTER: 您想要应用于控件的筛选方法列表。要激活文本控件筛选,请将 TEXT 添加到列表中。
  • CONTROL_FILTER_TOP_K_PLAN: 用于筛选控件的代理计划关键字或短语的数量。

参考

一个提供根据计划筛选控件项目的方法的类。

control_filter(control_dicts, plans) staticmethod

根据关键字筛选控件项目。

参数
  • control_dicts (Dict) –

    要筛选的控件项目字典。

  • plans (List[str]) –

    用于筛选的计划列表。

返回
  • Dict

    已过滤的控件项。

源代码在 automator/ui_control/control_filter.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@staticmethod
def control_filter(control_dicts: Dict, plans: List[str]) -> Dict:
    """
    Filters control items based on keywords.
    :param control_dicts: The dictionary of control items to be filtered.
    :param plans: The list of plans to be used for filtering.
    :return: The filtered control items.
    """
    filtered_control_dict = {}

    keywords = BasicControlFilter.plans_to_keywords(plans)
    for label, control_item in control_dicts.items():
        control_text = control_item.element_info.name.lower()
        if any(
            keyword in control_text or control_text in keyword
            for keyword in keywords
        ):
            filtered_control_dict[label] = control_item
    return filtered_control_dict