{"id":381719,"date":"2024-06-29T03:50:07","date_gmt":"2024-06-29T03:50:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=381719"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=381719","title":{"rendered":"<span>\u041f\u0438\u0448\u0435\u043c \u0447\u0430\u0442-\u0431\u043e\u0442 \u043d\u0430 Python + PostgreSQL \u0438 Telegram<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u043e\u0448\u0430\u0433\u043e\u0432\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Python.<\/h2>\n<ul>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Python \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0442\u0432\u0435\u0442\u044b \u0438\u0437 \u0411\u0414 PostgreSQL;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u044e;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0447\u0430\u0442-\u0431\u043e\u0442 \u043a \u043a\u0430\u043d\u0430\u043b\u0443 Telegram.<\/p>\n<\/li>\n<\/ul>\n<h2>Colaboratory \u043e\u0442 Google<\/h2>\n<p>\u0418\u0437\u0443\u0447\u0435\u043d\u0438\u0435 Python \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0435\u0440\u0432\u0438\u0441 <a href=\"https:\/\/colab.research.google.com\/\" rel=\"noopener noreferrer nofollow\">Colaboratory <\/a>\u043e\u0442 Google, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e Colab. \u0421\u0435\u0440\u0432\u0438\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u0434 Python \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044f   \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430. \u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0442\u0432\u0435\u0442\u044b \u0434\u043b\u044f \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u0438\u043c \u0441 <a href=\"https:\/\/drive.google.com\" rel=\"noopener noreferrer nofollow\">https:\/\/drive.google.com<\/a> \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430<\/p>\n<pre><code># \u041e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 pymorphy2 \u0438 numpy !pip install pymorphy2 numpy  # ----------------------------  # \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 import  csv import pymorphy2 import re  morph = pymorphy2.MorphAnalyzer(lang='ru')  # \u041c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 questions=[]   # \u041c\u0430\u0441\u0441\u0438\u0432 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 answer=[]   # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0441 Google \u0434\u0438\u0441\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441\u044b\/\u043e\u0442\u0432\u0435\u0442\u044b # \u0415\u0441\u0442\u044c \u043b\u0438 \u0436\u0438\u0437\u043d\u044c \u043d\u0430 \u043c\u0430\u0440\u0441\u0435;\u0415\u0441\u0442\u044c  with open(\"\/content\/drive\/MyDrive\/robo-bot\/question.txt\", \"r\") as f_obj:   reader = csv.reader(f_obj)   for row in reader:     s=\" \".join(row)     r=s.split(';')     questions.append(r[0])     answer.append(r[1])  # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 print (questions) print (answer)  <\/code><\/pre>\n<h2>\u0417\u0430\u043f\u0443\u0441\u043a \u0432 Production<\/h2>\n<p>\u041d\u0430\u0438\u0433\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u0441 \u043a\u043e\u0434\u043e\u043c \u0432 Colaboratory \u0438 \u043e\u0441\u0432\u043e\u0438\u0432 Python \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043d\u0430 \u0431\u043e\u0435\u0432\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 Debian<\/p>\n<p><strong>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Python \u0438 PIP (\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0449\u0438\u043a \u043f\u0430\u043a\u0435\u0442\u043e\u0432).<\/strong> <\/p>\n<p><em>\u0422\u0430\u043a \u043a\u0430\u043a Debian \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u043d\u043e\u0432\u044b\u0439, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u0441\u0438\u044f 3.5<\/em><\/p>\n<pre><code>aptitude install python3 python3-pip  # \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043f\u0430\u043a\u0435\u0442\u044b \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0440\u0430\u043d\u0435\u0435 pip3 install --upgrade setuptools pip<\/code><\/pre>\n<p><strong>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b Python<\/strong><\/p>\n<pre><code># \u0418\u0437 \u0437\u0430 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Debian \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c psycopg2 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 psycopg2-binary  # \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 psycopg2 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL  # pip3 install psycopg2  pip3 install psycopg2-binary scikit-learn numpy pymorphy2<\/code><\/pre>\n<h2>\u041f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0432 \u0444\u0430\u0439\u043b\u0435 Chat_bot.py<\/h2>\n<pre><code># \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 import pymorphy2 import re import psycopg2 import sklearn import numpy as np   # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a PostgreSQL conn = psycopg2.connect(dbname='energy', user='mao', password='darin', host='localhost') cursor = conn.cursor()  # \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u044f\u0437\u044b\u043a \u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0438 morph = pymorphy2.MorphAnalyzer(lang='ru')  # \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u0434\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 answer_id=[]  answer = dict()  # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 PostgreSQL \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0438\u0445. # \u0420\u0430\u0431\u043e\u0442\u0430\u044f \u0441 PostgreSQL \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u0445\u0435\u043c\u0435 app, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 cursor.execute('SELECT id, answer FROM app.chats_answer;') records = cursor.fetchall() for row in records: answer[row[0]]=row[1]    <\/code><\/pre>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432 chats_answer, \u0444\u043e\u0440\u043c\u0430\u0442 SQL<\/p>\n<pre><code>CREATE TABLE app.chats_answer (   id SERIAL,   answer VARCHAR(512),   CONSTRAINT chats_answer_pkey PRIMARY KEY(id) )  WITH (oids = false);  ALTER TABLE app.chats_answer   OWNER TO mao;<\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">id<\/p>\n<\/td>\n<td>\n<p align=\"left\">answer<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041c\u043d\u0435 45 \u043b\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0430, \u044f \u0433\u043e\u0442\u043e\u0432 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u042f \u0442\u043e\u0436\u0435 \u0445\u043e\u0447\u0443 \u0441\u043f\u0430\u0442\u044c<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 chats_question, \u0444\u043e\u0440\u043c\u0430\u0442 SQL. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u043a\u043e\u0434\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<pre><code>CREATE TABLE app.chats_question (   id SERIAL,   question VARCHAR(512),   answer_id INTEGER,   CONSTRAINT chats_question_pkey PRIMARY KEY(id) )  WITH (oids = false);  ALTER TABLE app.chats_question   OWNER TO mao;<\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">id<\/p>\n<\/td>\n<td>\n<p align=\"left\">question<\/p>\n<\/td>\n<td>\n<p align=\"left\">answer_id<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0431\u0435 \u043b\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041b\u0435\u0442 \u0442\u043e \u0442\u0435\u0431\u0435 \u0441\u043a\u043e\u043b\u044c\u043a\u043e<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">4<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0440\u0435\u0439\u043b\u0435\u0440 \u0444\u0438\u043b\u044c\u043c\u0430 \u041c\u0430\u0442\u0440\u0438\u0446\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">6<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u043a\u0430 \u043c\u043e\u0439 \u0434\u0440\u0443\u0433<\/p>\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043a\u043e\u0434 \u0432 \u0444\u0430\u0439\u043b\u0435 Chat_bot.py<\/h3>\n<pre><code># \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 questions=[]   # \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043a\u043e\u0434\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432 cursor.execute('SELECT question, answer_id FROM app.chats_question;') records = cursor.fetchall()  # \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 transform=0  for row in records: # \u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0441\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0439  if row[0]>\"\":    # \u0415\u0441\u043b\u0438 \u0432 \u0411\u0414 \u0435\u0441\u0442\u044c \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441   if row[1]>0:    phrases=row[0]        # \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430    words=phrases.split(' ')    phrase=\"\"    for word in words:       # \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0438\u0437 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0432\u043e\u0444\u043e\u0440\u043c\u0443       word = morph.parse(word)[0].normal_form    # \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0440\u0430\u0437\u0443 \u0438\u0437 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u043e\u0432      phrase = phrase + word + \" \"               # \u0415\u0441\u043b\u0438 \u0434\u043b\u0438\u043d\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0444\u0440\u0430\u0437\u044b \u0431\u043e\u043b\u044c\u0448\u0435 0 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0439 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u0434\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u043e\u0432    if (len(phrase)>0):     questions.append(phrase.strip())     answer_id.append(row[1])     transform=transform+1  # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043e\u0442\u0432\u0435\u0442\u044b \u0438 \u043a\u043e\u0434\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432 print (questions) print (answer) print (answer_id)  # \u0417\u0430\u043a\u0440\u043e\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a PostgreSQL cursor.close() conn.close()<\/code><\/pre>\n<h2>\u0412\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f<\/h2>\n<pre><code># \u0412\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0432 \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443  # \u041f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0438\u0432 \u0444\u0440\u0430\u0437\u044b \u043d\u0430 \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f  from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.decomposition import TruncatedSVD  vectorizer_q = TfidfVectorizer() vectorizer_q.fit(questions) matrix_big_q = vectorizer_q.transform(questions) print (\"\u0420\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0442\u0440\u0438\u0446\u044b: \") print (matrix_big_q.shape)  # \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 # \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0432 200 \u043c\u0435\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u0435\u0441\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 200 # \u0420\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0431\u0430\u0437\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c 1 \u043c\u043b\u043d. \u0438\u043b\u0438 1\u043a \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 1 # \u0411\u0435\u0437 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043f\u043e\u0442\u0435\u0440\u044f\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438  if transform>200: transform=200  svd_q = TruncatedSVD(n_components=transform) svd_q.fit(matrix_big_q)  # \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 matrix_small_q = svd_q.transform(matrix_big_q)  print (\"\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u044b: \") print ( svd_q.explained_variance_ratio_.sum()) <\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<pre><code># \u0422\u0435\u043b\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432  from sklearn.neighbors import BallTree from sklearn.base import BaseEstimator  def softmax(x):   #\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f   proba = np.exp(-x)   return proba \/ sum(proba)  class NeighborSampler(BaseEstimator):   def __init__(self, k=5, temperature=10.0):     self.k=k     self.temperature = temperature   def fit(self, X, y):     self.tree_ = BallTree(X)     self.y_ = np.array(y)   def predict(self, X, random_state=None):     distances, indices = self.tree_.query(X, return_distance=True, k=self.k)     result = []     for distance, index in zip(distances, indices):       result.append(np.random.choice(index, p=softmax(distance * self.temperature)))     return self.y_[result]  from sklearn.pipeline import make_pipeline  ns_q = NeighborSampler()  # answer_id - \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 ns_q.fit(matrix_small_q, answer_id)  pipe_q = make_pipeline(vectorizer_q, svd_q, ns_q)<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438<\/p>\n<pre><code># \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438  print(\"\u041f\u0438\u0448\u0438\u0442\u0435 \u0432\u0430\u0448 \u0432\u043e\u043f\u0440\u043e\u0441, \u0441\u043b\u043e\u0432\u0430 exit \u0438\u043b\u0438 \u0432\u044b\u0445\u043e\u0434 \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430\")  request=\"\"  while request not in ['exit', '\u0432\u044b\u0445\u043e\u0434']: # \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0435\u043a\u0441\u0442 \u043e\u0442 \u0432\u0432\u043e\u0434\u0430 request=input()      # \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0444\u0440\u0430\u0437\u0443 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430  words= re.split('\\W',request)  phrase=\"\"  for word in words:     word = morph.parse(word)[0].normal_form  # \u043c\u043e\u0440\u0444\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0432\u043e\u0444\u043e\u0440\u043c\u0443     # \u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u043e\u0444\u043e\u0440\u043c\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0438 \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0444\u0440\u0430\u0437\u0443     phrase = phrase + word + \" \"  # \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430  reply_id    = int(pipe_q.predict([phrase.strip()]))    # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u043e\u0442\u0432\u0435\u0442\u0430  print (answer[reply_id]) <\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c<\/p>\n<pre><code>python3 Chat_bot.py<\/code><\/pre>\n<h2>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c Telegram<\/h2>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443<\/p>\n<pre><code># \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435 \u0441\u0430\u043c\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 #pip3 install PyTelegramBotAPI  pip3 install PyTelegramBotAPI==3.6.7<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c Telegram \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u0431\u043e\u0442\u0443 <a href=\"https:\/\/t.me\/botfather\" rel=\"noopener noreferrer nofollow\">@BOTFATHER<\/a> https:\/\/t.me\/botfather<\/p>\n<p>\u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c token.<\/p>\n<pre><code>import telebot  telebot.apihelper.ENABLE_MIDDLEWARE = True  # \u0423\u043a\u0430\u0436\u0435\u043c token \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u043e\u0442\u0430 bot = telebot.TeleBot(\"9999999999:AABBCCDDEEFFGGQWERTYUIOPASDFGHJKLLK\")  # \u041d\u0430\u0447\u043d\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0431\u043e\u0442\u0430, \u043e\u0442\u0432\u0435\u0442\u0438\u043c  @bot.message_handler(commands=['start']) def start_message(message): bot.send_message(message.from_user.id, \" \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435. \u042f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u043e\u0442 Mao!\")  # \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b, \u043e\u0442\u0432\u0435\u0442\u0438\u043c @bot.message_handler(func=lambda message: True) def get_text_messages(message): request=message.text      # \u0440\u0430\u0437\u043e\u0431\u044c\u0451\u043c \u0444\u0440\u0430\u0437\u0443 \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043b\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f split. '\\W' - \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043a\u0440\u043e\u043c\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0446\u0438\u0444\u0440\u044b words= re.split('\\W',request) phrase=\"\"    # \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0444\u0440\u0430\u0437\u0443 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430, \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u0438 \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0444\u0440\u0430\u0437\u0443 for word in words: word = morph.parse(word)[0].normal_form       phrase = phrase + word + \" \"    # \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e    reply_id    = int(pipe_q.predict([phrase.strip()]))      # \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u043e\u0442\u0432\u0435\u0442 bot.send_message(message.from_user.id, answer[reply_id])  # \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441 id=99999999 # bot.send_message(99999999, str(message.from_user.id) + \"\\n\" + str(message.from_user.first_name) + \" \" + str(message.from_user.last_name) + \" \" +str(message.from_user.username) + \"\\n\"+ str(request) + \"\\n\"+ str(answer[reply_id]))      # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u043e\u043f\u0440\u043e\u0441 \/ \u043e\u0442\u0432\u0435\u0442\u0430 print(\"\u0417\u0430\u043f\u0440\u043e\u0441:\", request, \" \\n\\t\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439: \", phrase, \" \\n\\t\\t\u041e\u0442\u0432\u0435\u0442 :\", answer[reply_id])  # \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u043e\u0442\u0430 bot.infinity_polling(none_stop=True, interval=1) <\/code><\/pre>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e. \u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442 \u0441\u043b\u0443\u0436\u0431\u044b \u0442\u0435\u0445. \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438. \u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043c\u0430\u0440\u043a\u0435\u0442\u043e\u043b\u043e\u0433\u0443 \u0432 \u0430\u0434\u043c\u0438\u043d \u043f\u0430\u043d\u0435\u043b\u0438 \u043d\u0430 YII \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c. \u0420\u0430\u0437 \u0432 \u0441\u0443\u0442\u043a\u0438 cron \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430, \u043d\u043e\u0432\u044b\u0435 \u0444\u0440\u0430\u0437\u044b \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<h2>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0447\u0430\u0442 \u0431\u043e\u0442\u0430<\/h2>\n<pre><code>import csv import pymorphy2 import re   import psycopg2 conn = psycopg2.connect(dbname='energy', user='mao', password='daring', host='localhost') cursor = conn.cursor()  morph = pymorphy2.MorphAnalyzer(lang='ru')   answer_id=[]  answer = dict()  cursor.execute('SELECT id, answer FROM app.chats_answer;') records = cursor.fetchall() for row in records:  answer[row[0]]=row[1]  questions=[]   cursor.execute('SELECT question, answer_id FROM app.chats_question;') records = cursor.fetchall() transform=0  for row in records:  if row[0]>\"\":   if row[1]>0:    phrases=row[0]    words=phrases.split(' ')    phrase=\"\"    for word in words:     word = morph.parse(word)[0].normal_form       phrase = phrase + word + \" \"    if (len(phrase)>0):     questions.append(phrase.strip())     answer_id.append(row[1])     transform=transform+1  #print (questions) #print (answer) #print (answer_id)  cursor.close() conn.close()  import sklearn from sklearn.feature_extraction.text import TfidfVectorizer  from sklearn.decomposition import TruncatedSVD  vectorizer_q = TfidfVectorizer() vectorizer_q.fit(questions) matrix_big_q = vectorizer_q.transform(questions) print (\"\u0420\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0442\u0440\u0438\u0446\u044b: \") print (matrix_big_q.shape)  if transform>200:  transform=200 print(transform) svd_q = TruncatedSVD(n_components=transform) svd_q.fit(matrix_big_q) matrix_small_q = svd_q.transform(matrix_big_q) print (\"\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u044b: \") print ( svd_q.explained_variance_ratio_.sum())   # \u0442\u0435\u043b\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b k=5, temperature=10.0 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c import numpy as np  from sklearn.neighbors import BallTree from sklearn.base import BaseEstimator  def softmax(x):   #\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f   proba = np.exp(-x)   return proba \/ sum(proba)  class NeighborSampler(BaseEstimator):   def __init__(self, k=5, temperature=10.0):     self.k=k     self.temperature = temperature   def fit(self, X, y):     self.tree_ = BallTree(X)     self.y_ = np.array(y)   def predict(self, X, random_state=None):     distances, indices = self.tree_.query(X, return_distance=True, k=self.k)     result = []     for distance, index in zip(distances, indices):       result.append(np.random.choice(index, p=softmax(distance * self.temperature)))     return self.y_[result]  from sklearn.pipeline import make_pipeline  ns_q = NeighborSampler() ns_q.fit(matrix_small_q, answer_id)  pipe_q = make_pipeline(vectorizer_q, svd_q, ns_q)   import re import telebot telebot.apihelper.ENABLE_MIDDLEWARE = True bot = telebot.TeleBot(\"299999999:sdfgnreognrtgortgmrtgmrtgm\")  @bot.message_handler(commands=['start']) def start_message(message): bot.send_message(message.from_user.id, \" \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435. \u042f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a Mao?\")  @bot.message_handler(func=lambda message: True) def get_text_messages(message): request=message.text words= re.split('\\W',request) phrase=\"\" for word in words: word = morph.parse(word)[0].normal_form   phrase = phrase + word + \" \" reply_id    = int(pipe_q.predict([phrase.strip()])) bot.send_message(message.from_user.id, answer[reply_id]) print(\"\u0417\u0430\u043f\u0440\u043e\u0441:\", request, \" \\n\\t\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439: \", phrase, \" \\n\\t\\t\u041e\u0442\u0432\u0435\u0442 :\", answer[reply_id])  bot.infinity_polling(none_stop=True, interval=1)   print(\"\u041f\u0438\u0448\u0438\u0442\u0435 \u0432\u0430\u0448 \u0432\u043e\u043f\u0440\u043e\u0441, \u0441\u043b\u043e\u0432\u0430 exit \u0438\u043b\u0438 \u0432\u044b\u0445\u043e\u0434 \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430\") request=\"\" while request not in ['exit', '\u0432\u044b\u0445\u043e\u0434']:  request=input()  words= re.split('\\W',request)  phrase=\"\"  for word in words:   word = morph.parse(word)[0].normal_form     phrase = phrase + word + \" \"  reply_id    = int(pipe_q.predict([phrase.strip()]))  print (answer[reply_id])  <\/code><\/pre>\n<p>\u0412 \u0442\u0435\u043b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 k=5 \u0438 temperature=10.0. \u0418\u0445 \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043f\u043e\u0438\u0441\u043a, \u0434\u0435\u043b\u0430\u044f \u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043c\u044f\u0433\u043a\u0438\u043c \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0436\u0435\u0441\u0442\u043a\u0438\u043c.<\/p>\n<p>P.S. \u0423\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438. \u0422\u0435\u043e\u0440\u0438\u044e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/habr.com\/ru\/post\/462333\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/593065\/\"> https:\/\/habr.com\/ru\/articles\/593065\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u043e\u0448\u0430\u0433\u043e\u0432\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Python.<\/h2>\n<ul>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Python \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0442\u0432\u0435\u0442\u044b \u0438\u0437 \u0411\u0414 PostgreSQL;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u044e;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0447\u0430\u0442-\u0431\u043e\u0442 \u043a \u043a\u0430\u043d\u0430\u043b\u0443 Telegram.<\/p>\n<\/li>\n<\/ul>\n<h2>Colaboratory \u043e\u0442 Google<\/h2>\n<p>\u0418\u0437\u0443\u0447\u0435\u043d\u0438\u0435 Python \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0435\u0440\u0432\u0438\u0441 <a href=\"https:\/\/colab.research.google.com\/\" rel=\"noopener noreferrer nofollow\">Colaboratory <\/a>\u043e\u0442 Google, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e Colab. \u0421\u0435\u0440\u0432\u0438\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u0434 Python \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044f   \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430. \u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0442\u0432\u0435\u0442\u044b \u0434\u043b\u044f \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u0438\u043c \u0441 <a href=\"https:\/\/drive.google.com\" rel=\"noopener noreferrer nofollow\">https:\/\/drive.google.com<\/a> \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430<\/p>\n<pre><code># \u041e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 pymorphy2 \u0438 numpy !pip install pymorphy2 numpy  # ----------------------------  # \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 import  csv import pymorphy2 import re  morph = pymorphy2.MorphAnalyzer(lang='ru')  # \u041c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 questions=[]   # \u041c\u0430\u0441\u0441\u0438\u0432 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 answer=[]   # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0441 Google \u0434\u0438\u0441\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441\u044b\/\u043e\u0442\u0432\u0435\u0442\u044b # \u0415\u0441\u0442\u044c \u043b\u0438 \u0436\u0438\u0437\u043d\u044c \u043d\u0430 \u043c\u0430\u0440\u0441\u0435;\u0415\u0441\u0442\u044c  with open(\"\/content\/drive\/MyDrive\/robo-bot\/question.txt\", \"r\") as f_obj:   reader = csv.reader(f_obj)   for row in reader:     s=\" \".join(row)     r=s.split(';')     questions.append(r[0])     answer.append(r[1])  # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 print (questions) print (answer)  <\/code><\/pre>\n<h2>\u0417\u0430\u043f\u0443\u0441\u043a \u0432 Production<\/h2>\n<p>\u041d\u0430\u0438\u0433\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u0441 \u043a\u043e\u0434\u043e\u043c \u0432 Colaboratory \u0438 \u043e\u0441\u0432\u043e\u0438\u0432 Python \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043d\u0430 \u0431\u043e\u0435\u0432\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 Debian<\/p>\n<p><strong>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Python \u0438 PIP (\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0449\u0438\u043a \u043f\u0430\u043a\u0435\u0442\u043e\u0432).<\/strong> <\/p>\n<p><em>\u0422\u0430\u043a \u043a\u0430\u043a Debian \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u043d\u043e\u0432\u044b\u0439, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u0441\u0438\u044f 3.5<\/em><\/p>\n<pre><code>aptitude install python3 python3-pip  # \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043f\u0430\u043a\u0435\u0442\u044b \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0440\u0430\u043d\u0435\u0435 pip3 install --upgrade setuptools pip<\/code><\/pre>\n<p><strong>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b Python<\/strong><\/p>\n<pre><code># \u0418\u0437 \u0437\u0430 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Debian \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c psycopg2 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 psycopg2-binary  # \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 psycopg2 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL  # pip3 install psycopg2  pip3 install psycopg2-binary scikit-learn numpy pymorphy2<\/code><\/pre>\n<h2>\u041f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0432 \u0444\u0430\u0439\u043b\u0435 Chat_bot.py<\/h2>\n<pre><code># \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 import pymorphy2 import re import psycopg2 import sklearn import numpy as np   # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a PostgreSQL conn = psycopg2.connect(dbname='energy', user='mao', password='darin', host='localhost') cursor = conn.cursor()  # \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u044f\u0437\u044b\u043a \u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0438 morph = pymorphy2.MorphAnalyzer(lang='ru')  # \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u0434\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 answer_id=[]  answer = dict()  # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 PostgreSQL \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0438\u0445. # \u0420\u0430\u0431\u043e\u0442\u0430\u044f \u0441 PostgreSQL \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u0445\u0435\u043c\u0435 app, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 cursor.execute('SELECT id, answer FROM app.chats_answer;') records = cursor.fetchall() for row in records: answer[row[0]]=row[1]    <\/code><\/pre>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432 chats_answer, \u0444\u043e\u0440\u043c\u0430\u0442 SQL<\/p>\n<pre><code>CREATE TABLE app.chats_answer (   id SERIAL,   answer VARCHAR(512),   CONSTRAINT chats_answer_pkey PRIMARY KEY(id) )  WITH (oids = false);  ALTER TABLE app.chats_answer   OWNER TO mao;<\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">id<\/p>\n<\/td>\n<td>\n<p align=\"left\">answer<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041c\u043d\u0435 45 \u043b\u0435\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0430, \u044f \u0433\u043e\u0442\u043e\u0432 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u042f \u0442\u043e\u0436\u0435 \u0445\u043e\u0447\u0443 \u0441\u043f\u0430\u0442\u044c<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 chats_question, \u0444\u043e\u0440\u043c\u0430\u0442 SQL. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u043a\u043e\u0434\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<pre><code>CREATE TABLE app.chats_question (   id SERIAL,   question VARCHAR(512),   answer_id INTEGER,   CONSTRAINT chats_question_pkey PRIMARY KEY(id) )  WITH (oids = false);  ALTER TABLE app.chats_question   OWNER TO mao;<\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">id<\/p>\n<\/td>\n<td>\n<p align=\"left\">question<\/p>\n<\/td>\n<td>\n<p align=\"left\">answer_id<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0431\u0435 \u043b\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041b\u0435\u0442 \u0442\u043e \u0442\u0435\u0431\u0435 \u0441\u043a\u043e\u043b\u044c\u043a\u043e<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">4<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0440\u0435\u0439\u043b\u0435\u0440 \u0444\u0438\u043b\u044c\u043c\u0430 \u041c\u0430\u0442\u0440\u0438\u0446\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"223\" width=\"223\">\n<p align=\"left\">6<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043e\u043a\u0430 \u043c\u043e\u0439 \u0434\u0440\u0443\u0433<\/p>\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043a\u043e\u0434 \u0432 \u0444\u0430\u0439\u043b\u0435 Chat_bot.py<\/h3>\n<pre><code># \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 questions=[]   # \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043a\u043e\u0434\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432 cursor.execute('SELECT question, answer_id FROM app.chats_question;') records = cursor.fetchall()  # \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 transform=0  for row in records: # \u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0441\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0439  if row[0]>\"\":    # \u0415\u0441\u043b\u0438 \u0432 \u0411\u0414 \u0435\u0441\u0442\u044c \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441   if row[1]>0:    phrases=row[0]        # \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430    words=phrases.split(' ')    phrase=\"\"    for word in words:       # \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0438\u0437 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0432\u043e\u0444\u043e\u0440\u043c\u0443       word = morph.parse(word)[0].normal_form    # \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0440\u0430\u0437\u0443 \u0438\u0437 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u043e\u0432      phrase = phrase + word + \" \"               # \u0415\u0441\u043b\u0438 \u0434\u043b\u0438\u043d\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0444\u0440\u0430\u0437\u044b \u0431\u043e\u043b\u044c\u0448\u0435 0 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0439 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u0434\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u043e\u0432    if (len(phrase)>0):     questions.append(phrase.strip())     answer_id.append(row[1])     transform=transform+1  # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043e\u0442\u0432\u0435\u0442\u044b \u0438 \u043a\u043e\u0434\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432 print (questions) print (answer) print (answer_id)  # \u0417\u0430\u043a\u0440\u043e\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a PostgreSQL cursor.close() conn.close()<\/code><\/pre>\n<h2>\u0412\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f<\/h2>\n<pre><code># \u0412\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0432 \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443  # \u041f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0438\u0432 \u0444\u0440\u0430\u0437\u044b \u043d\u0430 \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f  from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.decomposition import TruncatedSVD  vectorizer_q = TfidfVectorizer() vectorizer_q.fit(questions) matrix_big_q = vectorizer_q.transform(questions) print (\"\u0420\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0442\u0440\u0438\u0446\u044b: \") print (matrix_big_q.shape)  # \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 # \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0432 200 \u043c\u0435\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u0435\u0441\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 200 # \u0420\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0431\u0430\u0437\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c 1 \u043c\u043b\u043d. \u0438\u043b\u0438 1\u043a \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 1 # \u0411\u0435\u0437 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043f\u043e\u0442\u0435\u0440\u044f\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438  if transform>200: transform=200  svd_q = TruncatedSVD(n_components=transform) svd_q.fit(matrix_big_q)  # \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 matrix_small_q = svd_q.transform(matrix_big_q)  print (\"\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u044b: \") print ( svd_q.explained_variance_ratio_.sum()) <\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<pre><code># \u0422\u0435\u043b\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432  from sklearn.neighbors import BallTree from sklearn.base import BaseEstimator  def softmax(x):   #\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f   proba = np.exp(-x)   return proba \/ sum(proba)  class NeighborSampler(BaseEstimator):   def __init__(self, k=5, temperature=10.0):     self.k=k     self.temperature = temperature   def fit(self, X, y):     self.tree_ = BallTree(X)     self.y_ = np.array(y)   def predict(self, X, random_state=None):     distances, indices = self.tree_.query(X, return_distance=True, k=self.k)     result = []     for distance, index in zip(distances, indices):       result.append(np.random.choice(index, p=softmax(distance * self.temperature)))     return self.y_[result]  from sklearn.pipeline import make_pipeline  ns_q = NeighborSampler()  # answer_id - \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 ns_q.fit(matrix_small_q, answer_id)  pipe_q = make_pipeline(vectorizer_q, svd_q, ns_q)<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438<\/p>\n<pre><code># \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438  print(\"\u041f\u0438\u0448\u0438\u0442\u0435 \u0432\u0430\u0448 \u0432\u043e\u043f\u0440\u043e\u0441, \u0441\u043b\u043e\u0432\u0430 exit \u0438\u043b\u0438 \u0432\u044b\u0445\u043e\u0434 \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430\")  request=\"\"  while request not in ['exit', '\u0432\u044b\u0445\u043e\u0434']: # \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0435\u043a\u0441\u0442 \u043e\u0442 \u0432\u0432\u043e\u0434\u0430 request=input()      # \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0444\u0440\u0430\u0437\u0443 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430  words= re.split('\\W',request)  phrase=\"\"  for word in words:     word = morph.parse(word)[0].normal_form  # \u043c\u043e\u0440\u0444\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0432\u043e\u0444\u043e\u0440\u043c\u0443     # \u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u043e\u0444\u043e\u0440\u043c\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0438 \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0444\u0440\u0430\u0437\u0443     phrase = phrase + word + \" \"  # \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430  reply_id    = int(pipe_q.predict([phrase.strip()]))    # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u043e\u0442\u0432\u0435\u0442\u0430  print (answer[reply_id]) <\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c<\/p>\n<pre><code>python3 Chat_bot.py<\/code><\/pre>\n<h2>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c Telegram<\/h2>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443<\/p>\n<pre><code># \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435 \u0441\u0430\u043c\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 #pip3 install PyTelegramBotAPI  pip3 install PyTelegramBotAPI==3.6.7<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c Telegram \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u0431\u043e\u0442\u0443 <a href=\"https:\/\/t.me\/botfather\" rel=\"noopener noreferrer nofollow\">@BOTFATHER<\/a> https:\/\/t.me\/botfather<\/p>\n<p>\u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c token.<\/p>\n<pre><code>import telebot  telebot.apihelper.ENABLE_MIDDLEWARE = True  # \u0423\u043a\u0430\u0436\u0435\u043c token \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u043e\u0442\u0430 bot = telebot.TeleBot(\"9999999999:AABBCCDDEEFFGGQWERTYUIOPASDFGHJKLLK\")  # \u041d\u0430\u0447\u043d\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0431\u043e\u0442\u0430, \u043e\u0442\u0432\u0435\u0442\u0438\u043c  @bot.message_handler(commands=['start']) def start_message(message): bot.send_message(message.from_user.id, \" \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435. \u042f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u043e\u0442 Mao!\")  # \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b, \u043e\u0442\u0432\u0435\u0442\u0438\u043c @bot.message_handler(func=lambda message: True) def get_text_messages(message): request=message.text      # \u0440\u0430\u0437\u043e\u0431\u044c\u0451\u043c \u0444\u0440\u0430\u0437\u0443 \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043b\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f split. '\\W' - \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043a\u0440\u043e\u043c\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0446\u0438\u0444\u0440\u044b words= re.split('\\W',request) phrase=\"\"    # \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0444\u0440\u0430\u0437\u0443 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430, \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u0438 \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0444\u0440\u0430\u0437\u0443 for word in words: word = morph.parse(word)[0].normal_form       phrase = phrase + word + \" \"    # \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e    reply_id    = int(pipe_q.predict([phrase.strip()]))      # \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u043e\u0442\u0432\u0435\u0442 bot.send_message(message.from_user.id, answer[reply_id])  # \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441 id=99999999 # bot.send_message(99999999, str(message.from_user.id) + \"\\n\" + str(message.from_user.first_name) + \" \" + str(message.from_user.last_name) + \" \" +str(message.from_user.username) + \"\\n\"+ str(request) + \"\\n\"+ str(answer[reply_id]))      # \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u043e\u043f\u0440\u043e\u0441 \/ \u043e\u0442\u0432\u0435\u0442\u0430 print(\"\u0417\u0430\u043f\u0440\u043e\u0441:\", request, \" \\n\\t\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439: \", phrase, \" \\n\\t\\t\u041e\u0442\u0432\u0435\u0442 :\", answer[reply_id])  # \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u043e\u0442\u0430 bot.infinity_polling(none_stop=True, interval=1) <\/code><\/pre>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e. \u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442 \u0441\u043b\u0443\u0436\u0431\u044b \u0442\u0435\u0445. \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438. \u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043c\u0430\u0440\u043a\u0435\u0442\u043e\u043b\u043e\u0433\u0443 \u0432 \u0430\u0434\u043c\u0438\u043d \u043f\u0430\u043d\u0435\u043b\u0438 \u043d\u0430 YII \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c. \u0420\u0430\u0437 \u0432 \u0441\u0443\u0442\u043a\u0438 cron \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430, \u043d\u043e\u0432\u044b\u0435 \u0444\u0440\u0430\u0437\u044b \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<h2>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0447\u0430\u0442 \u0431\u043e\u0442\u0430<\/h2>\n<pre><code>import csv import pymorphy2 import re   import psycopg2 conn = psycopg2.connect(dbname='energy', user='mao', password='daring', host='localhost') cursor = conn.cursor()  morph = pymorphy2.MorphAnalyzer(lang='ru')   answer_id=[]  answer = dict()  cursor.execute('SELECT id, answer FROM app.chats_answer;') records = cursor.fetchall() for row in records:  answer[row[0]]=row[1]  questions=[]   cursor.execute('SELECT question, answer_id FROM app.chats_question;') records = cursor.fetchall() transform=0  for row in records:  if row[0]>\"\":   if row[1]>0:    phrases=row[0]    words=phrases.split(' ')    phrase=\"\"    for word in words:     word = morph.parse(word)[0].normal_form       phrase = phrase + word + \" \"    if (len(phrase)>0):     questions.append(phrase.strip())     answer_id.append(row[1])<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-381719","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/381719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=381719"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/381719\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=381719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=381719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=381719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}