Browse Source

be 引入NLP模型

master
Chunxian Zhang 2 years ago
parent
commit
da5d91d3ff
9 changed files with 7999 additions and 5821 deletions
  1. +0
    -8
      Lesson1/.idea/Lesson1.iml
  2. +7
    -6
      lazy-timer-be/app.py
  3. BIN
      lazy-timer-be/model.pkl
  4. +105
    -0
      lazy-timer-be/mymodel.py
  5. +2750
    -0
      lazy-timer-be/stop.txt
  6. +129
    -0
      lazy-timer-be/tmp.csv
  7. +5
    -5
      lazy-timer-fe/src/components/ThemeSettings.jsx
  8. +5003
    -5801
      lazy-timer-fe/src/data/dummy.js
  9. +0
    -1
      lazy-timer-fe/src/pages/Customers.jsx

+ 0
- 8
Lesson1/.idea/Lesson1.iml View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

+ 7
- 6
lazy-timer-be/app.py View File

@ -79,9 +79,10 @@ def getDayScreenUseTime():
sendJson = {'getDayScreenUseTimeH': getDayScreenUseTimeH, 'getDayScreenUseTimeM': getDayScreenUseTimeM, 'getDayScreenUseTimeS': getDayScreenUseTimeS, 'firstScreenTime': firstScreenTime, 'lastScreenTime': lastScreenTime, 'getScreenTimeSpanH': getScreenTimeSpanH, 'getScreenTimeSpanM': getScreenTimeSpanM, 'getScreenTimeSpanS': getScreenTimeSpanS } sendJson = {'getDayScreenUseTimeH': getDayScreenUseTimeH, 'getDayScreenUseTimeM': getDayScreenUseTimeM, 'getDayScreenUseTimeS': getDayScreenUseTimeS, 'firstScreenTime': firstScreenTime, 'lastScreenTime': lastScreenTime, 'getScreenTimeSpanH': getScreenTimeSpanH, 'getScreenTimeSpanM': getScreenTimeSpanM, 'getScreenTimeSpanS': getScreenTimeSpanS }
return json.dumps(sendJson, indent=4) return json.dumps(sendJson, indent=4)
# @app.route('/getDayScreenUseTime', methods=['POST'])
# @cross_origin()
# def getDayScreenUseTime():
# datetimeStr1 = json.loads(request.data)
# datetimeStr = datetimeStr1['datetimeStr']
# struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime
@app.route('/getDayScreenUseTime', methods=['POST'])
@cross_origin()
def getDayScreenUseTime():
datetimeStr1 = json.loads(request.data)
datetimeStr = datetimeStr1['datetimeStr']
struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime
return "1"

BIN
lazy-timer-be/model.pkl View File


+ 105
- 0
lazy-timer-be/mymodel.py View File

@ -0,0 +1,105 @@
# import re
# import torch
# import torch.nn as nn
# import jieba
# import pandas as pd
# # from torchtext import data
#
# class LSTMNet(nn.Module):
# def __init__(self,vocab_size,embedding_dim,hidden_dim,layer_dim,output_dim):
# super(LSTMNet,self).__init__()
# self.hidden_dim= hidden_dim
# self.layer_dim = layer_dim
# self.embedding = nn.Embedding(vocab_size,embedding_dim)
# # LSTM+全连接
# self.lstm = nn.LSTM(embedding_dim,hidden_dim,layer_dim,
# batch_first=True)
# self.fcl= nn.Linear(hidden_dim,output_dim)
# def forward(self,x):
# embeds = self.embedding(x)
# r_out,(h_n,h_c)=self.lstm(embeds,None)
# out = self.fcl(r_out[:,-1,:])
# return out
#
# def Chinese_pre(text_data,stopwords):
# # 字母转化为小写, 去掉数字
# text_data = text_data.lower()
# text_data = re.sub("\d+","",text_data)
# # 分词,使用精确模式
# text_data = list(jieba.cut(text_data,cut_all = False))
# # 去除停用词和多余空格
# text_data = [word.strip() for word in text_data if word not in stopwords]
# # 处理后的词语使用空格连接为字符串
# text_data = " ".join(text_data)
# return text_data
#
# def TexttoLable(textdata):
# # 将输入文本转为tensor
# # 首先对文本进行分词
# from nltk.corpus import stopwords
# import nltk
# nltk.download('stopwords')
# words = stopwords.words('english')
# stopwords = set()
# with open("stop.txt",encoding="utf-8") as infile:
# for line in infile:
# line = line.rstrip('\n')
# if line:
# stopwords.add(line.lower())
# for i in words:
# stopwords.add(i)
# textdata=Chinese_pre(textdata,stopwords)
#
# data1=[]
# for i in range(128):
# data1.append(textdata)
# df = pd.DataFrame({'cutword':data1})
#
# df.to_csv("tmp.csv")
#
# mytokenize = lambda x:x.split()
# from torchtext.legacy import data
# TEXT = data.Field(sequential = True,tokenize = mytokenize,
# include_lengths=True,use_vocab=True,
# batch_first=True,fix_length=40)
#
# LABEL = data.Field(sequential =False,use_vocab=False,
# pad_token=None,unk_token=None)
# # 对所有读取的数据集的列进行处理
# text_data_fields = [
# ("labelcode",LABEL),
# ("cutword",TEXT)
# ]
# # 读取数据
# # 读取数据
# traindata,valdata,testdata = data.TabularDataset.splits(
# path="./",format="csv",train="tmp.csv",fields = text_data_fields,
# validation = "tmp.csv",
# test ="tmp.csv",skip_header=True
# )
#
# em = testdata.examples[0]
# TEXT.build_vocab(traindata,max_size=100,vectors=None)
#
# # 定义一个迭代器,将类似长度的示例一起批处理
# BATCH_SIZE=128
# test_iter = data.BucketIterator(testdata,batch_size=128)
#
#
# vocab_size=len(TEXT.vocab)
# embedding_dim=50
# hidden_dim=256
# layer_dim=1
# output_dim=4
# lstmmodel = LSTMNet(vocab_size, embedding_dim, hidden_dim, layer_dim, output_dim)
#
# res=0
# model = torch.load("model.pkl")
# for step,batch in enumerate(test_iter):
# textfinal = batch.cutword[0]
# out = model(textfinal)
# pre_lab = torch.argmax(out,1)
# res = pre_lab[0]
# print(res.numpy())
#
# TexttoLable("萝卜云服交流群等3个会话 ")

