This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------- | |
// i2c_scanner | |
// | |
// Version 1 | |
// This program (or code that looks like it) | |
// can be found in many places. | |
// For example on the Arduino.cc forum. | |
// The original author is not known. | |
// Version 2, Juni 2012, Using Arduino 1.0.1 | |
// Adapted to be as simple as possible by Arduino.cc user Krodal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import StringDist | |
Input_text = 'ผมรักคุณ' | |
compare_text = 'คุณรักผม' | |
result = stringdist.levenshtein_norm(Input_text,compare_text) | |
print(result) | |
##result = 0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import StringDist | |
Input_text = 'ผมรักคุณ' | |
compare_text = 'คุณรักผม' | |
result = stringdist.levenshtein_norm(Input_text,compare_text) | |
print(result) | |
##result = 0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymongo import MongoClient | |
client = MongoClient( | |
'mongodb://<dbuser>:<dbpassword>@ds359298.mlab.com:59298/heroku_7hhcq7v4?retryWrites=false') ##แทนด้วย url user pass ตัวเองนะครับ | |
chatbot_db = client["heroku_7hhcq7v4"] | |
def read_data(collection_name):## อ่านข้้อมูลจาก Database นะครับ | |
compare_text =[] | |
intent_text=[] # สร้าง list ไว้เปรียบเทียบ | |
my_collection = chatbot_db[collection_name] #เรียก coloection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_data(collection_name,data):## collection ที่ต้องการส่ง และข้อมูล | |
my_collection = chatbot_db[collection_name] #เรียก coloection | |
my_collection.insert_one(data) #ส่ง data | |
print("collection:",collection_name,"inserted!","data:",data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from db_connect import read_data, send_data ## แยกตัวส่งข้อมูลออกมา | |
import stringdist as sd | |
from write_log import write_log,write_untrain #ตัวสร้าง log | |
import pendulum #จัดการ Timestamp | |
def find_distance(input_keyword): | |
distance_list = [] #list | |
theshold = 0.9 #กำหนก theshold สักหน่อย | |
timenow = pendulum.now('Asia/Bangkok') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write_log(timenow,input_keyword,predicted_answer,distance_value): | |
Log_obj={ | |
'time':timenow, | |
'input':input_keyword, | |
'answer': predicted_answer, | |
'distance':distance_value | |
} | |
print('wrote log') | |
return Log_obj | |
def write_untrain(timenow,input_keyword,predicted_answer,distance_value): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from textprocessing import find_distance | |
@handler.add(MessageEvent, message=TextMessage) | |
def handle_message(event): | |
input_msg=event.message.text | |
reply_msg = find_distance(input_msg) | |
line_bot_api.reply_message( | |
event.reply_token, | |
TextSendMessage(text=reply_msg)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first install gcsfuse | |
%%capture | |
!echo "deb http://packages.cloud.google.com/apt gcsfuse-bionic main" > /etc/apt/sources.list.d/gcsfuse.list | |
!curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - | |
!apt update | |
!apt install gcsfuse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%env GOOGLE_APPLICATION_CREDENTIALS=/key.json | |
!mkdir /content/my-bucket | |
!gcsfuse my-bucket /content/my-bucket ##ตามBucket | |
import sys | |
nb_path = '/content/my-bucket' #สำคัญที่บรรทัดนี้ครับผม | |
sys.path.insert(0, nb_path) | |
# Do this just once | |
!pip install --target=$nb_path pythainlp |
OlderNewer