-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
100 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
��������=�������ʒ���月�� �����Ϗ�(���������2 | ||
ℨ���־���鿶������月�� �����Ϗ�(�������2 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# sql_tokenizer.py | ||
import re | ||
import json | ||
from tensorflow.keras.preprocessing.sequence import pad_sequences | ||
|
||
|
||
class SQLTokenizer: | ||
def __init__(self, max_words=10000, max_len=100): | ||
self.max_words = max_words | ||
self.max_len = max_len | ||
self.token_index = {} | ||
|
||
def tokenize(self, query): | ||
# Define a regex pattern for SQL tokens (operators, punctuation, keywords) | ||
pattern = r"[\w']+|[=><!]+|--|/\*|\*/|;|\(|\)|,|\*|\||\s+" | ||
tokens = re.findall(pattern, query.lower()) | ||
return tokens | ||
|
||
def fit_on_texts(self, queries): | ||
# Build a token index based on the provided queries | ||
all_tokens = set() | ||
for query in queries: | ||
tokens = self.tokenize(query) | ||
all_tokens.update(tokens) | ||
# Limit to max_words | ||
all_tokens = list(all_tokens)[: self.max_words] | ||
self.token_index = {token: i + 1 for i, token in enumerate(all_tokens)} | ||
|
||
def texts_to_sequences(self, queries): | ||
# Convert queries to sequences of token IDs | ||
sequences = [] | ||
for query in queries: | ||
tokens = self.tokenize(query) | ||
sequence = [self.token_index.get(token, 0) for token in tokens] | ||
sequences.append(sequence) | ||
return pad_sequences(sequences, maxlen=self.max_len) | ||
|
||
def save_token_index(self, filepath): | ||
with open(filepath, "w") as f: | ||
json.dump(self.token_index, f) | ||
|
||
def load_token_index(self, filepath): | ||
with open(filepath, "r") as f: | ||
self.token_index = json.load(f) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.