Пример #1
0
    def _initialize_grammar_dictionary(self, grammar_dictionary: Dict[str, List[str]]) -> Dict[str, List[str]]:
        # Add all the table and column names to the grammar.
        update_grammar_with_tables(grammar_dictionary, self.schema)

        if self.cursor is not None and not self.use_prelinked_entities:
            # Now if we have strings in the table, we need to be able to
            # produce them, so we find all of the strings in the tables here
            # and create production rules from them. We only do this if
            # we haven't pre-linked entities, because if we have, we don't
            # need to be able to generate the values - just the placeholder
            # symbols which link to them.
            grammar_dictionary["number"] = []
            grammar_dictionary["string"] = []
            update_grammar_with_table_values(grammar_dictionary, self.schema, self.cursor)

        # Finally, update the grammar with global, non-variable values
        # found in the dataset, if present.
        update_grammar_with_global_values(grammar_dictionary, self.dataset_name)

        if self.variable_free:
            update_grammar_to_be_variable_free(grammar_dictionary)

        if self.use_untyped_entities:
            update_grammar_with_untyped_entities(grammar_dictionary)

        return grammar_dictionary
Пример #2
0
    def _initialize_grammar_dictionary(
            self, grammar_dictionary: Dict[str,
                                           List[str]]) -> Dict[str, List[str]]:
        # Add all the table and column names to the grammar.
        update_grammar_with_tables(grammar_dictionary, self.schema)

        if self.cursor is not None and not self.use_prelinked_entities:
            # Now if we have strings in the table, we need to be able to
            # produce them, so we find all of the strings in the tables here
            # and create production rules from them. We only do this if
            # we haven't pre-linked entities, because if we have, we don't
            # need to be able to generate the values - just the placeholder
            # symbols which link to them.
            grammar_dictionary["number"] = []
            grammar_dictionary["string"] = []
            update_grammar_with_table_values(grammar_dictionary, self.schema,
                                             self.cursor)

        # Finally, update the grammar with global, non-variable values
        # found in the dataset, if present.
        update_grammar_with_global_values(grammar_dictionary,
                                          self.dataset_name)

        if self.variable_free:
            update_grammar_to_be_variable_free(grammar_dictionary)

        if self.use_untyped_entities:
            update_grammar_with_untyped_entities(grammar_dictionary)

        return grammar_dictionary
Пример #3
0
    def _initialize_grammar_dictionary(
            self, grammar_dictionary: Dict[str,
                                           List[str]]) -> Dict[str, List[str]]:
        # Add all the table and column names to the grammar.
        if self.schema:
            update_grammar_with_tables(grammar_dictionary, self.schema)

            if self.cursor is not None and not self.use_prelinked_entities:
                # Now if we have strings in the table, we need to be able to
                # produce them, so we find all of the strings in the tables here
                # and create production rules from them. We only do this if
                # we haven't pre-linked entities, because if we have, we don't
                # need to be able to generate the values - just the placeholder
                # symbols which link to them.
                grammar_dictionary["number"] = []
                grammar_dictionary["string"] = []

                update_grammar_with_table_values(grammar_dictionary,
                                                 self.schema, self.cursor)
            else:
                # TODO(Mark): The grammar can be tightened here if we don't need to
                # produce concrete values.
                pass

        return grammar_dictionary