Skip to content

Instantly share code, notes, and snippets.

View yamanahlawat's full-sized avatar
:shipit:

Yaman Ahlawat yamanahlawat

:shipit:
View GitHub Profile
@yamanahlawat
yamanahlawat / repeating_characters_replacer.py
Last active January 25, 2017 13:21
Remove repeating characters from a word using regular expressions and nltk wordnet
import re
from nltk.corpus import wordnet
class RepeatReplacer(object):
def __init__(self):
self.repeat_regexp = re.compile(r'(\w*)(\w)\2(\w*)')
self.repl = r'\1\2\3'
def replace(self, word):
@yamanahlawat
yamanahlawat / replacers.py
Created January 25, 2017 12:17
Using Regular Expressions to expand contractions of a Word
import re
replacement_patterns = [
(r'won\'t', 'will not'),
(r'can\'t', 'cannot'),
(r'i\'m', 'i am'),
(r'ain\'t', 'is not'),
(r'(\w+)\'ll', '\g<1> will'),
(r'(\w+)n\'t', '\g<1> not'),
(r'(\w+)\'ve', '\g<1> have'),