コード例 #1
0
 def from_json(dictionary: Dict[str, Any]) -> "NLToSQLInput":
     """Loads the NLToSQLInput attributes from a dictionary."""
     original_utterance = dictionary["original_utterance"]
     utterance_wordpieces = [
         Wordpiece.from_json(wordpiece)
         for wordpiece in dictionary["utterance_wordpieces"]
     ]
     tables = [DatabaseTable.from_json(table) for table in dictionary["tables"]]
     return NLToSQLInput(original_utterance, utterance_wordpieces, tables)
コード例 #2
0
ファイル: nl_to_sql_example.py プロジェクト: zzj0402/language
    def from_json(self, dictionary):
        """Loads the NLToSQLInput attributes from a dictionary."""
        self.original_utterance = dictionary['original_utterance']
        self.tables = [
            DatabaseTable().from_json(table) for table in dictionary['tables']
        ]
        self.utterance_wordpieces = [
            Wordpiece().from_json(wordpiece)
            for wordpiece in dictionary['utterance_wordpieces']
        ]

        return self
コード例 #3
0
ファイル: schema_utils.py プロジェクト: yyht/language
    def from_json(self, dictionary):
        """Converts from a JSON dictionary to a DatabaseTable object."""
        self.original_table_name = dictionary['original_table_name']
        self.table_name_wordpieces = [
            Wordpiece().from_json(wordpiece)
            for wordpiece in dictionary['table_name_wordpieces']
        ]
        self.table_columns = [
            TableColumn().from_json(column)
            for column in dictionary['table_columns']
        ]
        self.matches_to_utterance = dictionary['matches_to_utterance']

        return self
コード例 #4
0
  def from_json(self, dictionary):
    """Converts from a JSON representation to a SQL action."""
    # Should only have one key -- any of the above keys.
    assert len(dictionary) == 1
    if 'symbol' in dictionary:
      self.symbol = dictionary['symbol']
      return self

    if 'entity_copy' in dictionary:
      self.entity_copy = SchemaEntityCopy().from_json(dictionary['entity_copy'])
      return self

    if 'utterance_copy' in dictionary:
      self.utterance_copy = Wordpiece().from_json(dictionary['utterance_copy'])
      return self
コード例 #5
0
ファイル: schema_utils.py プロジェクト: yyht/language
    def from_json(self, dictionary):
        """Sets the properties of the column from a dictionary representation."""
        self.original_column_name = dictionary['original_column_name']
        self.column_name_wordpieces = [
            Wordpiece().from_json(wordpiece)
            for wordpiece in dictionary['column_name_wordpieces']
        ]
        self.column_type = dictionary['column_type']
        self.table_name = dictionary['table_name']
        self.is_foreign_key = dictionary['is_foreign_key']
        self.matches_to_utterance = dictionary['matches_to_utterance']
        assert self.column_type in ACCEPTABLE_COL_TYPES, (
            ('Column type not '
             'recognized: %r; name: %r') %
            (self.column_type, self.original_column_name))

        return self
コード例 #6
0
ファイル: sql_utils.py プロジェクト: samuelstevens/language
    def from_json(self, dictionary) -> "SQLAction":
        """Converts from a JSON representation to a SQL action."""
        # Should only have one key -- any of the above keys.
        assert len(dictionary) == 1
        if "symbol" in dictionary:
            self.symbol = dictionary["symbol"]
            return self

        if "entity_copy" in dictionary:
            self.entity_copy = SchemaEntityCopy().from_json(dictionary["entity_copy"])
            return self

        if "utterance_copy" in dictionary:
            self.utterance_copy = Wordpiece.from_json(dictionary["utterance_copy"])
            return self

        raise ValueError(
            f"Dictionary with keys {dictionary.keys()} does not contain a good key!"
        )
コード例 #7
0
    def from_json(dictionary) -> "DatabaseTable":
        """Converts from a JSON dictionary to a DatabaseTable object."""
        original_table_name = dictionary["original_table_name"]
        table_name_wordpieces = [
            Wordpiece.from_json(wordpiece)
            for wordpiece in dictionary["table_name_wordpieces"]
        ]
        table_columns = [
            TableColumn.from_json(column)
            for column in dictionary["table_columns"]
        ]
        matches_to_utterance = dictionary["matches_to_utterance"]

        return DatabaseTable(
            original_table_name,
            table_name_wordpieces,
            table_columns,
            matches_to_utterance,
        )
コード例 #8
0
    def from_json(dictionary) -> "TableColumn":
        """Sets the properties of the column from a dictionary representation."""
        original_column_name = dictionary["original_column_name"]
        column_name_wordpieces = [
            Wordpiece.from_json(wordpiece)
            for wordpiece in dictionary["column_name_wordpieces"]
        ]
        column_type = dictionary["column_type"]
        table_name = dictionary["table_name"]
        is_foreign_key = dictionary["is_foreign_key"]
        matches_to_utterance = dictionary["matches_to_utterance"]
        assert column_type in ACCEPTABLE_COL_TYPES, (
            "Column type not "
            "recognized: %r; name: %r") % (column_type, original_column_name)

        return TableColumn(
            column_type,
            original_column_name,
            column_name_wordpieces,
            table_name,
            is_foreign_key,
            matches_to_utterance,
        )