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

Before Change


        finished_lambdas = set()
        for key, lambda_stack in new_lambda_stacks.items():
            if not lambda_stack:
                finished_lambdas.add(key)
        for finished_lambda in finished_lambdas:
            del new_lambda_stacks[finished_lambda]

        return GrammarState(nonterminal_stack=new_stack,

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: pyannote/pyannote-audio
Commit Name: 2fcc7e8c87bd3d8f44b491d1f43be7002a2db6d7
Time: 2019-04-08
Author: bredin@limsi.fr
File Name: pyannote/audio/labeling/tasks/base.py
Class Name: LabelingTaskGenerator
Method Name: _load_metadata


Project Name: dgasmith/opt_einsum
Commit Name: 265614193fce8dfc8aec34be3539d9b068f5b259
Time: 2018-08-18
Author: fritzo@uber.com
File Name: opt_einsum/parser.py
Class Name:
Method Name: convert_to_valid_einsum_chars