Skip to content

Commit 50ecb78

Browse files
committed
Tie-breaking on visual distance added
1 parent 474db74 commit 50ecb78

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

queries/argument.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from PythonVoiceCodingPlugin.library.traverse import search_upwards,search_upwards_log, find_matching,match_node, find_all_nodes,search_upwards_for_parent
1010

1111
from PythonVoiceCodingPlugin.queries.abstract import SelectionQuery
12-
from PythonVoiceCodingPlugin.queries.tiebreak import tiebreak_on_lca
12+
from PythonVoiceCodingPlugin.queries.tiebreak import tiebreak_on_lca,tiebreak_on_visual
1313
from PythonVoiceCodingPlugin.queries.strategies import adjective_strategy,decode_abstract_vertical,translate_adjective,obtain_result
1414

1515
#
@@ -111,7 +111,7 @@ def process_line(self,q, root ,atok, origin = None, select_node = None,tiebreak
111111
result,alternatives = obtain_result(None,temporary)
112112

113113
if second_tiebreaker:
114-
alternatives = second_tiebreaker(origin,result,alternatives)
114+
alternatives = second_tiebreaker(result,alternatives)
115115

116116

117117

@@ -195,7 +195,8 @@ def case_two(self,view_information,query_description, extra = {}):
195195
tiebreaker = lambda x: tiebreak_on_lca(statement_node,origin,x),
196196
line = nr+1,
197197
priority = priority,
198-
constrained_space = (view_information["text_point"](nr,0),view_information["text_point"](nr + 1,0))
198+
constrained_space = (view_information["text_point"](nr,0),view_information["text_point"](nr + 1,0)),
199+
second_tiebreaker = lambda x,y : tiebreak_on_visual(row + 1,x,y)
199200
)
200201
return self._backward_result(result, alternatives,build)
201202

queries/tiebreak.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ def tiebreak_on_lca(root,origin,candidates):
2626

2727

2828

29+
def tiebreak_on_visual(original_line,result,alternatives):
30+
if result:
31+
if original_line:
32+
k = lambda x: (
33+
abs(x.first_token.start[0] - result.first_token.start[0]) +
34+
(
35+
10 if (
36+
x.first_token.start[0]<=original_line<=result.first_token.start[0] or
37+
x.first_token.start[0]>=original_line>=result.first_token.start[0]
38+
) else 0
39+
)
40+
)
41+
else:
42+
k = lambda x: abs(x.first_token.start[0] - result.first_token.start[0])
43+
if alternatives:
44+
return sorted(alternatives, key = k)
45+
return alternatives
46+
2947

3048

3149

0 commit comments

Comments
 (0)