+ 2750
- 0
lazy-timer-be/stop.txt
File diff suppressed because it is too large
View File


+ 129
- 0
lazy-timer-be/tmp.csv View File

@ -0,0 +1,129 @@
,cutword
0,萝卜 云服 交流 群等个 话
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,萝卜 云服 交流 群等个 话
43,萝卜 云服 交流 群等个 话
44,萝卜 云服 交流 群等个 话
45,萝卜 云服 交流 群等个 话
46,萝卜 云服 交流 群等个 话
47,萝卜 云服 交流 群等个 话
48,萝卜 云服 交流 群等个 话
49,萝卜 云服 交流 群等个 话
50,萝卜 云服 交流 群等个 话
51,萝卜 云服 交流 群等个 话
52,萝卜 云服 交流 群等个 话
53,萝卜 云服 交流 群等个 话
54,萝卜 云服 交流 群等个 话
55,萝卜 云服 交流 群等个 话
56,萝卜 云服 交流 群等个 话
57,萝卜 云服 交流 群等个 话
58,萝卜 云服 交流 群等个 话
59,萝卜 云服 交流 群等个 话
60,萝卜 云服 交流 群等个 话
61,萝卜 云服 交流 群等个 话
62,萝卜 云服 交流 群等个 话
63,萝卜 云服 交流 群等个 话
64,萝卜 云服 交流 群等个 话
65,萝卜 云服 交流 群等个 话
66,萝卜 云服 交流 群等个 话
67,萝卜 云服 交流 群等个 话
68,萝卜 云服 交流 群等个 话
69,萝卜 云服 交流 群等个 话
70,萝卜 云服 交流 群等个 话
71,萝卜 云服 交流 群等个 话
72,萝卜 云服 交流 群等个 话
73,萝卜 云服 交流 群等个 话
74,萝卜 云服 交流 群等个 话
75,萝卜 云服 交流 群等个 话
76,萝卜 云服 交流 群等个 话
77,萝卜 云服 交流 群等个 话
78,萝卜 云服 交流 群等个 话
79,萝卜 云服 交流 群等个 话
80,萝卜 云服 交流 群等个 话
81,萝卜 云服 交流 群等个 话
82,萝卜 云服 交流 群等个 话
83,萝卜 云服 交流 群等个 话
84,萝卜 云服 交流 群等个 话
85,萝卜 云服 交流 群等个 话
86,萝卜 云服 交流 群等个 话
87,萝卜 云服 交流 群等个 话
88,萝卜 云服 交流 群等个 话
89,萝卜 云服 交流 群等个 话
90,萝卜 云服 交流 群等个 话
91,萝卜 云服 交流 群等个 话
92,萝卜 云服 交流 群等个 话
93,萝卜 云服 交流 群等个 话
94,萝卜 云服 交流 群等个 话
95,萝卜 云服 交流 群等个 话
96,萝卜 云服 交流 群等个 话
97,萝卜 云服 交流 群等个 话
98,萝卜 云服 交流 群等个 话
99,萝卜 云服 交流 群等个 话
100,萝卜 云服 交流 群等个 话
101,萝卜 云服 交流 群等个 话
102,萝卜 云服 交流 群等个 话
103,萝卜 云服 交流 群等个 话
104,萝卜 云服 交流 群等个 话
105,萝卜 云服 交流 群等个 话
106,萝卜 云服 交流 群等个 话
107,萝卜 云服 交流 群等个 话
108,萝卜 云服 交流 群等个 话
109,萝卜 云服 交流 群等个 话
110,萝卜 云服 交流 群等个 话
111,萝卜 云服 交流 群等个 话
112,萝卜 云服 交流 群等个 话
113,萝卜 云服 交流 群等个 话
114,萝卜 云服 交流 群等个 话
115,萝卜 云服 交流 群等个 话
116,萝卜 云服 交流 群等个 话
117,萝卜 云服 交流 群等个 话
118,萝卜 云服 交流 群等个 话
119,萝卜 云服 交流 群等个 话
120,萝卜 云服 交流 群等个 话
121,萝卜 云服 交流 群等个 话
122,萝卜 云服 交流 群等个 话
123,萝卜 云服 交流 群等个 话
124,萝卜 云服 交流 群等个 话
125,萝卜 云服 交流 群等个 话
126,萝卜 云服 交流 群等个 话
127,萝卜 云服 交流 群等个 话

