Skip to content

Instantly share code, notes, and snippets.

View vi3k6i5's full-sized avatar
πŸ‘¨β€πŸ’»
Learning...

Vikash Singh vi3k6i5

πŸ‘¨β€πŸ’»
Learning...
View GitHub Profile
@vi3k6i5
vi3k6i5 / comparison.md
Last active September 16, 2017 11:35
Comparison results for FlashText vs Regex
Text Length 319065 Keywords Count 47326
FlashText 156 ms per loop
Compiled Regex 19.5 s per loop
@vi3k6i5
vi3k6i5 / flashtext_regex_timing.ipynb
Last active September 27, 2017 18:07
Time FlashText and Regex for increasing number of keywords
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vi3k6i5
vi3k6i5 / flashtext_extract_example.py
Created September 15, 2017 18:38
FlashText extract keywords from sentence
# pip install flashtext
from flashtext.keyword import KeywordProcessor
keyword_processor = KeywordProcessor()
keyword_processor.add_keyword('Big Apple', 'New York')
keyword_processor.add_keyword('Bay Area')
keywords_found = keyword_processor.extract_keywords('I love Big Apple and Bay Area.')
keywords_found
# ['New York', 'Bay Area']
@vi3k6i5
vi3k6i5 / flashtext_replace_example.py
Created September 15, 2017 18:31
FlashText replace keyword example
from flashtext.keyword import KeywordProcessor
keyword_processor = KeywordProcessor()
keyword_processor.add_keyword('Big Apple', 'New York')
keyword_processor.add_keyword('New Delhi', 'NCR region')
new_sentence = keyword_processor.replace_keywords('I love Big Apple and new delhi.')
new_sentence
# 'I love New York and NCR region.'
@vi3k6i5
vi3k6i5 / flashtext_compare_regex.ipynb
Created September 5, 2017 20:04
Compare FlashText with Regex Example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vi3k6i5
vi3k6i5 / clean string.py
Created February 24, 2017 14:34
python code to clean text.
import re
import string
text_translator = str.maketrans({ord(c): " " for c in string.punctuation})
def clean_text(text, remove_punctuation_all=False):
if not text:
return ''
try:
text = text.replace(chr(160), " ")
text = ''.join([i if ord(i) < 128 else ' ' for i in text])
# part solution to http://stackoverflow.com/questions/41447277/trouble-using-pandas-read-html/41447560#41447560
max_value = [0,0]
for item in [(int(val.split('/')[0]), int(val.split('/')[1])) for val in df['Date Posted'].values]:
if item[0] > max_value[0]:
max_value[0] = item[0]
elif item[0] == max_value[0]:
if item[1] > max_value[1]:
max_value[1] = item[1]
max_date_posted = str(max_value[0]) + '/' + str(max_value[1])
@vi3k6i5
vi3k6i5 / program.py
Created December 19, 2016 12:40
sql_lite_db_update
# this is just to check db connection and sql commands from python.
# I know a better thing to do is to use django or SQLAlchemy to avoid sql injections. And that's what i do generally.
import sqlite3
conn = sqlite3.connect('example.db')
conn.execute('''CREATE TABLE COMPANY
(ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
from tkinter import*
class hunterClass:
def BMHunter(self):
hunter = Tk()
hunter.title("Beast Mastery Gear Worth Calculator")
agiString = StringVar()
import requests
import json
resp = requests.post('https://api.thingspeak.com/update.json',
data=json.dumps({"api_key":"XXXXXXXXXXXXXXXX",
"field1":73,
"field2":66}))