Toggle navigation
Toggle navigation
This project
Loading...
Sign in
윤창신
/
searchGuide
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
bluejoyq
2019-12-03 18:20:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ee9e8644894bb571ce7cd5f21785cba4cf746e5e
ee9e8644
1 parent
2b988a78
add machine read server py
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
model/app.py
model/app.py
0 → 100644
View file @
ee9e864
from
flask
import
Flask
,
redirect
,
url_for
,
request
from
gensim.models.doc2vec
import
Doc2Vec
from
konlpy.tag
import
Mecab
import
json
import
sys
model
=
Doc2Vec
.
load
(
"doc2vec.model"
)
app
=
Flask
(
__name__
)
@app.route
(
'/analyze'
,
methods
=
[
'POST'
])
def
sendreq
():
try
:
data
=
request
.
data
.
decode
(
'utf-8'
)
.
replace
(
"'"
,
'"'
)
datadic
=
json
.
loads
(
data
)
sentence1
=
datadic
[
"sentence1"
]
sentence2
=
datadic
[
"sentence2"
]
token1
=
parsetoken
(
sentence1
)
token2
=
parsetoken
(
sentence2
)
num_similar
=
model
.
n_similarity
(
token1
,
token2
)
return
json
.
dumps
({
"result"
:
str
(
num_similar
)})
except
:
return
json
.
dumps
({
"result"
:
-
1
})
def
parsetoken
(
sentence
):
mecab
=
Mecab
()
lst
=
[]
tags
=
mecab
.
pos
(
sentence
)
for
tag
in
tags
:
try
:
model
[
"/"
.
join
(
tag
)]
lst
.
append
(
"/"
.
join
(
tag
))
except
:
null
# resdata = dict(zip(range(1, len(lst) + 1), lst))
return
lst
if
__name__
==
"__main__"
:
app
.
run
()
Please
register
or
login
to post a comment