nlp-lab/simple_test.ipynb

173 lines
3.0 KiB
Plaintext
Raw Normal View History

2018-04-24 15:30:59 +02:00
{
"cells": [
{
"cell_type": "code",
2018-04-29 18:37:21 +02:00
"execution_count": 1,
"metadata": {
"collapsed": true
},
2018-04-24 15:30:59 +02:00
"outputs": [],
"source": [
"import nltk"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* download nltk data:"
]
},
{
"cell_type": "code",
2018-04-29 18:37:21 +02:00
"execution_count": 2,
2018-04-24 15:30:59 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2018-04-29 18:37:21 +02:00
"[nltk_data] Downloading package punkt to /Users/Carsten/nltk_data...\n",
"[nltk_data] Unzipping tokenizers/punkt.zip.\n"
2018-04-24 15:30:59 +02:00
]
},
{
"data": {
"text/plain": [
"True"
]
},
2018-04-29 18:37:21 +02:00
"execution_count": 2,
2018-04-24 15:30:59 +02:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nltk.download('punkt')"
]
},
{
"cell_type": "code",
2018-04-29 18:37:21 +02:00
"execution_count": 3,
2018-04-24 15:30:59 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[nltk_data] Downloading package averaged_perceptron_tagger to\n",
2018-04-29 18:37:21 +02:00
"[nltk_data] /Users/Carsten/nltk_data...\n",
"[nltk_data] Unzipping taggers/averaged_perceptron_tagger.zip.\n"
2018-04-24 15:30:59 +02:00
]
},
{
"data": {
"text/plain": [
"True"
]
},
2018-04-29 18:37:21 +02:00
"execution_count": 3,
2018-04-24 15:30:59 +02:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nltk.download('averaged_perceptron_tagger')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* simple example"
]
},
{
"cell_type": "code",
2018-04-29 18:37:21 +02:00
"execution_count": 4,
"metadata": {
"collapsed": true
},
2018-04-24 15:30:59 +02:00
"outputs": [],
"source": [
"sentence = \"This is a test sentence.\""
]
},
{
"cell_type": "code",
2018-04-29 18:37:21 +02:00
"execution_count": 5,
2018-04-24 15:30:59 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['This', 'is', 'a', 'test', 'sentence', '.']"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tokens = nltk.word_tokenize(sentence)\n",
"display(tokens)"
]
},
{
"cell_type": "code",
2018-04-29 18:37:21 +02:00
"execution_count": 6,
2018-04-24 15:30:59 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('This', 'DT'),\n",
" ('is', 'VBZ'),\n",
" ('a', 'DT'),\n",
" ('test', 'NN'),\n",
" ('sentence', 'NN'),\n",
" ('.', '.')]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"taggers = nltk.pos_tag(tokens)\n",
"display(taggers)"
]
},
{
"cell_type": "code",
"execution_count": null,
2018-04-29 18:37:21 +02:00
"metadata": {
"collapsed": true
},
2018-04-24 15:30:59 +02:00
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}