Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions topicexplorer/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ def contains_pattern(directory, pattern):
return True
except StopIteration:
return False

def filter_until(predicate, n, ls):
ls = list(ls)
while n > 0 and ls:
item = ls.pop(0)
if predicate(item):
yield item
n -= 1

16 changes: 14 additions & 2 deletions topicexplorer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

from bottle import request, response, route, run, static_file
from topicexplorer.lib.ssl import SSLWSGIRefServer
from topicexplorer.lib.util import filter_until
import numpy as np

import pystache
import topicexplorer.lib.color as colorlib


stopwords = None
def _set_acao_headers(f):
"""
Decorator to set Access-Control-Allow-Origin headers to enable cross-InPhO
Expand Down Expand Up @@ -202,7 +205,11 @@ def topics():
# populate word values
data = lda_v.topics()
for i,topic in enumerate(data):
js[str(i)].update({'words' : dict([(w, p) for w,p in topic[:10]])})
if stopwords:
js[str(i)].update({'words' : dict([(w, p) for w,p in
filter_until(lambda w_p: w_p[0] not in stopwords, 20, topic)])})
else:
js[str(i)].update({'words' : dict([(w, p) for w,p in topic[:20]])})

return json.dumps(js)

Expand Down Expand Up @@ -265,7 +272,12 @@ def get_docs(docs=None, id_as_key=False, query=None):

def main(args):
global context_type, lda_c, lda_m, lda_v, label, id_fn

global stopwords
with open('../corpus.stopwords') as swfile:
stopwords = []
for line in swfile:
stopwords.append(line.strip())

# load in the configuration file
config = ConfigParser({
'certfile' : None,
Expand Down