Skip to content

Commit

Permalink
added 'textclass' support in FQL so a textclass can be set whilst set…
Browse files Browse the repository at this point in the history
…ting a text (proycon/flat#173)
  • Loading branch information
proycon committed Apr 6, 2021
1 parent 66bc220 commit b128a83
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion folia/fql.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def parse(q, i=0):
v = lambda x,y='cls': getattr(x,y)
elif q[i] in ("text","value","phon"):
v = lambda x,y='text': getattr(x,'value') if isinstance(x, (folia.Description, folia.Comment, folia.Content)) else getattr(x,'phon') if isinstance(x,folia.PhonContent) else getattr(x,'text')()
elif q[i] == 'textclass':
v = lambda x,y='text': getattr(x,'cls') if isinstance(x, folia.TextContent) else getattr(x,'textcontent')().cls
else:
v = lambda x,y=q[i]: getattr(x,y)
if q[i] == 'confidence':
Expand Down Expand Up @@ -1367,6 +1369,9 @@ def getassignments(q, i, assignments, focus=None):
key = 'text'
assignments[key] = q[i+1]
i+=2
elif q.kw(i, 'textclass'):
assignments[key] = q[i+1]
i+=2
elif q.kw(i, 'datetime'):
if q[i+1] == "now":
assignments[q[i]] = datetime.datetime.now()
Expand Down Expand Up @@ -1662,10 +1667,15 @@ def __call__(self, query, contextselector, debug=False):
focus.setphon(value)
else:
if debug: print("[FQL EVALUATION DEBUG] Action - settext("+ value+ ") on focus ", repr(focus),file=sys.stderr)
focus.settext(value)
if attr == 'text' and 'textclass' in action.assignments:
focus.settext(value, action.assignments['textclass'])
else:
focus.settext(value)
elif attr == "class":
if debug: print("[FQL EVALUATION DEBUG] Action - " + attr + " = " + value + " on focus ", repr(focus),file=sys.stderr)
focus.cls = value
elif attr == "textclass":
pass #is handled only in combination with setting text
else:
if debug: print("[FQL EVALUATION DEBUG] Action - " + attr + " = " + str(value) + " on focus ", repr(focus),file=sys.stderr)
setattr(focus, attr, value)
Expand Down

0 comments on commit b128a83

Please sign in to comment.