+ 5
- 5
lazy-timer-fe/src/components/ThemeSettings.jsx View File

@ -13,7 +13,7 @@ const ThemeSettings = () => {
<div className="bg-half-transparent w-screen fixed nav-item top-0 right-0"> <div className="bg-half-transparent w-screen fixed nav-item top-0 right-0">
<div className="float-right h-screen dark:text-gray-200 bg-white dark:bg-[#484B52] w-400"> <div className="float-right h-screen dark:text-gray-200 bg-white dark:bg-[#484B52] w-400">
<div className="flex justify-between items-center p-4 ml-4"> <div className="flex justify-between items-center p-4 ml-4">
<p className="font-semibold text-lg">Settings</p>
<p className="font-semibold text-lg">设置</p>
<button <button
type="button" type="button"
onClick={() => setThemeSettings(false)} onClick={() => setThemeSettings(false)}
@ -25,7 +25,7 @@ const ThemeSettings = () => {
</div> </div>
<div className="flex-col border-t-1 border-color p-4 ml-4"> <div className="flex-col border-t-1 border-color p-4 ml-4">
<p className="font-semibold text-xl ">Theme Option</p>
<p className="font-semibold text-xl ">色彩选择</p>
<div className="mt-4"> <div className="mt-4">
<input <input
@ -39,7 +39,7 @@ const ThemeSettings = () => {
/> />
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */} {/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label htmlFor="light" className="ml-2 text-md cursor-pointer"> <label htmlFor="light" className="ml-2 text-md cursor-pointer">
Light
白色
</label> </label>
</div> </div>
<div className="mt-2"> <div className="mt-2">
@ -54,12 +54,12 @@ const ThemeSettings = () => {
/> />
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */} {/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label htmlFor="dark" className="ml-2 text-md cursor-pointer"> <label htmlFor="dark" className="ml-2 text-md cursor-pointer">
Dark
暗色
</label> </label>
</div> </div>
</div> </div>
<div className="p-4 border-t-1 border-color ml-4"> <div className="p-4 border-t-1 border-color ml-4">
<p className="font-semibold text-xl ">Theme Colors</p>
<p className="font-semibold text-xl ">主题颜色</p>
<div className="flex gap-3"> <div className="flex gap-3">
{themeColors.map((item, index) => ( {themeColors.map((item, index) => (
<TooltipComponent key={index} content={item.name} position="TopCenter"> <TooltipComponent key={index} content={item.name} position="TopCenter">

+ 5003
- 5801
lazy-timer-fe/src/data/dummy.js
File diff suppressed because it is too large
View File


+ 0
- 1
lazy-timer-fe/src/pages/Customers.jsx View File

@ -23,7 +23,6 @@ const Customers = () => {
allowSorting allowSorting
> >
<ColumnsDirective> <ColumnsDirective>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
{customersGrid.map((item, index) => <ColumnDirective key={index} {...item} />)} {customersGrid.map((item, index) => <ColumnDirective key={index} {...item} />)}
</ColumnsDirective> </ColumnsDirective>
<Inject services={[Page, Selection, Toolbar, Edit, Sort, Filter]} /> <Inject services={[Page, Selection, Toolbar, Edit, Sort, Filter]} />

Loading…
Cancel
Save