Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
paulNrad authored Aug 15, 2018
1 parent 133647a commit d132a81
Showing 1 changed file with 168 additions and 0 deletions.
168 changes: 168 additions & 0 deletions Day-3/NLP-5.1 noun or noun.ipynb
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
}

0 comments on commit d132a81

Please sign in to comment.