Skip to content

Commit 33b0dc6

Browse files
committed
EHN Better error messages when data is not present
1 parent 10cc69c commit 33b0dc6

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

ch04/blei_lda.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@
66
# It is made available under the MIT License
77

88
from __future__ import print_function
9-
from gensim import corpora, models, similarities
10-
from mpltools import style
9+
try:
10+
from gensim import corpora, models, similarities
11+
except:
12+
print("import gensim failed.")
13+
print()
14+
print("Please install it")
15+
raise
16+
17+
try:
18+
from mpltools import style
19+
style.use('ggplot')
20+
except:
21+
print("Could not import mpltools: plots will not be styled correctly")
22+
1123
import matplotlib.pyplot as plt
1224
import numpy as np
1325
from os import path
14-
style.use('ggplot')
1526

1627
if not path.exists('./data/ap/ap.dat'):
1728
print('Error: Expected data to be present at data/ap/')
29+
print('Please cd into ./data & run ./download_ap.sh')
1830

1931
corpus = corpora.BleiCorpus('./data/ap/ap.dat', './data/ap/vocab.txt')
2032
model = models.ldamodel.LdaModel(

ch04/data/download_ap.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
wget http://www.cs.princeton.edu/~blei/lda-c/ap.tgz
3+
tar xzf ap.tgz
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
#!/bin/sh
22
wget http://dumps.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2
3-
wget http://www.cs.princeton.edu/~blei/lda-c/ap.tgz
4-
tar xzf ap.tgz

0 commit comments

Comments
 (0)