forked from utsabigdata/AI-Workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Finding all the cases in a given text where there is a 'or' betwen two \"NOUN\"." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import nltk" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 17, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"['[',\n", | ||
" 'Stories',\n", | ||
" 'to',\n", | ||
" 'Tell',\n", | ||
" 'to',\n", | ||
" 'Children',\n", | ||
" 'by',\n", | ||
" 'Sara',\n", | ||
" 'Cone',\n", | ||
" 'Bryant',\n", | ||
" '1918',\n", | ||
" ']',\n", | ||
" 'TWO',\n", | ||
" 'LITTLE',\n", | ||
" 'RIDDLES',\n", | ||
" 'IN',\n", | ||
" 'RHYME',\n", | ||
" 'There',\n", | ||
" \"'\",\n", | ||
" 's']" | ||
] | ||
}, | ||
"execution_count": 17, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"stories = nltk.corpus.gutenberg.words(\"bryant-stories.txt\")\n", | ||
"stories[:20]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"tags = nltk.pos_tag(stories, tagset=\"universal\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[('[', 'NOUN'),\n", | ||
" ('Stories', 'NOUN'),\n", | ||
" ('to', 'PRT'),\n", | ||
" ('Tell', 'VERB'),\n", | ||
" ('to', 'PRT'),\n", | ||
" ('Children', 'NOUN'),\n", | ||
" ('by', 'ADP'),\n", | ||
" ('Sara', 'NOUN'),\n", | ||
" ('Cone', 'NOUN'),\n", | ||
" ('Bryant', 'NOUN'),\n", | ||
" ('1918', 'NUM'),\n", | ||
" (']', 'NOUN'),\n", | ||
" ('TWO', 'NOUN'),\n", | ||
" ('LITTLE', 'NOUN'),\n", | ||
" ('RIDDLES', 'NOUN'),\n", | ||
" ('IN', 'NOUN'),\n", | ||
" ('RHYME', 'NOUN'),\n", | ||
" ('There', 'DET'),\n", | ||
" (\"'\", '.'),\n", | ||
" ('s', 'VERB')]" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"tags[:20]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 27, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#for item in nltk.trigrams(tags):\n", | ||
"# print(item)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 29, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"ship or part\n", | ||
"food or water\n", | ||
"queens or princesses\n", | ||
"rank or wealth\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for ((word1,tag1),(word2,tag2),(word3,tag3)) in nltk.trigrams(tags):\n", | ||
" if tag1 == \"NOUN\" and word2 == \"or\" and tag3 == \"NOUN\":\n", | ||
" print(word1 + \" \" + word2 + \" \" + word3)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"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.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |