fix the regex in cleaning axtree

This commit is contained in:
alexisxy 2023-12-05 21:33:52 -05:00
parent 8210cd1be0
commit e989873eb5

View File

@ -562,14 +562,15 @@ class TextObervationProcessor(ObservationProcessor):
"""further clean accesibility tree"""
clean_lines: list[str] = []
for line in tree_str.split("\n"):
# remove statictext if the content already appears in the previous line
if "statictext" in line.lower():
prev_lines = clean_lines[-3:]
pattern = r"\[\d+\] StaticText '([^']+)'"
pattern = r"\[\d+\] StaticText (.+)"
match = re.search(pattern, line)
match = re.search(pattern, line, re.DOTALL)
if match:
static_text = match.group(1)
if all(
static_text = match.group(1)[1:-1] # remove the quotes
if static_text and all(
static_text not in prev_line
for prev_line in prev_lines
):