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

Before Change


        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

        productions = self._get_productions_from_string(right_side)
        // Looking for lambda productions, but not for cells or columns with the word "lambda" in

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,
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

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: MolSSI/QCEngine
Commit Name: ec327b6f6735efa8f37240b05df42a5ebb5c40c9
Time: 2020-02-04
Author: dgasmith@vt.edu
File Name: qcengine/programs/tests/test_qchem.py
Class Name:
Method Name: test_qchem_logfile_parser_qcscr


Project Name: GoogleCloudPlatform/PerfKitBenchmarker
Commit Name: 78a4138657b22aed8d47558ffe8fb7fa380ff917
Time: 2021-03-23
Author: tohaowu@google.com
File Name: perfkitbenchmarker/linux_benchmarks/nccl_benchmark.py
Class Name:
Method Name: Run