-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAcronymizer.py
executable file
·144 lines (122 loc) · 4.12 KB
/
Acronymizer.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
from sys import argv
import json
from random import shuffle
import os
import pdb
import db
from subprocess import check_output
import whiptail
''' Input:
first argument
sbsequent arguments: the dictionary
./Acronymizer.py $1 $(cat acronym/links/$1)'''
def get_relephant(wikiword):
word_links = db.db_query('''
SELECT wl.link
FROM word_links wl
INNER JOIN word w ON wl.word_id = w.id
WHERE w.word = ?
''', wikiword)
relephant = []
for word_link in word_links:
relephant.append(word_link["link"])
return relephant
def acronymize(wikiword, relephant):
''' I accept a word and a list of related words and return
a relevant acronym of the word using only related words'''
wikiword = wikiword.replace('_', ' ')
acronym = []
def initialyze(singleletter, relephant):
if len(singleletter) != 1: return "only one letter plz"
if singleletter.isspace(): return " "
if singleletter == '_': return " "
shuffle(relephant)
for each in relephant:
if each[0].capitalize() == singleletter.capitalize():
return each
return "##QWANTZ no match; increase relephant pool" # singleletter
for eachletter in wikiword:
#pdb.set_trace()
acronym.append(initialyze(eachletter, relephant))
return acronym
def get_choice_with_whiptail(word, acronym_words, relephant):
#pdb.set_trace()
# print('acronym_words')
# for acronym_word in acronym_words: print(acronym_word)
while ' ' in acronym_words: acronym_words.remove(' ')
word = word.replace(' ', '')
for each in enumerate(acronym_words):
if each[1].isspace(): acronym_words[each[0]] = ('');
else: acronym_words[each[0]] = str(each[0]) + " " + word[each[0]] + " " + each[1]
thechoice = whiptail.Whiptail()
thechoice.title = word
thechoice.backtitle = 'inasra'
possible_choices = acronym_words
possible_choices.append('respin')
choice_word, exitstatus = thechoice.menu('choose your path', possible_choices,'-')
if exitstatus == '1':
return -1
if choice_word == "respin":
# input("respinnin'")
return get_choice_with_whiptail(word, acronym_words, relephant)
#input("you said " + choice_word.split(' ')[-1])
#input(choice_word.split(' ')[0])
choice_pos = int(choice_word.split(' ')[0])
return choice_pos
def do_acronomize(wikiterm):
relephants = db.db_query('''
SELECT wl.link
FROM word_links wl
INNER JOIN word w ON wl.word_id = w.id
WHERE w.word = ?
''', wikiterm)
wordclean = wikiterm.replace('_', ' ')
# relephant_words = [relephant_words for relephant in relephants]
relephant_words = [r.link for r in relephants]
# relephant_words = []
# for relephant in relephants:
# relephant_words.append(relephant.link)
# acronymize(wordclean, acronym, relephant)
return acronymize(wordclean, relephants)
def main():
'''this bit allows us to handle either a word or a path'''
if len(argv) != 2: word = " ".join(argv)
else:
word = argv[1]
print(argv[1] + '\n')
if "/" in word: word = word.split('/')[-1]
related_words = do_acronomize(word)
# '''this is where we pull from the sqlite3 db if it exists'''
# maybe?
# word = word.replace('_', ' ')
#
# relephant = db.db_query('''
# SELECT wl.link
# FROM word_links wl
# INNER JOIN word w ON wl.word_id = w.id
# WHERE w.word = ?
# ''', word)
#
# # word = word.replace('_', ' ')
# # word = word.replace('_', ' ')
#
# related_words = acronymize(word, db.db_query('''
# SELECT wl.link
# FROM word_links wl
# INNER JOIN word w ON wl.word_id = w.id
# WHERE w.word = ?
# ''', relephant[0].)) # relephant here?
# FIXME: the 2nd related_words needs to a relephant
# respin will be broken until this is fixed
choice_pos = get_choice_with_whiptail(word, related_words, related_words)
# word = word.replace('_', ' ')
# acronym = acronymize(word, relephant)
#choice_pos = get_choice_with_whiptail(word, related_words, relephant)
#choice_word = acronym[choice_pos].split(' ')[-1]
#input("my choice word is: " + choice_word)
#print(relephant)
record_acronym_choice(word, choice_pos, choice_word, argv[1])
#pdb.set_trace()
os.system('./recursive_spine_builder.sh ' + argv[1] +'/'+ choice_word.replace(' ','_').split('/')[-1])
if __name__ == "__main__": main()