File size: 1,159 Bytes
795f737 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | """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))
|