-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimilarJobs.py
46 lines (36 loc) · 1.31 KB
/
SimilarJobs.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
43
44
45
46
import configparser
import re
from flask import Flask
from flask import jsonify
from flask import request
import pymorphy2
from gensim.models import KeyedVectors
import pickle
from flask_cors import CORS
config = configparser.ConfigParser()
config.read('config.ini')
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}}, send_wildcard=True)
model_w2v_ru = KeyedVectors.load_word2vec_format('../web_0_300_20.bin', binary=True)
model_ru = pymorphy2.MorphAnalyzer()
with open(config['Data']['Path']+'title_words.pickle', 'rb') as file:
title_words = pickle.load(file)
@app.route('/similar', methods=['POST'])
def similar():
words = re.findall('\w+', request.json['query'])
word_pos = []
similar_words = []
for word in words:
word_pos = model_ru.parse(word)[0].tag.POS
similar_words.append(model_w2v_ru.most_similar(word+'_'+word_pos))
similar_words = [word for el in similar_words for word in el]
words = list(map(lambda x:x[0].split('_')[0], similar_words))
words_in_title = []
for word in words:
if word in title_words.keys():
words_in_title.append(word)
response = jsonify(words_in_title)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
if __name__=='__main__':
app.run(host='127.0.0.1', port=13562)