Describes a single generation action for a SQL query.
| 103 | |
| 104 | |
| 105 | class SQLAction(object): |
| 106 | """Describes a single generation action for a SQL query.""" |
| 107 | |
| 108 | def __init__(self, symbol=None, entity_copy=None, utterance_copy=None): |
| 109 | # Make sure only one of the things are set. |
| 110 | assert len([obj for obj in [symbol, entity_copy, utterance_copy] if obj |
| 111 | ]) <= 1 |
| 112 | |
| 113 | self.symbol = symbol |
| 114 | self.entity_copy = entity_copy |
| 115 | self.utterance_copy = utterance_copy |
| 116 | |
| 117 | def to_json(self): |
| 118 | if self.symbol: |
| 119 | return {'symbol': self.symbol} |
| 120 | if self.entity_copy: |
| 121 | return {'entity_copy': self.entity_copy.to_json()} |
| 122 | if self.utterance_copy: |
| 123 | return {'utterance_copy': self.utterance_copy.to_json()} |
| 124 | |
| 125 | def from_json(self, dictionary): |
| 126 | """Converts from a JSON representation to a SQL action.""" |
| 127 | # Should only have one key -- any of the above keys. |
| 128 | assert len(dictionary) == 1 |
| 129 | if 'symbol' in dictionary: |
| 130 | self.symbol = dictionary['symbol'] |
| 131 | return self |
| 132 | |
| 133 | if 'entity_copy' in dictionary: |
| 134 | self.entity_copy = SchemaEntityCopy().from_json(dictionary['entity_copy']) |
| 135 | return self |
| 136 | |
| 137 | if 'utterance_copy' in dictionary: |
| 138 | self.utterance_copy = Wordpiece().from_json(dictionary['utterance_copy']) |
| 139 | return self |
| 140 | |
| 141 | |
| 142 | class SQLQuery(object): |
no outgoing calls
no test coverage detected
searching dependent graphs…