Skip to content

Commit fccb570

Browse files
author
Kyle Johnson
committed
add init from prev lecture
1 parent a4c4c32 commit fccb570

9 files changed

Lines changed: 2175 additions & 0 deletions

1 CLTK Setup.ipynb

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"deletable": true,
7+
"editable": true
8+
},
9+
"source": [
10+
"# Join the Slack channel\n",
11+
"\n",
12+
"Send your email to `kyle@kyle-p-johnson.com` and he'll add you to this channel. Other instructions will be sent via this route."
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {
18+
"deletable": true,
19+
"editable": true
20+
},
21+
"source": [
22+
"# Install Python\n",
23+
"\n",
24+
"## Mac\n",
25+
"\n",
26+
"<https://www.python.org/downloads/> (currently is 3.5.2)\n",
27+
"\n",
28+
"\n",
29+
"## Linux\n",
30+
"\n",
31+
"Open Terminal and check current version with `python --version` or `python3 --version`. If 3.4 or 3.5, you're fine. If Python version is out of date, run these:\n",
32+
"\n",
33+
"``` bash\n",
34+
"$ curl -O https://raw.githubusercontent.com/kylepjohnson/python3_bootstrap/master/install.sh\n",
35+
"\n",
36+
"$ chmod +x install.sh\n",
37+
"\n",
38+
"$ ./install.sh\n",
39+
"```\n",
40+
"\n",
41+
"This Linux build from source will take ~5 mins."
42+
]
43+
},
44+
{
45+
"cell_type": "markdown",
46+
"metadata": {
47+
"deletable": true,
48+
"editable": true
49+
},
50+
"source": [
51+
"# Install Git\n",
52+
"\n",
53+
"CLTK uses Git for corpus management. For Mac, install it from here: <https://git-scm.com/downloads>. For Linux, check if present (`git --version`); if not then use your package manager to get it (e.g., `apt-get install git`)."
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"metadata": {
59+
"deletable": true,
60+
"editable": true
61+
},
62+
"source": [
63+
"# Make virtual environment\n",
64+
"\n",
65+
"This makes a special environment (a \"sandbox\") just for the cltk. If something goes wrong, you can just delete it and start again.\n",
66+
"\n",
67+
"``` bash\n",
68+
"$ cd ~/\n",
69+
"$ mkdir cltk\n",
70+
"$ cd cltk\n",
71+
"$ pyvenv venv\n",
72+
"$ source venv/bin/activate\n",
73+
"```\n",
74+
"\n",
75+
"Now you can see that you're not using your system Python but this particular one:\n",
76+
"\n",
77+
"``` bash\n",
78+
"$ which python\n",
79+
"```\n",
80+
"\n",
81+
"Note that every time you open a new Terminal window, you'll need to \"activate\" this environment with `source ~/cltk/venv/bin/activate`."
82+
]
83+
},
84+
{
85+
"cell_type": "markdown",
86+
"metadata": {
87+
"deletable": true,
88+
"editable": true
89+
},
90+
"source": [
91+
"# Install CLTK\n",
92+
"\n",
93+
"``` bash\n",
94+
"$ pip install cltk\n",
95+
"```\n",
96+
"\n",
97+
"This will take a few minutes, as it will install several \"dependencies\", being other Python libraries which the CLTK uses.\n",
98+
"\n",
99+
"Also install Jupyter, which is a really handy way of writing code.\n",
100+
"\n",
101+
"``` bash\n",
102+
"$ pip install jupyter\n",
103+
"```"
104+
]
105+
},
106+
{
107+
"cell_type": "markdown",
108+
"metadata": {
109+
"deletable": true,
110+
"editable": true
111+
},
112+
"source": [
113+
"# Test Jupter\n",
114+
"\n",
115+
"Launch a notebook (such as this one) from the Terminal with `jupyter notebook`. Then open your preferred browser to <http://localhost:8888>."
116+
]
117+
},
118+
{
119+
"cell_type": "markdown",
120+
"metadata": {
121+
"deletable": true,
122+
"editable": true
123+
},
124+
"source": [
125+
"# Download these tutorials\n",
126+
"\n",
127+
"Now or sometime later, you may find these instructions at <https://github.com/kylepjohnson/notebooks/tree/master/public_talks/2016_12_08_harvard_classics>."
128+
]
129+
},
130+
{
131+
"cell_type": "markdown",
132+
"metadata": {
133+
"deletable": true,
134+
"editable": true
135+
},
136+
"source": [
137+
"# Join GitHub\n",
138+
"\n",
139+
"A nice way to share code. Do this later, then come visit us at <https://github.com/cltk/cltk/>."
140+
]
141+
}
142+
],
143+
"metadata": {
144+
"kernelspec": {
145+
"display_name": "Python 3",
146+
"language": "python",
147+
"name": "python3"
148+
},
149+
"language_info": {
150+
"codemirror_mode": {
151+
"name": "ipython",
152+
"version": 3
153+
},
154+
"file_extension": ".py",
155+
"mimetype": "text/x-python",
156+
"name": "python",
157+
"nbconvert_exporter": "python",
158+
"pygments_lexer": "ipython3",
159+
"version": "3.6.0"
160+
}
161+
},
162+
"nbformat": 4,
163+
"nbformat_minor": 1
164+
}

