-
Notifications
You must be signed in to change notification settings - Fork 3
/
__init__.py
255 lines (215 loc) · 5.75 KB
/
__init__.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# coding=utf-8
import os
import json
import sys
from flask import Flask, url_for, redirect, render_template, send_from_directory
import Utilities
import CorpusViewer
import TextViewer
import RankViewer
from Support.flask_util_js.flask_util_js import FlaskUtilJs
from config import DevelopmentConfig
runSentry = False
try:
from raven.contrib.flask import Sentry
sentryInstalled = True
except:
print 'Raven not installed--Sentry will not be run.'
sentryInstalled = False
#########################
#### Flask App Setup ####
#########################
app = Flask(__name__)
# Load some sweet Jinja2 extensions
app.jinja_options = dict(
extensions=[
'jinja2.ext.do',
'jinja2.ext.autoescape'
]
)
# Load the configuration object.
#app.config.from_object("config.DevelopmentConfig")
app.config.from_object(DevelopmentConfig)
# For flask_util.url_for() in JavaScript: https://github.com/dantezhu/flask_util_js
fujs = FlaskUtilJs(app)
# Sentry
if runSentry and sentryInstalled:
try:
app.config['SENTRY_DSN'] = 'https://d3db637793f0492cbd5c8b7a65ca14ba:[email protected]/78772'
sentry = Sentry(app)
except RuntimeError as err:
print 'Error trying to run Sentry:', err
def get_colors():
colors_str_prefix = "app_colors = "
colors_path = os.path.join(
app.static_folder,
"js",
"app_colors.json"
)
colors_file = open(colors_path, "rU")
colors_str = colors_file.read()
colors_file.close()
if colors_str.startswith(colors_str_prefix):
colors_str = colors_str[len(colors_str_prefix):]
colors = json.loads(colors_str)
return colors
# Add the colors to the app configuration.
app.config.update(
COLORS=get_colors()
)
########################################
# Index Redirection to CorpusViewer ####
########################################
@app.route("/")
def index():
return redirect(
url_for(
"cv_view_by_name",
model_name=app.config["DEFAULT_MODEL_NAME"]
)
)
############################################
# TESTING CODE FOR BIG THETA AND OTHERS ####
############################################
@app.route('/bigThetaTest')
def bigThetaTest():
return render_template(
'BigThetaTest.html'
)
######################
#### CorpusViewer ####
######################
# Redirect to matrix view for "/model:<model_name>/"
@app.route('/model:<path:model_name>/')
def redirect_corpus_view(model_name):
return redirect(
url_for(
"cv_view_by_name",
model_name=model_name
)
)
app.add_url_rule(
'/model:<path:model_name>/matrix',
"cv_view_by_name",
CorpusViewer.view_by_name
)
app.add_url_rule(
'/model:<path:model_name>/_getMetadata',
"cv_get_metadata",
CorpusViewer.get_metadata
)
app.add_url_rule(
'/model:<path:model_name>/_getTheta',
"cv_get_theta",
CorpusViewer.get_theta
)
app.add_url_rule(
'/model:<path:model_name>/_setGroupName/<group_file>/<group_name>/<group>',
"cv_set_group_name",
CorpusViewer.set_group_name
)
app.add_url_rule(
'/model:<path:model_name>/_getGroups/<group_file>',
"cv_get_groups",
CorpusViewer.get_groups
)
app.add_url_rule(
'/model:<path:model_name>/_getAnovaOrder/<fieldName>',
"cv_get_anova_order",
CorpusViewer.getAnovaOrder
)
app.add_url_rule(
'/model:<path:model_name>/_getContrastOrder/<fieldName>/<group1>/<group2>',
"cv_get_contrast_order",
CorpusViewer.getContrastOrder
)
####################
#### TextViewer ####
####################
app.add_url_rule(
'/slimTV/',
'tv_single_view_by_name/',
TextViewer.single_view_by_name
)
app.add_url_rule(
'/slimTV/tokens_url:<path:tokens_url>',
'tv_single_fromURL_view_by_name/',
TextViewer.single_fromURL_view_by_name
)
app.add_url_rule(
'/slimTV/model:<path:model_name>/text:<text_name>/',
'tv_view_by_name',
TextViewer.view_by_name
)
app.add_url_rule(
'/_getTokens/model:<path:model_name>/text:<text_name>/',
'tv_get_tokens_json',
TextViewer.get_tokens_json
)
###################
#### Utilities ####
###################
app.add_url_rule(
'/model:<path:model_name>/_getTopic/<topic_num>/<num_words>/<ranking_type>',
"utils_get_topic",
Utilities.get_topic
)
app.add_url_rule(
'/model:<path:model_name>/_getTopicNames/',
"utils_get_topic_names",
Utilities.get_topic_names
)
app.add_url_rule(
'/model:<path:model_name>/_setTopicName/<topic_num>/<topic_name>/<num_topics>',
"utils_set_topic_name",
Utilities.set_topic_name
)
app.add_url_rule(
'/model:<path:model_name>/_getRankingTypes',
"utils_get_ranking_types",
Utilities.get_ranking_types
)
#######################################
#### EXTRA (WORDRANKINGS AND SUCH) ####
#######################################
'''
app.add_url_rule(
'/model:<path:model_name>/meso',
"cv_mesoview",
CorpusViewer.mesoview
)
app.add_url_rule(
'/_getCorpora',
"get_corpora",
Utilities.get_corpora
)
'''
app.add_url_rule(
'/model:<path:model_name>/_get_word_rankings/<rankingType>/<words>',
'get_word_rankings_json',
RankViewer.get_word_rankings_json
)
app.add_url_rule(
'/model:<path:model_name>/wordRankings/<rankingType>/<wordColorPairs>',
'wordRankings',
RankViewer.wordRankings
)
app.add_url_rule(
'/model:<path:model_name>/wordRankings/',
'wordRankingsDefault',
RankViewer.wordRankingsDefault
)
app.add_url_rule(
'/model:<model_name>/get_word_ranking/<rankingType>/<word>',
'get_word_ranking',
RankViewer.get_word_ranking
)
#################
#### Run it! ####
#################
if __name__ == '__main__':
if len(sys.argv) > 1:
app.config.update(
METADATA_ROOT=sys.argv[1]
)
app.run(port=5001)