Skip to content

Commit

Permalink
Propagate 'textclass' from FQL to the main library (as 'settextclass'…
Browse files Browse the repository at this point in the history
…). Allows setting textclass from a higher level and needed to solve proycon/flat#173
  • Loading branch information
proycon committed Apr 7, 2021
1 parent 5a28872 commit 241f59e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions folia/fql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ def substitute(self, query, substitution, contextselector, debug):

kwargs = self.assemblesuggestions(query,substitution,debug,kwargs)

if debug: print("[FQL EVALUATION DEBUG] Correction.substitute - Applying and returning correction",file=sys.stderr)
if debug: print("[FQL EVALUATION DEBUG] Correction.substitute - Applying and returning correction with keyword arguments:", repr(kwargs),file=sys.stderr)
return substitution['parent'].correct(**kwargs)


Expand All @@ -1278,6 +1278,10 @@ def assemblesuggestions(self, query, substitution, debug, kwargs):
except KeyError:
actionassignments['set'] = query.doc.defaultset(Class)
actionassignments['id'] = "corrected.%08x" % random.getrandbits(32) #generate a random ID
if 'textclass' in actionassignments:
#FQL uses text class differently (to set) than the folia library's textclass property (for provenance)
actionassignments['settextclass'] = actionassignments['textclass']
del actionassignments['textclass']
e = Class(query.doc, **actionassignments)
if debug: print("[FQL EVALUATION DEBUG] Correction.assemblesuggestions - Adding to new",file=sys.stderr)
kwargs['new'].append(e)
Expand Down Expand Up @@ -1674,10 +1678,11 @@ def __call__(self, query, contextselector, debug=False):
if debug: print("[FQL EVALUATION DEBUG] Action - setphon("+ value+ ") on focus ", repr(focus),file=sys.stderr)
focus.setphon(value)
else:
if debug: print("[FQL EVALUATION DEBUG] Action - settext("+ value+ ") on focus ", repr(focus),file=sys.stderr)
if attr == 'text' and 'textclass' in action.assignments:
if debug: print("[FQL EVALUATION DEBUG] Action - settext("+ value+ ",cls=" + action.assignments['textclass'] + ") on focus ", repr(focus),file=sys.stderr)
focus.settext(value, action.assignments['textclass'])
else:
if debug: print("[FQL EVALUATION DEBUG] Action - settext("+ value+ ") on focus ", repr(focus),file=sys.stderr)
focus.settext(value)
elif attr == "class":
if debug: print("[FQL EVALUATION DEBUG] Action - " + attr + " = " + value + " on focus ", repr(focus),file=sys.stderr)
Expand Down Expand Up @@ -1870,6 +1875,7 @@ def __call__(self, query, contextselector, debug=False):
constrainedtargetselection_all = []
constrainedtargetselection = []
if action.form:
if debug: print("[FQL EVALUATION DEBUG] Form - Invoking Subtitution through Form (" + repr(action.form)+")",file=sys.stderr)
result = action.form.substitute(query, substitution, None, debug)
if len(actions) > 1:
focusselection_all.append(result)
Expand Down
6 changes: 5 additions & 1 deletion folia/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,11 @@ def parsecommonarguments(self, doc, **kwargs):

if 'text' in kwargs:
if kwargs['text']:
self.settext(kwargs['text'])
if 'settextclass' in kwargs:
self.settext(kwargs['text'], kwargs['settextclass'])
del kwargs['settextclass']
else:
self.settext(kwargs['text'])
del kwargs['text']

if 'phon' in kwargs:
Expand Down

0 comments on commit 241f59e

Please sign in to comment.