-
Notifications
You must be signed in to change notification settings - Fork 0
/
memeifywords.py
92 lines (88 loc) · 4.01 KB
/
memeifywords.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import sys
import json
import requests
import random
#get synynoms for the words in the sentence that are longer than three characters
def getVerbose(sentence):
phrase = sentence
yield phrase
for i in range(3):
phrase=getSyns(phrase,i+1)
yield phrase
def getUrban(sentence,iteration):
#Given a sentence, change things in the UD most popular list to their UD defs
words = sentence.split()
for i in range(len(words)):
if words[i] in open('list.txt').read():
phrase = words[i]
if len(phrase)>6-iteration:
it=1
while phrase in open('list.txt').read():
if i+it<len(words) and (phrase + words[i+it] in open('list.txt').read()):
phrase +=' ' + words[i+it]
it+=1
else:
break
if len(phrase.split()) > 0:
phrase.replace(' ','+')
response=requests.get("http://api.urbandictionary.com/v0/define?term="+phrase)
UD = response.json()
x = UD["list"][0]["definition"]
try:
return x.split('\r', 1)[0]
except:
try:
return x.split('\n',1)[0]
except:
return x
def getSyns(sentence, iteration):
end = ''
with open("adjAdvMod.json") as data_file:
data = json.load(data_file)
for word in sentence.split():
response = requests.get("http://words.bighugelabs.com/api/2/9a9636f5440c4799c19d84f0fd806c8d/"+word+"/json")
if len(word) < 6 - iteration :
end+=word+' '
else:
#lots of try shit to see if the word is a verb or a noun
try:
syns = response.json()
#limit is to keep the nyms from getting too weird
upperlimit=5*iteration
try:
if len(syns["noun"]["syn"])>len(syns["verb"]["syn"]):
if len(syns["noun"]['syn']) < upperlimit:
upperlimit = len(syns["noun"]['syn'])
end+=(random.choice(data["adj"]))+ ' ' + (random.choice(syns["noun"]['syn'][:upperlimit]))+' '
else:
if len(syns["verb"]['syn']) < upperlimit:
upperlimit = len(syns["verb"]['syn'])
end+=(random.choice(data["adv"]))+ ' ' + (random.choice(syns["verb"]['syn'][:upperlimit]))+' '
except:
try:
if len(syns["noun"]['syn']) < upperlimit:
upperlimit = len(syns["noun"]['syn'])
end+=(random.choice(data["adj"])) + ' '+ (random.choice(syns["noun"]['syn'][:upperlimit]))+' '
except:
try:
if len(syns["adjective"]['syn']) < upperlimit:
upperlimit = len(syns["adjective"]['syn'])
end+=(random.choice(syns["adjective"]['syn']))+' '
except:
try:
if len(syns["adverb"]['syn']) < upperlimit:
upperlimit = len(syns["adverb"]['syn'])
end+=(random.choice(syns["adverb"]['syn']))+' '
except:
if len(syns["verb"]['syn']) < upperlimit:
upperlimit = len(syns["verb"]['syn'])
end+=(random.choice(data["adv"])) +' '+ (random.choice(syns["verb"]['syn'][:upperlimit]))+' '
except:
end+=word+' '
#end = getUrban(end,iteration)
return end
if __name__ == "__main__":
#print(getUrban("a shiny vagoo"))
words = getVerbose(sys.argv[1])
for i in range(4):
print(next(words))