This file contains hidden or 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 handle_location(lat,lng,cdat,topK): | |
| result = getdistace(lat, lng,cdat) | |
| result = result.sort_values(by='km') | |
| result = result.iloc[0:topK] | |
| txtResult = '' | |
| for i in range(len(result)): | |
| kmdistance = '%.1f'%(result.iloc[i]['km']) | |
| newssource = str(result.iloc[i]['News_Soruce']) | |
| txtResult = txtResult + kmdistance + '\n' + newssource + '\n\n' | |
| return txtResult[0:-2] |
This file contains hidden or 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
| { | |
| "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", | |
| "type": "message", | |
| "mode": "active", | |
| "timestamp": 1462629479859, | |
| "source": { | |
| "type": "user", | |
| "userId": "U4af4980629..." | |
| }, | |
| "message": { |
This file contains hidden or 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 geopy.distance as ps | |
| def getdistace(latitude, longitude,cdat): | |
| coords_1 = (float(latitude), float(longitude)) | |
| ## create list of all reference locations from a pandas DataFrame | |
| latlngList = cdat[['Latitude','Longitude']].values | |
| ## loop and calculate distance in KM using geopy.distance library and append to distance list | |
| kmsumList = [] | |
| for latlng in latlngList: | |
| coords_2 = (float(latlng[0]),float(latlng[1])) | |
| kmsumList.append(ps.vincenty(coords_1, coords_2).km) |
This file contains hidden or 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 namesearch(pquery,mquery,nn=10,gender='',day=''): | |
| ndb = namedb.copy() | |
| if gender!='': | |
| ndb = ndb[ndb['เพศ']==gender] | |
| if day!='': | |
| ndb = ndb[ndb['วันเกิด']==day] | |
| psc = pronouncescore(pquery,ndb) | |
| msc = meaningscore(mquery,ndb) | |
| tsc = psc+msc | |
| asort = np.argsort(-tsc)[0:nn] |
This file contains hidden or 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 w2vdist(query,nvec): | |
| res = sentence2vec(query) | |
| nmat = np.vstack(nvec) | |
| return np.dot(res,nmat.T) |
This file contains hidden or 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
| mod = pickle.load(open('botnoiw2v.mod','rb')) | |
| def sentence2vec(sentence): | |
| wList = word_tokenize(sentence) | |
| w2vList = [] | |
| for w in wList: | |
| try: | |
| w2vList.append(mod[w]) | |
| except: | |
| w2vList.append(np.zeros(150)) | |
| feat = np.mean(w2vList,0) |
This file contains hidden or 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 pronouncescore(query,ndb): | |
| pdList = np.array(callev(query,ndb['สะกด'].values)) | |
| ndList = np.array(callev(query,ndb['ชื่อ'].values)) | |
| psc = 1-(pdList + ndList)/2 | |
| return psc | |
| def callev(query,namelist): | |
| dList = [] | |
| for n in namelist: | |
| dList.append(sd.levenshtein_norm(query, n)) |
This file contains hidden or 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 gettitlefeature(featMat): | |
| fn = featMat['Name'].str.split(',') | |
| tt = [n[1][0:3] for n in fn] | |
| featMat['Title'] = tt | |
| featMat = createdummie(featMat,'Title') | |
| return featMat |
This file contains hidden or 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 createdummie(dat,col): | |
| dummiefeature = pd.get_dummies(dat[col]) | |
| dummiefeature = dummiefeature.iloc[:,0:-1] | |
| dat = pd.concat([dat,dummiefeature],axis=1) | |
| return dat |
This file contains hidden or 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 feature_extraction(featMat): | |
| featMat = converttobinary(featMat,'Sex','male') | |
| featMat = featMat._get_numeric_data() | |
| featMat = featMat.fillna(0) | |
| return featMat |