Skip to content

Commit

Permalink
Merge branch 'testing' of https://github.com/DARIAH-DE/Topics into te…
Browse files Browse the repository at this point in the history
…sting
  • Loading branch information
pielstroem committed Feb 21, 2017
2 parents f8c1f49 + 040c632 commit f6c1d52
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions demonstrator/demonstrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"""

from dariah_topics import preprocessing
from dariahs_topics import visualization
from dariahs_topics import mallet
from dariah_topics import visualization
from dariah_topics import mallet
from flask import Flask, request, render_template, send_file
from gensim.models import LdaModel
from gensim.corpora import MmCorpus
Expand Down Expand Up @@ -70,9 +70,10 @@ def upload_file():
print("Creating MALLET binary ...")
mallet.create_mallet_model("./mallet_output", "./tmp_files", './mallet/bin/mallet')
print("Training MALLET LDA model ...")
mallet.create_mallet_output('./mallet_output/malletModel.mallet', './mallet_output', './mallet/bin/mallet')
num_topics = str(request.form['number_topics'])
mallet.create_mallet_output('./mallet_output/malletModel.mallet', './mallet_output', './mallet/bin/mallet', num_topics=num_topics)
shutil.rmtree('./tmp_files')
df = mallet.show_topics_keys('./mallet_output')
df = mallet.show_topics_keys('./mallet_output', topic_num=int(num_topics))
doc_topic = mallet.show_docTopicMatrix('./mallet_output')
heatmap = visualization.doc_topic_heatmap(doc_topic)
heatmap.savefig('./static/heatmap.png')
Expand Down Expand Up @@ -127,11 +128,6 @@ def upload_file():
# Todo: replace by DataFrame.to_html():
print("Accessing topics for HTML table ...")
df = visualization.topicwords_in_df(model)
import regex
pattern = regex.compile(r'\p{L}+\p{P}?\p{L}+')
topics = []
for n, topic in enumerate(model.show_topics()):
topics.append((n+1, pattern.findall(topic[1])))
print("Rendering result.html ...")

return render_template('result.html', tables=[df.to_html(classes='df')])
Expand Down

0 comments on commit f6c1d52

Please sign in to comment.