Skip to content

Instantly share code, notes, and snippets.

@tomblench
Created March 28, 2014 10:48
Show Gist options
  • Save tomblench/9829989 to your computer and use it in GitHub Desktop.
Save tomblench/9829989 to your computer and use it in GitHub Desktop.
import re
import string
pronMap = {"i": "you",
"you": "you",
"they": "they",
"we": "you",
"he": "he",
"she": "she",
"it": "it"};
def couldShould(sentence) :
# (could should would won't can't)
m = re.search("(I|you|they|we|he|she|it)\s+(could|should|would|won't|will not|can't|cannot|can not)(\s+have|'ve)\s+([^-.;,]*)", sentence, re.I);
if (m) :
return (pronMap[string.lower(m.group(1))] + " " + m.group(2) + " of " + m.group(4) + "!");
return None
# testing...
print(couldShould("I should have done the shopping; but i forgot"));
print(couldShould("i should have done the shopping; but i forgot"));
print(couldShould("I should have done the shopping"));
print(couldShould("it should have been fixed - but it wasn't"));
print(couldShould("I should asd done the shopping"));
print(couldShould("we should have gone to the park...but it's raining"));
print(couldShould("we could've gone to the park...but it's raining"));
print(couldShould("she won't have heard of the new json datastore"));
print(couldShould("she won't've heard of the new json datastore"));
print(couldShould("she will not have heard of the new json datastore"));
bash-3.2$ python ~/couldshould.py
you should of done the shopping!
you should of done the shopping!
you should of done the shopping!
it should of been fixed !
None
you should of gone to the park!
you could of gone to the park!
she won't of heard of the new json datastore!
she won't of heard of the new json datastore!
she will not of heard of the new json datastore!
bash-3.2$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment