Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 3989000

Browse files
kl2806matt-gardner
authored andcommitted
Bug fix binary expression in updates to grammar (#1869)
* fix biexpr * docs * pylint * fix types
1 parent 3d78e46 commit 3989000

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

allennlp/semparse/worlds/atis_world.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ def _update_grammar(self):
8787
ternary expression will refer to the start and end times.
8888
"""
8989

90-
# This will give us a shallow copy, but that's OK because everything
91-
# inside is immutable so we get a new copy of it.
90+
# This will give us a shallow copy. We have to be careful here because the ``Grammar`` object
91+
# contains ``Expression`` objects that have tuples containing the members of that expression.
92+
# We have to create new sub-expression objects so that original grammar is not mutated.
9293
new_grammar = copy(AtisWorld.sql_table_context.grammar)
9394

9495
numbers = self._get_numeric_database_values('number')
@@ -154,7 +155,9 @@ def _update_grammar(self):
154155
new_binary_expressions.extend([month_binary_expression,
155156
day_binary_expression])
156157

157-
new_grammar['biexpr'].members = new_grammar['biexpr'].members + tuple(new_binary_expressions)
158+
new_binary_expressions = new_binary_expressions + list(new_grammar['biexpr'].members)
159+
new_grammar['biexpr'] = OneOf(*new_binary_expressions, name='biexpr')
160+
self._update_expression_reference(new_grammar, 'condition', 'biexpr')
158161
return new_grammar
159162

160163
def _get_numeric_database_values(self,

0 commit comments

Comments
 (0)