matt-tries-dl commited on
Commit
9084b03
1 Parent(s): 01e2d8f

turn query structure into sql text

Browse files
Files changed (1) hide show
  1. llama_test.ipynb +26 -7
llama_test.ipynb CHANGED
@@ -160,7 +160,7 @@
160
  },
161
  {
162
  "cell_type": "code",
163
- "execution_count": 15,
164
  "metadata": {},
165
  "outputs": [
166
  {
@@ -172,27 +172,46 @@
172
  "1-1000181-1\n",
173
  "['State/territory', 'Text/background colour', 'Format', 'Current slogan', 'Current series', 'Notes']\n",
174
  "\n",
175
- "{'id': '1-1000181-1', 'header': ['State/territory', 'Text/background colour', 'Format', 'Current slogan', 'Current series', 'Notes'], 'types': ['text', 'text', 'text', 'text', 'text', 'text'], 'rows': [['Australian Capital Territory', 'blue/white', 'Yaa·nna', 'ACT · CELEBRATION OF A CENTURY 2013', 'YIL·00A', 'Slogan screenprinted on plate'], ['New South Wales', 'black/yellow', 'aa·nn·aa', 'NEW SOUTH WALES', 'BX·99·HI', 'No slogan on current series'], ['New South Wales', 'black/white', 'aaa·nna', 'NSW', 'CPX·12A', 'Optional white slimline series'], ['Northern Territory', 'ochre/white', 'Ca·nn·aa', 'NT · OUTBACK AUSTRALIA', 'CB·06·ZZ', 'New series began in June 2011'], ['Queensland', 'maroon/white', 'nnn·aaa', 'QUEENSLAND · SUNSHINE STATE', '999·TLG', 'Slogan embossed on plate'], ['South Australia', 'black/white', 'Snnn·aaa', 'SOUTH AUSTRALIA', 'S000·AZD', 'No slogan on current series'], ['Victoria', 'blue/white', 'aaa·nnn', 'VICTORIA - THE PLACE TO BE', 'ZZZ·562', 'Current series will be exhausted this year']], 'name': 'table_1000181_1'}\n"
 
 
176
  ]
177
  }
178
  ],
179
  "source": [
180
  "import json\n",
 
 
 
 
 
 
 
 
 
 
181
  "with open('data/train.jsonl') as f:\n",
182
  " j = f.readline()\n",
183
  " js = json.loads(j)\n",
184
  " print(js)\n",
185
- "\n",
186
  "print()\n",
187
  "\n",
188
  "with open('data/train.tables.jsonl') as f:\n",
189
  " j = f.readline()\n",
190
- " js = json.loads(j)\n",
191
  " #print(js)\n",
192
- " print(js['id'])\n",
193
- " print(js['header'])\n",
194
  " print()\n",
195
- " print(js)"
 
 
 
 
 
 
 
196
  ]
197
  }
198
  ],
 
160
  },
161
  {
162
  "cell_type": "code",
163
+ "execution_count": 12,
164
  "metadata": {},
165
  "outputs": [
166
  {
 
172
  "1-1000181-1\n",
173
  "['State/territory', 'Text/background colour', 'Format', 'Current slogan', 'Current series', 'Notes']\n",
174
  "\n",
175
+ "{'id': '1-1000181-1', 'header': ['State/territory', 'Text/background colour', 'Format', 'Current slogan', 'Current series', 'Notes'], 'types': ['text', 'text', 'text', 'text', 'text', 'text'], 'rows': [['Australian Capital Territory', 'blue/white', 'Yaa·nna', 'ACT · CELEBRATION OF A CENTURY 2013', 'YIL·00A', 'Slogan screenprinted on plate'], ['New South Wales', 'black/yellow', 'aa·nn·aa', 'NEW SOUTH WALES', 'BX·99·HI', 'No slogan on current series'], ['New South Wales', 'black/white', 'aaa·nna', 'NSW', 'CPX·12A', 'Optional white slimline series'], ['Northern Territory', 'ochre/white', 'Ca·nn·aa', 'NT · OUTBACK AUSTRALIA', 'CB·06·ZZ', 'New series began in June 2011'], ['Queensland', 'maroon/white', 'nnn·aaa', 'QUEENSLAND · SUNSHINE STATE', '999·TLG', 'Slogan embossed on plate'], ['South Australia', 'black/white', 'Snnn·aaa', 'SOUTH AUSTRALIA', 'S000·AZD', 'No slogan on current series'], ['Victoria', 'blue/white', 'aaa·nnn', 'VICTORIA - THE PLACE TO BE', 'ZZZ·562', 'Current series will be exhausted this year']], 'name': 'table_1000181_1'}\n",
176
+ "SELECT col5 FROM table WHERE col3 = SOUTH AUSTRALIA\n",
177
+ "SELECT Notes FROM table WHERE Current slogan = SOUTH AUSTRALIA\n"
178
  ]
179
  }
180
  ],
181
  "source": [
182
  "import json\n",
183
+ "import sys\n",
184
+ "import re\n",
185
+ "sys.path.append('./WikiSQL')\n",
186
+ "from WikiSQL.lib.query import Query\n",
187
+ "\n",
188
+ "def replace_cols(qs,cmap):\n",
189
+ " for k,v in cmap.items():\n",
190
+ " qs = re.sub(f' {k} ',f' {v} ',qs)\n",
191
+ " return qs\n",
192
+ "\n",
193
  "with open('data/train.jsonl') as f:\n",
194
  " j = f.readline()\n",
195
  " js = json.loads(j)\n",
196
  " print(js)\n",
197
+ " \n",
198
  "print()\n",
199
  "\n",
200
  "with open('data/train.tables.jsonl') as f:\n",
201
  " j = f.readline()\n",
202
+ " js2 = json.loads(j)\n",
203
  " #print(js)\n",
204
+ " print(js2['id'])\n",
205
+ " print(js2['header'])\n",
206
  " print()\n",
207
+ " print(js2)\n",
208
+ "\n",
209
+ "sql = js['sql']\n",
210
+ "q = Query.from_dict(sql)\n",
211
+ "print(q)\n",
212
+ "cm = {f'col{i}':js2['header'][i] for i in range(len(js2['header']))}\n",
213
+ "qs = replace_cols(str(q),cm)\n",
214
+ "print(qs)"
215
  ]
216
  }
217
  ],