# -*- coding: utf-8 -*-
"""
Created on Wed Dec 30 15:28:52 2020

@author: TNIKOLIC
"""
import streamlit as st
import nltk
from nltk.tokenize import word_tokenize
import seaborn as sns
from collections import Counter

def plot_parts_of_speach_barchart(text):
    nltk.download('averaged_perceptron_tagger')

    def _get_pos(text):
        pos=nltk.pos_tag(word_tokenize(text))
        pos=list(map(list,zip(*pos)))[1]
        return pos
    
    tags=text.apply(lambda x : _get_pos(x))
    tags=[x for l in tags for x in l]
    counter=Counter(tags)
    x,y=list(map(list,zip(*counter.most_common(7))))
    
    sns.barplot(x=y,y=x)
    
    st.pyplot()
    
    pos = set(tags)
    return pos
    

def plot_most_common_part_of_speech_barchart(text, part_of_speech):
    nltk.download('averaged_perceptron_tagger')
    
    def _filter_pos(text):
        pos_type=[]
        pos=nltk.pos_tag(word_tokenize(text))
        for word,tag in pos:
            if tag==part_of_speech:
                pos_type.append(word)
        return pos_type


    words=text.apply(lambda x : _filter_pos(x))
    words=[x for l in words for x in l]
    counter=Counter(words)
    x,y=list(map(list,zip(*counter.most_common(30))))
    sns.barplot(x=y,y=x).set_title(part_of_speech)
    
    st.pyplot()


# -*- coding: utf-8 -*-
"""
Created on Wed Dec 30 15:28:52 2020

@author: TNIKOLIC
"""
import streamlit as st
import nltk
from nltk.tokenize import word_tokenize
import seaborn as sns
from collections import Counter

def plot_parts_of_speach_barchart(text):
    nltk.download('averaged_perceptron_tagger')

    def _get_pos(text):
        pos=nltk.pos_tag(word_tokenize(text))
        pos=list(map(list,zip(*pos)))[1]
        return pos
    
    tags=text.apply(lambda x : _get_pos(x))
    tags=[x for l in tags for x in l]
    counter=Counter(tags)
    x,y=list(map(list,zip(*counter.most_common(7))))
    
    sns.barplot(x=y,y=x)
    
    st.pyplot()
    
    pos = set(tags)
    return pos
    

def plot_most_common_part_of_speech_barchart(text, part_of_speech):
    nltk.download('averaged_perceptron_tagger')
    
    def _filter_pos(text):
        pos_type=[]
        pos=nltk.pos_tag(word_tokenize(text))
        for word,tag in pos:
            if tag==part_of_speech:
                pos_type.append(word)
        return pos_type


    words=text.apply(lambda x : _filter_pos(x))
    words=[x for l in words for x in l]
    counter=Counter(words)
    x,y=list(map(list,zip(*counter.most_common(30))))
    sns.barplot(x=y,y=x).set_title(part_of_speech)
    
    st.pyplot()


# -*- coding: utf-8 -*- Created on Wed Dec 30 15:28:52 2020  @author: TNIKOLIC