Skip to content

Commit 1905d78

Browse files
committed
Initial support for using color as positional description argument queries
Addresses #48 SelectionQuery had to be modified In order to pass "index" as an extra When handling multiple inputs. These may have to change in the future as it may not be enough
1 parent b44e528 commit 1905d78

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111

1212
- add cut action
1313

14+
- Support for using negative indices to pick up arguments from the end of the function call
15+
16+
- Queries of the form `<color> argument 2`
17+
1418
### Code related
1519

20+
#### Changed
21+
22+
- The default implementation for handling selection queries that do not define handle_multiple, now sets in the extra dictionary not only "selection" but"index" as well
23+
1624
## [0.1.3]
1725

1826
Various stability issues resolved

queries/abstract/selection_query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ def __call__(self,view_information,query_description,extra = {}):
6767
return None,None
6868
self.result = []
6969
self.alternatives = []
70-
for s in selection:
70+
for i,s in enumerate(selection):
7171
temporary_extra = deepcopy(extra)
7272
temporary_extra["selection"] = s
73+
temporary_extra["index"] = i
7374
r,a = self.handle_single(view_information,query_description,temporary_extra)
7475
if not isinstance(r,list):
7576
r =[r]

queries/argument.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
from PythonVoiceCodingPlugin.library.LCA import LCA
1111
from PythonVoiceCodingPlugin.library.level_info import LevelVisitor
1212
from PythonVoiceCodingPlugin.library.partial import partially_parse, line_partial
13-
from PythonVoiceCodingPlugin.library.traverse import search_upwards,search_upwards_log, find_matching,match_node, find_all_nodes,search_upwards_for_parent
13+
from PythonVoiceCodingPlugin.library.traverse import (
14+
search_upwards,search_upwards_log, find_matching,match_node, find_all_nodes,search_upwards_for_parent
15+
)
1416

1517
from PythonVoiceCodingPlugin.queries.abstract import SelectionQuery
1618
from PythonVoiceCodingPlugin.queries.tiebreak import tiebreak_on_lca,tiebreak_on_visual
17-
from PythonVoiceCodingPlugin.queries.strategies import adjective_strategy,decode_abstract_vertical,translate_adjective,obtain_result
19+
from PythonVoiceCodingPlugin.queries.strategies import (
20+
adjective_strategy,decode_abstract_vertical,translate_adjective,obtain_result,
21+
decode_item_selection,result_alternatives_sequence
22+
)
1823

19-
#
2024
# a lot of this code needs rewriting at some point
2125
# it is a mess indeed but it works, mostly :)
2226
#
@@ -175,7 +179,8 @@ def process_line(self,q, root ,atok, origin = None, select_node = None,tiebreak
175179
def handle_single(self,view_information,query_description,extra = {}):
176180
f = query_description["format"]
177181
possibilities = {
178-
1: self.case_one,2: self.case_two,3: self.case_three,4: self.case_four,5:self.case_five,
182+
1: self.case_one,2: self.case_two,3: self.case_three,
183+
4: self.case_four,5:self.case_five,6:self.case_six
179184
}
180185
return possibilities[f](view_information,query_description, extra)
181186

@@ -409,4 +414,35 @@ def case_five(self,view_information,query_description, extra = {}):
409414
return self._backward_result(result, alternatives,build)
410415

411416

417+
def case_six(self,view_information,query_description, extra = {}):
418+
################################################################
419+
# <adjective> argument <argument_index>
420+
###############################################################
421+
state = extra["state"]
422+
index = extra.get("index",0)
423+
candidates = result_alternatives_sequence(state,location=True)
424+
if state["mode"]=="single":
425+
colorful_region = decode_item_selection(candidates,query_description,"individual","color",decrement=False)
426+
else:
427+
colorful_region = decode_item_selection(candidates[index],query_description,"individual","color",decrement=False)
428+
selection = colorful_region[0]
412429

430+
build = self.general_build if self.general_build else line_partial(self.code,selection[0])
431+
if not build or not build[0] :
432+
return None,None
433+
root,atok,m,r = build
434+
selection = m.forward(selection)
435+
436+
437+
origin = nearest_node_from_offset(root,atok, selection[0]) if selection[0]==selection[1] else node_from_range(root,atok, selection)
438+
statement_node = self.get_statement(origin,atok)
439+
result, alternatives = self.process_line(
440+
q = query_description,
441+
root = statement_node,
442+
atok = atok,
443+
origin = origin,
444+
select_node = origin if selection[0]!=selection[1] else None,
445+
tiebreaker = lambda x: tiebreak_on_lca(statement_node,origin,x),
446+
constrained_space = selection
447+
)
448+
return self._backward_result(result, alternatives,build)

0 commit comments

Comments
 (0)