# -*- coding: utf-8 -*-
"""2_b_c_tagged, noun

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1rpZCMhPuXRCAaHicEBwHrfQdWTtLqVi9
"""

import nltk
from nltk import tokenize

para = "in heaven. But what shall I do?"
sents = tokenize.sent_tokenize(para)
print("\nsentence tokenization\n\n",sents)
print("\nword tokenization\n\n")
for index in range(len(sents)):
    words = tokenize.word_tokenize(sents[index])
    print(words)

"""**Write a program to find the most frequent noun tags.
**
"""


import nltk
from collections import defaultdict

# Download required data
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
nltk.download('averaged_perceptron_tagger_eng')   # ⭐ FIX

# Tokenize
text = nltk.word_tokenize("Nick likes to play football. Nick does not like to play cricket.")

# POS tagging
tagged = nltk.pos_tag(text)
print(tagged)

# Extract nouns
addNounWords = []

for word, tag in tagged:
    if tag in ['NN', 'NNS', 'NNP', 'NNPS']:
        addNounWords.append(word)

print("Nouns:", addNounWords)

# Count frequency
temp = defaultdict(int)

for word in addNounWords:
    temp[word] += 1

# Max frequency
res = max(temp, key=temp.get)
print("Word with maximum frequency:", res)
