| """Deterministic comparison baseline, explicitly not the proposed final agent.""" |
| from dataclasses import asdict |
| import re |
| from .actions import Action,Decision,Kind |
| from .features import candidates,lexical |
|
|
|
|
| class LexicalRoleBaseline: |
| def predict(self,goal,state,ticket): |
| elements = [asdict(e) for e in state.elements] |
| indices = candidates(goal,elements) |
| if not indices: |
| return Decision(ticket,Action(Kind.ASK_USER,('No candidate.',))) |
| index = max(indices,key=lambda i:(lexical(goal,elements[i])[2],lexical(goal,elements[i])[0])) |
| element = state.elements[index] |
| if element.role in {'textbox','searchbox'}: |
| kind = Kind.TYPE |
| elif element.role in {'combobox','listbox'}: |
| kind = Kind.SELECT |
| else: |
| kind = Kind.CLICK |
| args = (element.ref,) |
| if kind in {Kind.TYPE,Kind.SELECT}: |
| values = re.findall(r'"([^"\n]*)"',goal) |
| if len(values)!=1: |
| return Decision(ticket,Action(Kind.ASK_USER,('No unambiguous literal.',))) |
| args += (values[0],) |
| return Decision(ticket,Action(kind,args)) |
|
|