in utils/entity_resolution.py [0:0]
def _add_defaults(self, tree):
"""
This method adds the default (NUMBER 1 ) subtree to every tree rooted in
PIZZAORDER or DRINKORDER which does not already contain an occurrence of this node.
This is a convention in EXR that all orders have a default (NUMBER 1), but the
TOP format could be 'get me pie with X' which will have no NUMBER to resolve into the
default (NUMBER 1). Hence we need to add it before comparing to EXR.
:param: (ExpressSemanticTree) Input ExpressSemanticTree object.
:return: (ExpressSemanticTree) ExpressSemanticTree object with added defaults
"""
# Stopping criterion for our recursion
if tree.is_leaf():
return tree
# If the root node is either of the following two, we consider adding the defaults
if tree.root_symbol() in ['PIZZAORDER', 'DRINKORDER']:
# We only add the default if not already present
if all(c.root_symbol() != 'NUMBER' for c in tree.children()):
children = tree.children()
children.append(ExpressSemanticTree(flat_string=f"(NUMBER 1 )").children()[0])
return ExpressSemanticTree(root_symbol=tree.root_symbol(), children=children)
return ExpressSemanticTree(root_symbol=tree.root_symbol(), children=[self._add_defaults(c) for c in tree.children()])