-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
42 lines (31 loc) · 1.05 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pandas as pd
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from clickhouse_driver import Client
def is_valid_txt(txt: str) -> bool:
"""get text return where True good text"""
if type(txt) != str:
return False
if len(txt.split()) == 0 or pd.isnull(txt):
return False
return True
def get_data_token(corpus, input_len, max_features=95000):
tokenizer = Tokenizer(num_words=max_features)
tokenizer.fit_on_texts(corpus)
train = tokenizer.texts_to_sequences(corpus)
train = pad_sequences(train, maxlen=input_len)
return train, tokenizer
def click_patch(self, req):
cols = [x[0] for x in self.execute(f'describe ({req})')]
return pd.DataFrame(self.execute(req), columns=cols)
class Struct:
"""Convert dict to object
c_ = {
"DATA_FOLDER": 'data',
"fil_1": 'df.csv',
}
c_ = Struct(**c_)
"""
def __init__(self, **entries):
self.__dict__.update(entries)
Client.get_df = click_patch