2 Import corpora.ipynb

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"deletable": true,
7+
"editable": true
8+
},
9+
"source": [
10+
"The CLTK has a distributed infrastructure that lets you download official CLTK texts or other corpora shared by others. For full docs, see <http://docs.cltk.org/en/latest/importing_corpora.html>.\n",
11+
"\n",
12+
"To get started, from the Terminal, open a new Jupyter notebook from within your `~/cltk` directory (see notebook 1 for instructions): `jupyter notebook`. Then go to <http://localhost:8888>."
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {
18+
"deletable": true,
19+
"editable": true
20+
},
21+
"source": [
22+
"# See what corpora are available\n",
23+
"\n",
24+
"First we need to \"import\" the right part of the CLTK library. Think of this as pulling just the book you need off the shelf and having it ready to read."
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 1,
30+
"metadata": {
31+
"collapsed": true,
32+
"deletable": true,
33+
"editable": true
34+
},
35+
"outputs": [],
36+
"source": [
37+
"# this is the import of the right part of the CLTK library\n",
38+
"from cltk.corpus.utils.importer import CorpusImporter"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 2,
44+
"metadata": {
45+
"collapsed": false,
46+
"deletable": true,
47+
"editable": true
48+
},
49+
"outputs": [],
50+
"source": [
51+
"# See https://github.com/cltk for all official corpora\n",
52+
"\n",
53+
"my_latin_downloader = CorpusImporter('latin')\n",
54+
"\n",
55+
"# 'my_latin_downloader' is the variable by which we now call the CorpusImporter"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 3,
61+
"metadata": {
62+
"collapsed": false,
63+
"deletable": true,
64+
"editable": true
65+
},
66+
"outputs": [
67+
{
68+
"data": {
69+
"text/plain": [
70+
"['latin_text_perseus',\n",
71+
" 'latin_treebank_perseus',\n",
72+
" 'latin_treebank_perseus',\n",
73+
" 'latin_text_latin_library',\n",
74+
" 'phi5',\n",
75+
" 'phi7',\n",
76+
" 'latin_proper_names_cltk',\n",
77+
" 'latin_models_cltk',\n",
78+
" 'latin_pos_lemmata_cltk',\n",
79+
" 'latin_treebank_index_thomisticus',\n",
80+
" 'latin_lexica_perseus',\n",
81+
" 'latin_training_set_sentence_cltk',\n",
82+
" 'latin_word2vec_cltk',\n",
83+
" 'latin_text_antique_digiliblt',\n",
84+
" 'latin_text_corpus_grammaticorum_latinorum']"
85+
]
86+
},
87+
"execution_count": 3,
88+
"metadata": {},
89+
"output_type": "execute_result"
90+
}
91+
],
92+
"source": [
93+
"my_latin_downloader.list_corpora"
94+
]
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"metadata": {
99+
"deletable": true,
100+
"editable": true
101+
},
102+
"source": [
103+
"# Import several corpora"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"execution_count": 4,
109+
"metadata": {
110+
"collapsed": true,
111+
"deletable": true,
112+
"editable": true
113+
},
114+
"outputs": [],
115+
"source": [
116+
"my_latin_downloader.import_corpus('latin_text_latin_library')\n",
117+
"my_latin_downloader.import_corpus('latin_models_cltk')"
118+
]
119+
},
120+
{
121+
"cell_type": "markdown",
122+
"metadata": {
123+
"deletable": true,
124+
"editable": true
125+
},
126+
"source": [
127+
"You can verify the files were downloaded in the Terminal with `$ ls -l ~/cltk_data/latin/text/latin_text_latin_library/`"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": 5,
133+
"metadata": {
134+
"collapsed": false,
135+
"deletable": true,
136+
"editable": true
137+
},
138+
"outputs": [
139+
{
140+
"data": {
141+
"text/plain": [
142+
"['greek_software_tlgu',\n",
143+
" 'greek_text_perseus',\n",
144+
" 'phi7',\n",
145+
" 'tlg',\n",
146+
" 'greek_proper_names_cltk',\n",
147+
" 'greek_models_cltk',\n",
148+
" 'greek_treebank_perseus',\n",
149+
" 'greek_lexica_perseus',\n",
150+
" 'greek_training_set_sentence_cltk',\n",
151+
" 'greek_word2vec_cltk',\n",
152+
" 'greek_text_lacus_curtius']"
153+
]
154+
},
155+
"execution_count": 5,
156+
"metadata": {},
157+
"output_type": "execute_result"
158+
}
159+
],
160+
"source": [
161+
"# Let's get a Greek corpus, too\n",
162+
"\n",
163+
"my_greek_downloader = CorpusImporter('greek')\n",
164+
"my_greek_downloader.list_corpora"
165+
]
166+
},
167+
{
168+
"cell_type": "code",
169+
"execution_count": 6,
170+
"metadata": {
171+
"collapsed": false,
172+
"deletable": true,
173+
"editable": true
174+
},
175+
"outputs": [],
176+
"source": [
177+
"my_greek_downloader.import_corpus('greek_text_lacus_curtius')"
178+
]
179+
},
180+
{
181+
"cell_type": "markdown",
182+
"metadata": {
183+
"deletable": true,
184+
"editable": true
185+
},
186+
"source": [
187+
"Likewise, verify with `ls -l ~/cltk_data/greek/text/greek_text_lacus_curtius/plain/`"
188+
]
189+
}
190+
],
191+
"metadata": {
192+
"kernelspec": {
193+
"display_name": "Python 3",
194+
"language": "python",
195+
"name": "python3"
196+
},
197+
"language_info": {
198+
"codemirror_mode": {
199+
"name": "ipython",
200+
"version": 3
201+
},
202+
"file_extension": ".py",
203+
"mimetype": "text/x-python",
204+
"name": "python",
205+
"nbconvert_exporter": "python",
206+
"pygments_lexer": "ipython3",
207+
"version": "3.6.0"
208+
}
209+
},
210+
"nbformat": 4,
211+
"nbformat_minor": 1
212+
}

0 commit comments

Comments
 (0)