abfb32dd9303358c670a7567df445de02f560868,allennlp/nn/decoding/grammar_state.py,GrammarState,take_action,#GrammarState#Any#,84

Before Change


        assert self._nonterminal_stack[-1] == left_side, (f"Tried to expand {self._nonterminal_stack[-1]}"
                                                          "but got rule f{left_side}->f{right_side}")
        new_stack = self._nonterminal_stack[:-1]
        new_lambda_stacks = deepcopy(self._lambda_stacks)
        for key, lambda_stack in new_lambda_stacks.items():
            assert lambda_stack[-1] == left_side
            lambda_stack.pop()  // pop to modify the value in the dictionary

After Change


        assert all(self._lambda_stacks[key][-1] == left_side for key in self._lambda_stacks)

        new_stack = self._nonterminal_stack[:-1]
        new_lambda_stacks = {key: self._lambda_stacks[key][:-1] for key in self._lambda_stacks}

        productions = self._get_productions_from_string(right_side)
        // Looking for lambda productions, but not for cells or columns with the word "lambda" in
        // them.
        if "lambda" in productions[0] and "fb:" not in productions[0]:
            production = productions[0]
            if production[0] == """ and production[-1] == """:
                // The production rule with a lambda is typically "<t,d> -> ["lambda x", d]".  We
                // need to strip the quotes.
                production = production[1:-1]
            lambda_variable = production.split(" ")[1]
            // The left side must be formatted as "<t,d>", where "t" is the type of the lambda
            // variable, and "d" is the return type of the lambda function.  We need to pull out the
            // "t" here.  TODO(mattg): this is pretty limiting, but I"m not sure how general we
            // should make this.
            if len(left_side) != 5:
                raise NotImplementedError("Can"t handle this type yet:", left_side)
            lambda_type = left_side[1]
            new_lambda_stacks[(lambda_type, lambda_variable)] = []

        for production in reversed(productions):
            if self._is_nonterminal(production):
                new_stack.append(production)
                for lambda_stack in new_lambda_stacks.values():
                    lambda_stack.append(production)

        // If any of the lambda stacks have now become empty, we remove them from our dictionary.
        new_lambda_stacks = {key: new_lambda_stacks[key]
                             for key in new_lambda_stacks if new_lambda_stacks[key]}

        return GrammarState(nonterminal_stack=new_stack,
                            lambda_stacks=new_lambda_stacks,
                            valid_actions=self._valid_actions,
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 6

Instances


Project Name: allenai/allennlp
Commit Name: abfb32dd9303358c670a7567df445de02f560868
Time: 2018-08-24
Author: mattg@allenai.org
File Name: allennlp/nn/decoding/grammar_state.py
Class Name: GrammarState
Method Name: take_action


Project Name: automl/SMAC3
Commit Name: fe799dada87ef117262b19ee6776c359dfa6fb04
Time: 2017-05-24
Author: joshua.marben@neptun.uni-freiburg.de
File Name: smac/runhistory/runhistory2epm.py
Class Name: AbstractRunHistory2EPM
Method Name: transform


Project Name: MLWave/kepler-mapper
Commit Name: 7bc7f45172308e6dec76d8134facadeb20af04ee
Time: 2019-02-08
Author: nat@saulgill.com
File Name: kmapper/kmapper.py
Class Name: KeplerMapper
Method Name: _remove_duplicate_nodes


Project Name: dask/distributed
Commit Name: d202e6253ed8ddc7919d0d4f128d88954e9859b8
Time: 2019-05-28
Author: mrocklin@gmail.com
File Name: distributed/diagnostics/tests/test_eventstream.py
Class Name:
Method Name: test_eventstream