"[(sentence, category) for category in sentence_polarity.categories() for sentence in sentence_polarity.sents(categories=category)]"
],
"metadata": {
"id": "mt1QgVClSEjA"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from nltk.corpus import wordnet\n",
"sysns = wordnet.synsets('dog')\n",
"sysns"
],
"metadata": {
"id": "IjSHEZScSQCF"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title\n",
"sysns[0].definition()"
],
"metadata": {
"id": "GgvX-BgHS81L"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"sysns[0].examples()"
],
"metadata": {
"id": "AT_3oaaHVLC1"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"sysns[0].lemmas()"
],
"metadata": {
"id": "kmk7qIobVMal"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"sysns[0].hypernyms()"
],
"metadata": {
"id": "oETa7kbkVOa_"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"dog = wordnet.synset('dog.n.01')\n",
"cat = wordnet.synset('cat.n.01')\n",
"dog.path_similarity(cat)"
],
"metadata": {
"id": "pIfiuH0oVQxC"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"dog.wup_similarity(cat)"
],
"metadata": {
"id": "SemuS9s9Vduy"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from nltk.corpus import sentiwordnet as swn\n",
"good = swn.senti_synsets('good', 'n')\n",
"\n",
"posscore=0\n",
"negscore=0\n",
"for synst in good:\n",
"\n",
" posscore=posscore+synst.pos_score()\n",
" negscore=negscore+synst.neg_score()\n",
"\n",
"\n",
"print(posscore)\n",
"print(negscore)"
],
"metadata": {
"id": "dngeFrS0VfvW"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from nltk.tokenize import sent_tokenize\n",
"text = gutenberg.raw('austen-emma.txt')\n",
"sents = sent_tokenize(text)\n",
"sents[100]"
],
"metadata": {
"id": "kfJJGbH-Vqrg"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from nltk.tokenize import word_tokenize\n",
"words = word_tokenize(sents[100])\n",
"words"
],
"metadata": {
"id": "T36no6nTYO1P"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from nltk import pos_tag\n",
"pos_tag(words)"
],
"metadata": {
"id": "G5WXfMZVYZq5"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# NER & # Chunking for nltk\n",
"from nltk.tokenize import word_tokenize\n",
"from nltk.tag import pos_tag\n",
"\n",
"ex = 'European authorities fined Google a record $5.1 billion on Wednesday for abusing its power in the mobile phone market and ordered the company to alter its practices'\n",