Skip to content

Commit

Permalink
Added tagging support to FQL library (proycon/folia#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Apr 6, 2021
1 parent b128a83 commit 7712e09
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion folia/fql.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ def parse(q, i=0):
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
v = lambda x,y='current': getattr(x,'cls') if isinstance(x, folia.TextContent) else getattr(x,'textcontent')().cls
elif q[i] == 'tag':
v = lambda x,y='sometag': y if x.hastag(y) else False
else:
v = lambda x,y=q[i]: getattr(x,y)
if q[i] == 'confidence':
Expand Down Expand Up @@ -1372,6 +1374,12 @@ def getassignments(q, i, assignments, focus=None):
elif q.kw(i, 'textclass'):
assignments[key] = q[i+1]
i+=2
elif q.kw(i, 'tag'):
assignments[key] = q[i+1]
i+=2
elif q.kw(i, 'untag'):
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 @@ -1676,6 +1684,10 @@ def __call__(self, query, contextselector, debug=False):
focus.cls = value
elif attr == "textclass":
pass #is handled only in combination with setting text
elif attr == "tag":
focus.tag(value)
elif attr == "untag":
focus.untag(value)
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 7712e09

Please sign in to comment.