' j2 ~3 R z, n3 L) t9 F6 @2 L/ c/ Y1 C' v z H% ]
@app.get(1 u4 Q4 y h: g8 {: n
"/bilibilivideos/{vid}/", ' O. O9 n8 i+ Z z' K1 F9 K response_model=schemas.BilibiliVideo, & ^) N- v4 X* Y/ h: }* k# l% F5 T1 A tags=['bilibili视频评论语料库数据接口'] . D; ~) U- w7 i)/ W# o- p3 Q& X6 U4 I" N2 A2 {
def get_bilibili_videos_by_vid(vid: int, db: Session = Depends(get_db)): ' q3 L7 x" Y2 R o4 w db_video = crud.get_bilibili_videos_by_vid(vid, db)) K* J3 n, d3 g" x6 D) T
return db_video 1 I" s9 B: \4 X3 g6 A" l& j' P 1 x$ a. t7 ]3 U7 e5 R+ Q4 r, T" j* w, e
@app.get(, A1 d# ]8 Y" J
"/bilibilivideos/{vid}/comments/", 8 S' o' Z4 y% M5 a. X response_model=List[schemas.BilibiliVideoComment], - t( }- }1 E$ q5 k tags=['bilibili视频评论语料库数据接口'] - w( G8 Y8 Z' s/ P# u; \) 3 d& u. I% J8 v8 tdef get_bilibili_video_comments_by_vid(vid: int, db: Session = Depends(get_db)): ) y$ G' `' M' i: R. i/ y( a db_comments = crud.get_bilibili_video_comments_by_vid(vid, db) + i) g. e1 ^5 R( Z7 b return db_comments 7 A& n ^! u5 t/ u2 K! r 1 ?. G7 a% t6 m' ?! T* E2 h9 C j9 @) B( J: {: X3 t
@app.get(& r8 `7 u7 ~8 w1 W, ]% x
"/onlineShoppingReviews/"," g1 F) n/ A7 N3 C& Q& _
response_model=List[schemas.OnlineShoppingReview],' c( a# x& i, v
tags=['电商购物评价语料库数据接口']# p( R+ v" f; F3 `; e& Q9 O
) $ [0 t1 F3 B8 r3 Kdef get_online_shopping_reviews(db: Session = Depends(get_db)):6 H) [- a% z3 z3 u
db_reviews = crud.get_online_shopping_reviews(db) / O' }2 m" W" B$ U$ R return db_reviews1 L$ s2 S& g) _1 j* f. c/ S7 M
( f+ F' T- `5 ?- i & p& r( f. u- h: `@app.get( V) k3 w. W3 D "/takeawayReviews/", & y; j# w# m7 S7 T) F# l6 f response_model=List[schemas.TakeawayReview],0 I8 i+ ^3 ?8 G7 q* N- Z4 q
tags=['外卖评价语料库数据接口'] 4 X" D& m7 j7 w" d7 r! h)9 U/ r+ N( } N1 W6 R# I' ]
def get_takeaway_reviews(db: Session = Depends(get_db)):; y8 q" r; ]) y4 W0 Q/ k W
db_reviews = crud.get_takeaway_reviews(db): w6 u6 `! K8 w# u" {+ h
return db_reviews 2 K& P4 Z: R: t+ Z! D6 z5 `: f- A$ g* Q* I$ I
- Y1 Z+ J- u0 ~, q0 t
@app.get( * y& s; L0 V+ B. |6 D/ Z3 ` "/chineseLyrics/", " l3 j7 @5 E8 m" L$ ~ response_model=List[schemas.ChineseLyrics],. A* ^1 N* p) ~# b, {# g& f
tags=['中文歌歌词语料库数据接口']1 j& B2 I/ I" ]! p# w) Y5 @# c0 k
)& T1 x2 Z0 L9 b- o( V9 |' \, w U
def get_chinese_lyrics(db: Session = Depends(get_db)):1 @1 ^5 F" f5 M$ y
db_reviews = crud.get_chinese_lyrics(db)" o0 p$ O: G3 I; A+ U2 j" }$ \! i
return db_reviews7 j7 d5 R' d! T: {2 T) O' z
- v& P# w4 `3 j2 ? 3 l( \6 t1 a2 D. S1 n2 {0 _: K: J@app.get( - g: ~9 h0 C% H w! K "/COVID19News/",' X; W7 \& b9 J0 V3 U
response_model=List[schemas.COVID19News], 8 x' H7 u6 M/ l; j tags=['新冠病毒新闻语料库数据接口']' j; ?$ H- |3 w
) % ?. H- k; e. `; U* k# ^def get_COVID19_news(db: Session = Depends(get_db)): 4 v& ~9 i' h/ [1 C db_reviews = crud.get_COVID19_news(db)! m; R! J; G2 l) P. ]
return db_reviews ; x& M& W& \: g* t, [6 h4 X( Y. C o9 |) g% }2 ~6 `# A- G
2 O! j, m0 f4 M, M2 f; Q, n# 为每个用户设置uuid标识符,并存入Cookie* U4 Y6 v T2 t/ b; ^% l5 P
def create_user_uuid_and_set_cookie(response: Response): ' Y7 S* P! S2 G) _* k4 ]5 i. u user_uuid = str(uuid.uuid1()) O4 \; |0 _6 d2 y. H3 w
response.set_cookie(key="user_uuid", value=user_uuid) Q) A: E, @# A. l. b' S
return user_uuid3 I2 q. m5 k( K: G0 `: L+ x
1 r v; }' X* E; |
$ X7 U3 ~7 R3 Q@app.post(8 l1 g! n. ?$ O( k2 O1 U
"/calculate/preprocessing/", ' r: V. f2 T$ i% D ~ tags=["计算模块数据接口"] * S3 f' y1 p' A* ~; {7 v8 s)7 |3 i3 ?$ R4 U, I
async def run_text_preprocessing_task(text_preprocessing_params: TextPreprocessingParams, 2 I8 a) o$ @% G; q0 f background_task: BackgroundTasks, 9 t! @ I6 z- _3 s1 i& o; j# I' K response: Response, $ P$ o p; Y7 k8 S' f) | user_uuid: str = Cookie(None)): 7 c1 U! B, I+ f" F+ l3 Y if not user_uuid: - m9 E3 I" M/ K! I) b* ~1 | user_uuid = create_user_uuid_and_set_cookie(response) 2 O3 J8 B5 e, C' y4 S( u. w& c 8 n6 t$ K7 G* q7 y3 }6 X global topic_model_training_tasks 9 T3 Z9 T- k$ |% D) B6 O task = TopicModelTrainingTask(text_preprocessing_params) ! v3 g# `& Z/ n8 O: t' H topic_model_training_tasks[user_uuid] = task - o7 h7 \% `2 J2 q1 @; ]0 s2 |+ V' X! y! [( Q" m, v
background_task.add_task(task.preprocessing)7 e1 c9 L: j' D( h
return {"message": "已添加文本预处理后台任务"} # H w! ^, {8 N' d- x" k 6 Q/ _! N- f" x7 y* f: d 1 p( c. @$ V$ q& m4 R@app.post(' N A7 E" U- j9 U! x2 J/ ~8 L
"/calculate/nmftraining/",* M( K: K6 Q% q3 T5 b
tags=["计算模块数据接口"], D6 T1 D& L3 r/ {# F
)7 y5 z$ w3 C0 Q6 {1 N# i
async def run_nmf_training_and_tsne_task(nmf_training_params: NMFTrainingParams,$ m$ `* g/ k# M% C; e
background_task: BackgroundTasks,) z8 N& k: f* W' j- T
response: Response, # K& t& {: _5 i) _. H6 u- d user_uuid: str = Cookie(None)):' V' X7 p# {2 a/ X
if not user_uuid:* v* K1 o* P" w S
user_uuid = create_user_uuid_and_set_cookie(response)) L3 m, N* X# O" l. ~
, F. `5 h3 s9 S. N4 s3 y& y/ | global topic_model_training_tasks : {0 A- i* A5 K" N6 Y. [' @8 o5 G* u" u' Q" D
if user_uuid and user_uuid in topic_model_training_tasks:; j1 @+ u2 ^) \) D
task = topic_model_training_tasks[user_uuid]' K- i- J0 B/ H) Z
if task.text_preprocessing_progress.status_code == 2:5 ~* k, ]9 u5 w2 b: D* z+ {
background_task.add_task(task.nmf_training, nmf_training_params). [' M) l! F# U K6 k
return {"message": "已添加NMF主题模型训练后台任务"}3 ~7 O8 ?6 h B' K2 P+ b9 n# p
else:, h9 q9 H, @( u; N4 O
raise HTTPException(status_code=404, detail="请先进行文本预处理任务!") ) s: ]& m3 K* A else: 7 g8 y8 k6 H5 R2 M9 N0 k raise HTTPException(status_code=404, detail="未找到相应的训练对象!") ! @" d; X& d$ T$ M* S5 D0 a. L [4 Y) m% ~! }$ m0 L+ T( w) E1 T; {+ s9 }' P( S) {$ m2 B4 b3 s1 \
@app.get( ; N3 \# }$ A( a6 J+ h$ ` "/calculate/nmftraining/keywordsearch/", * `" P, d/ e' p' I- D, t response_model=KeywordSearchResult, 5 R8 [" o4 h6 J8 o% e% y1 g' ` tags=["用户交互"]0 g( \( D4 w2 w& Q* d7 {
)5 M7 h8 P/ B H0 Y! v) v, b
async def search_keyword(search_text: str,2 v# j, r) Q0 W/ x# y
response: Response, 5 B! ?( G3 o N8 L user_uuid: str = Cookie(None)):. |% p. N6 X7 D/ P( X
if not user_uuid: 9 w/ a7 A8 |. G0 D user_uuid = create_user_uuid_and_set_cookie(response) 3 j( V6 D% O1 I" W 8 M9 [; \; [( s- O& e! u global topic_model_training_tasks1 B) U! G+ g f. m. C/ w" @5 ^; p
' b+ b Z7 G3 N7 [8 ^ if user_uuid and user_uuid in topic_model_training_tasks: 5 x1 J+ ?6 N; L$ e8 R$ j task = topic_model_training_tasks[user_uuid] , K4 T% [: R+ H6 n if task.text_preprocessing_progress.status_code == 2:* X" E* ~5 I1 d8 e" k! v1 M7 p% P
search_text = search_text.lower()7 z2 b9 k3 o R$ V7 r* B
bag_words = task.text_preprocessing.bagWords" A( m* q; W) F4 N
keyword_search_result = KeywordSearchResult()( ~6 Z9 P: M4 L3 z
for wi, word in enumerate(bag_words):4 y) f8 O. C/ n4 ^, I5 m
if search_text in word: ; g# I8 |% E& n w" } keyword_search_result.word_id_list.append(wi)2 G! e _- [6 N+ z! _" i
keyword_search_result.word_list.append(word) $ [! u9 B" B- r& @: { return keyword_search_result ; d/ B% l1 W, X3 C5 B# B else: % _3 | {- U8 T, i8 V( q$ l raise HTTPException(status_code=404, detail="请先进行文本预处理任务!") 2 p- j, @6 a4 X4 C+ H. @/ N( w else:$ |% J/ F9 P8 O4 b1 k/ x3 H
raise HTTPException(status_code=404, detail="未找到相应的训练对象!")+ H( c e. @; K; K7 c; m! `0 B
/ S$ R: I2 _( z( H. t3 I" R# b' Z; E2 v1 |# T
@app.post( }2 e, u( M! c' F! w
"/calculate/nmftraining/topickeywordoptimization/", 7 e2 P; @! t0 H. N tags=["用户交互"] A& ~8 D" }/ @# e9 L/ g
) - x8 m5 Q* z; P+ Easync def run_topic_keyword_optimization_task(tko_params: TopicKeywordOptimizationParams,: A3 }4 i, y; r# M# P' h
background_task: BackgroundTasks,9 ]7 l- u, n& A7 ?8 E6 N
response: Response, 4 u M5 @: m6 D user_uuid: str = Cookie(None)): * ~% T# p) w3 V2 ?5 R( Z2 d4 D if not user_uuid: 0 D0 l" I3 B, X6 l2 k$ L2 a& i g6 e user_uuid = create_user_uuid_and_set_cookie(response)6 f+ R+ ?2 U% f9 A7 Q
) E! i8 b3 j5 j6 n8 D/ w* P$ N global topic_model_training_tasks u/ K; H f% O! H2 Y; k
/ T# Z. c1 G3 s3 {8 L
if user_uuid and user_uuid in topic_model_training_tasks: + D' j- _6 p L8 G* i/ r3 r' t task = topic_model_training_tasks[user_uuid] 4 N% L e: h, W6 C' z; y( G if task.nmf_training_progress.status_code == 2: - T# m& p0 A& u2 J6 d0 r background_task.add_task(task.topic_keyword_optimization, tko_params)4 x `% i/ t' N7 p& t
return {"message": "已添加主题关键词优化后台任务"} * v: \, n; P! I! q3 A! w else:! ~1 M x& ~! d
raise HTTPException(status_code=404, detail="请先等待NMF训练结束!")0 r! @' C5 @, A3 X
else:7 R& u- i$ V* L! o6 g& C* B0 {
raise HTTPException(status_code=404, detail="未找到相应的训练对象!"), a5 A) C: G8 Z2 k$ q/ H; X
/ k% H3 p5 C. _5 R. S' ]* ? % }" b- {7 D) U& P: D1 N@app.post( 0 i9 a0 H$ m5 d, L "/calculate/nmftraining/topicsplit/", 6 D- f0 I# s/ c& P# O* j tags=["用户交互"] 3 j( X7 ?% s* {$ D)- m3 b: K% G5 |1 v) o
async def run_topic_split_task(ts_params: TopicSplitParams, # e( K9 I! P3 i! F, S background_task: BackgroundTasks, - b2 v9 F2 s( j! u q* c response: Response, - _' p% l. M6 p, T5 }" I user_uuid: str = Cookie(None)): 5 T) s* X; v& F2 `) \5 G8 g if not user_uuid: % s4 j' C; s+ u: t& a user_uuid = create_user_uuid_and_set_cookie(response)' V B+ q& R _
& l0 e- c$ V6 V! V
global topic_model_training_tasks! C/ H( x4 ^/ E2 I" u# F
% E6 d/ Q ^' q% h5 p* T5 d1 E
if user_uuid and user_uuid in topic_model_training_tasks: & q/ C6 w4 \4 w+ t3 C4 U task = topic_model_training_tasks[user_uuid] ) ?9 h& C: L2 y: ?0 f if task.nmf_training_progress.status_code == 2: $ G2 ]+ }7 K' O+ o5 ?3 a: B background_task.add_task(task.topic_split, ts_params)8 r/ ?8 A5 z+ a- G! e! |8 q2 R; C
return {"message": "已添加主题拆分后台任务"}7 \; c( v7 H c% M3 g0 _
else: ) @9 F) _4 q, I! c raise HTTPException(status_code=404, detail="请先等待NMF训练结束!"). [7 |/ B0 _2 b4 o. B: C1 y
else:: ]5 U3 X9 M9 e [' J
raise HTTPException(status_code=404, detail="未找到相应的训练对象!") 3 p# H/ q6 r$ L. Y7 W, S" H9 a4 }5 {( H' c
r9 Q. c% i) R! ]8 n6 I
@app.post( 2 n3 j8 v F) {- k6 }7 U* g "/calculate/nmftraining/topicmerge/", ~9 i m& {, I9 Z6 x3 a( ~ tags=["用户交互"] ! A' J7 }. f& d9 ?- g4 q6 ^)6 b2 c9 u6 L! [$ V; m
async def run_topic_merge_task(tm_params: TopicMergeParams,. G" R8 y$ p- Z
background_task: BackgroundTasks,# H/ Z, t- {$ x5 j1 ]
response: Response, o4 F# m$ K+ g7 o" \ user_uuid: str = Cookie(None)):3 N4 ?! B0 V3 o/ E* J
if not user_uuid:$ M9 B& U$ w! G
user_uuid = create_user_uuid_and_set_cookie(response) ?- r' \5 ~4 w9 H/ A W
$ N+ U$ R g% z& q- e; n6 ?% p/ s; \ global topic_model_training_tasks $ y" D" w: @6 i* n7 r3 p9 Q% H; D. o+ p! \ d& V
if user_uuid and user_uuid in topic_model_training_tasks:2 h# N# V+ H+ W6 ]" ^, X
task = topic_model_training_tasks[user_uuid] # x: x4 ~0 J! a if task.nmf_training_progress.status_code == 2: ' I" j* H- b% ~" q1 e3 n background_task.add_task(task.topic_merge, tm_params) ( J* w, Z1 L, G( O4 R, B return {"message": "已添加主题合并后台任务"} + V* u' f+ L# F: h; V0 h1 L else:9 O8 Y7 I# P* x% X
raise HTTPException(status_code=404, detail="请先等待NMF训练结束!") 7 ^; P( U( g1 L; z/ h! }# d else:$ z- {3 r* _* h" C; |
raise HTTPException(status_code=404, detail="未找到相应的训练对象!")) C1 A& | w0 b3 N- f# ~8 q' l
+ o* G- X9 H' C. i8 H: Q2 E
4 @* v# d" a0 F! g
@app.post( ; C( W' y4 K( r6 ] "/calculate/nmftraining/keywordinducedtopiccreate/", & T$ P2 ^" ?4 l! }2 \& E% { tags=["用户交互"]7 A& p: D/ o+ o k) b# F
)$ l+ U% v4 ?+ f& A0 o
async def run_keyword_induced_topic_create_task(kitc_params: KeywordInducedTopicCreateParams,. p9 L# J$ Q* M# u. ~6 \% x6 E
background_task: BackgroundTasks,! O j2 F! [0 d& V) i
response: Response,3 Z f' z5 |" w7 U1 B
user_uuid: str = Cookie(None)): - e4 a+ e& v( E1 F+ k: Z6 u if not user_uuid:2 H" @ g$ X- k* r/ s+ c$ c* u$ N. f, J
user_uuid = create_user_uuid_and_set_cookie(response) j% W7 u9 j E' L5 f2 t
, a6 k: b8 d0 O! E
global topic_model_training_tasks" N' z+ f8 n3 ?. q: B' S) V6 b
) w$ Q: P) C& ?3 C$ ?; F7 k if user_uuid and user_uuid in topic_model_training_tasks: : w$ @: ]5 @0 g+ | task = topic_model_training_tasks[user_uuid]3 C1 x2 X' Y% y _( m
if task.nmf_training_progress.status_code == 2: 2 N. [8 h& {8 t* n" m background_task.add_task(task.keyword_induced_topic_create, kitc_params)6 N8 [4 e& d% I2 G
return {"message": "已添加关键词诱导主题创建后台任务"} 7 j2 b) ]0 s- U/ L else:! R1 P, p6 y5 x
raise HTTPException(status_code=404, detail="请先等待NMF训练结束!") 5 P0 v3 |& e6 h- B else: 0 \4 Y0 d/ x+ L' o raise HTTPException(status_code=404, detail="未找到相应的训练对象!") : d9 X2 Q+ J q E& R+ D. g6 S$ G8 V$ R; J0 d% H
9 }6 T* H6 p& A3 P@app.post( , |& \3 ~3 N% `4 I2 A "/calculate/nmftraining/documentinducedtopiccreate/", 3 ?; m9 r: x0 a8 L3 d1 ?5 g tags=["用户交互"]* R7 Q( ]9 }: Y E6 |
) ; L4 G) a2 j4 B( F4 x5 aasync def run_document_induced_topic_create_task(ditc_params: DocumentInducedTopicCreateParams, - ]$ R( R6 v0 O4 f5 {3 m& p" k; f background_task: BackgroundTasks, ( k4 {( c' n9 @& H' A5 Q' b response: Response," _# U3 r4 `2 R* Y# S( u3 p
user_uuid: str = Cookie(None)):! Q W0 K) [/ J3 Q
if not user_uuid: 8 v: v K; |+ U# } user_uuid = create_user_uuid_and_set_cookie(response) # N; x* `) U4 x" O2 i) c$ P9 S! c/ ~5 h& j* [2 v9 \; m4 _
global topic_model_training_tasks0 D2 k) S" k/ ^2 _' U' D7 O- Y
- X2 E R8 e3 K
if user_uuid and user_uuid in topic_model_training_tasks:$ E' g9 g4 H& v+ |
task = topic_model_training_tasks[user_uuid]" ^4 K b2 w3 f0 m _! V8 i+ Y
if task.nmf_training_progress.status_code == 2:; ~/ \- P! t4 @- i- L9 R0 k+ W
background_task.add_task(task.document_induced_topic_create, ditc_params) ! T, s3 _( z) \. |6 t return {"message": "已添加文档诱导主题创建后台任务"}6 e; U) h/ v z& B5 |
else: 6 u0 p& U ^* ?% `) ~2 X0 X4 Q raise HTTPException(status_code=404, detail="请先等待NMF训练结束!")) o Q M* F+ {; g
else: ! F. e7 e. v3 l5 a1 Q8 C L4 \ raise HTTPException(status_code=404, detail="未找到相应的训练对象!") 9 R* @% A. Y- R6 O- k% o c5 y9 x4 I y) _
0 L* ~4 x8 a" o! x9 _( s: G: Y
@app.get(' p& X* b/ ]$ G
"/calculate/nmftraining/newdoctopicdistributionpredict/",; C) h. _4 A Z! D) Q4 V6 y
tags=["主题预测"] ! O7 h& F U! _)0 j6 m$ b) K; z7 @: @4 H5 V
async def run_new_document_topic_distribution_predict_task(9 Y& p+ ^3 p( v7 N9 x/ [# E
new_doc_text: str, 2 k- L) B1 Z1 R4 z9 l3 ^$ O& E background_task: BackgroundTasks, ) D/ t6 [; C9 ^7 u: R response: Response,9 O0 \; f ] f& N/ q; k' L
user_uuid: str = Cookie(None)): 8 r$ K+ d0 w' T+ G/ s: U if not user_uuid: / Z2 O/ e+ M0 L5 h, U) T" j user_uuid = create_user_uuid_and_set_cookie(response)" S8 v! r* k( S! w' ~; Y
' i* c Y& S9 A' a1 m global topic_model_training_tasks + m/ O- H8 y$ Q u' Q / d7 I; p* ~+ D' @# q7 u4 W if user_uuid and user_uuid in topic_model_training_tasks:0 g4 N6 e" [6 k2 u! I- ]6 c- ]+ C
task = topic_model_training_tasks[user_uuid] 2 P' H/ `. T5 J' |9 G' O! T) p if task.nmf_training_progress.status_code == 2:0 P; O: H7 G) o: _# u, v* R
background_task.add_task(" I1 `+ F: }. S* `& }% J% l
task.new_doc_topic_distribution_predict, * Q$ z% `- e: L% N+ J0 Y new_doc_text0 g: j$ |3 k& i3 f& t
) ' }4 }, n8 Q& w6 W' M return {"message": "已添加新文档主题分布预测后台任务"} / Z" t' z' M4 p8 ^( M& n4 X else:5 y/ C+ m7 L5 ^# ^1 u) S
raise HTTPException(status_code=404, detail="请先等待NMF训练结束!"): c2 f5 ?- y( Y% M5 [
else: 4 k9 r+ E% t- D$ f5 \' j: t raise HTTPException(status_code=404, detail="未找到相应的训练对象!")) C1 S6 ~1 U+ e+ J
6 p6 E& x' |! h) U( L . K% Y+ Q$ i) v. O8 p+ m7 q@app.get( ) e# T' G/ k% } "/calculate/preprocessing/progress/",3 l; `3 g: ?+ u+ d l9 G
tags=["计算模块数据接口"],8 t# {2 G7 e! \, F h$ l0 `
response_model=TextPreprocessingProgress9 M, N0 b: l/ y% x
). @6 W* |2 D2 I; G" ~5 d
def get_text_preprocessing_task_progress(user_uuid: str = Cookie(None)):7 c: E) o" ^) g! A/ }
global topic_model_training_tasks: g. Z6 f) y3 Z' N
9 D% @' a# A4 P/ ]7 ? if (not user_uuid) or (user_uuid not in topic_model_training_tasks):. d" T9 K5 C1 q4 c
raise HTTPException(status_code=404, detail="未找到相应的训练对象!") ! I' O$ ~4 }% D: O3 w return topic_model_training_tasks[user_uuid].text_preprocessing_progress- Y0 L5 P/ m3 ~* k7 K2 z* C) z
# l$ v' b% ] v4 S+ d. _7 h