import nltk

print( nltk.corpus.udhr.raw('English-Latin1'))

"""
Explanation: Introduction to the languages we chose for our purpose
Our Text Corpus
Universal Declaration of Human Rights
English
End of explanation
"""


import nltk

print( nltk.corpus.udhr.raw('Esperanto-UTF8'))

"""
Explanation: Esperanto
End of explanation
"""


import os
os.getcwd()

from IPython.display import Image
from IPython.core.display import HTML 

PATH = "C:\\Users\\user\\Desktop\\Language Space and Mind"
Image(filename = PATH + "\\canvas.png", width=1000, height=500)


list_of_languages = [


['English', ['English-Latin1'] ]
,['Esperanto', ['Esperanto-UTF8']],
['German', ['German_Deutsch-Latin1']]
,['French', ['French_Francais-Latin1']]
,['Russian', ['Russian-UTF8','Russian_Russky-Cyrillic','Russian_Russky-UTF8']]
,['Farsi', ['Farsi_Persian-UTF8', 'Farsi_Persian-v2-UTF8']]
,['Finnish',['Finnish_Suomi-Latin1']]
,['Hungarian',['Hungarian_Magyar-Latin1','Hungarian_Magyar-Latin2','Hungarian_Magyar-UTF8']]
,['Turkish', ['Turkish_Turkce-Turkish','Turkish_Turkce-UTF8']]
,['Mongolian', ['Mongolian_Khalkha-Cyrillic','Mongolian_Khalkha-UTF8']]
,['Chinese',['Chinese_Mandarin-GB2312']]
,['Japanese',['Japanese_Nihongo-EUC','Japanese_Nihongo-SJIS','Japanese_Nihongo-UTF8']]
,['Korean',['Korean_Hankuko-UTF8']]
,['Hebrew',['Hebrew_Ivrit-Hebrew','Hebrew_Ivrit-UTF8']]
,['Hindi',['Hindi-UTF8','Hindi_web-UTF8']]
,['Kazakh',['Kazakh-Cyrillic','Kazakh-UTF8']]
,['Swedish',['Swedish_Svenska-Latin1']]
,['Icelandic' ,['Icelandic_Yslenska-Latin1']]
,['Sanskrit ' ,['Sanskrit-UTF8']]
,['Latin',['Latin_Latina-Latin1', 'Latin_Latina-v2-Latin1']]
,['Greek', ['Greek_Ellinika-Greek', 'Greek_Ellinika-UTF8']]
,['Swahili', ['Swaheli-Latin1','Swahili_Kiswahili-Latin1']]


]





"""
Explanation: Here, Give a brief overview of Esperanto
Similarly we chose the UDHR in all the languages ( 22 in number ) shown in the following world map.
End of explanation
"""


import nltk

for i in range(len(list_of_languages)):
    
    print('\x1b[1;34m'+list_of_languages[i][0] +'\x1b[0m')
    print("\n\n")

    print(nltk.corpus.udhr.raw(list_of_languages[i][1]))

    
    print("\n\n\n\n\n\n\n")


"""
Explanation: Print the UDHR from each language
End of explanation
"""



import nltk

for i in range(len(list_of_languages)):
    print(list_of_languages[i][0])
    words = nltk.pos_tag(nltk.corpus.udhr.words(list_of_languages[i][1][0]))

    words_types = []
    for i in range(len(words)):
        words_types.append(words[i][1])
    
    print(set(words_types))

    print("\n\n\n\n\n\n\n")


"""
Explanation: The Parts of Speech Tagging in these languages
End of explanation
"""



import nltk

## now count the POS in each language
num_pos = []

for i in range(len(list_of_languages)):
    print(list_of_languages[i][0])
    words = nltk.pos_tag(nltk.corpus.udhr.words(list_of_languages[i][1][0]))

    words_types = []
    for i in range(len(words)):
        words_types.append(words[i][1])
    
    print(set(words_types))
    num_pos.append(len(set(words_types)))
    print("\n\n\n\n\n\n\n")


num_pos

len(num_pos)

len(list_of_languages)

len(words_types)

len(set(words_types))

np.arange(len(set(words_types)))

"""
Explanation: Now we plot the graph as per the number of distinct elements in the POS set
End of explanation
"""


import numpy as np
import matplotlib.pyplot as plt

plt.style.use('bmh')
%matplotlib inline 

fig_size = plt.rcParams["figure.figsize"]
fig_size[0] = 14
fig_size[1] = 9
plt.rcParams["figure.figsize"] = fig_size



lang_names=[]
for i in range(len(list_of_languages)):
    lang_names.append((list_of_languages[i][0]))

"""
Explanation: Plot styling
End of explanation
"""



import matplotlib.pyplot as plt
#plt.rcdefaults()
import numpy as np

plt.style.use('bmh')

# Example data
#people = set(words_types)

x_pos = np.arange(len(list_of_languages))

plt.bar(x_pos, num_pos,  color='r', align='center', alpha=0.4)

plt.xticks(x_pos,lang_names  ,  rotation=45 )

#plt.xlabel('Performance')
#plt.title('How fast do you want to go today?')

plt.show()


"""
Explanation: Here we plot the list of POS per language.
End of explanation
"""



import matplotlib.pyplot as plt
#plt.rcdefaults()
import numpy as np

plt.style.use('bmh')

# Example data
#people = set(words_types)

x_pos = np.arange(len(list_of_languages))

barlist= plt.bar(x_pos, num_pos,  color='r', align='center', alpha=0.4)

for i in range(len(barlist)):
    if barlist[i].get_height() >=15:
        barlist[i].set_color('b')

plt.xticks(x_pos,lang_names  ,  rotation=45 )

#plt.xlabel('Performance')
#plt.title('How fast do you want to go today?')

plt.show()


"""
Explanation: Clearly, the POS taggers in the basic library are not all of the same quality.
End of explanation
"""


text = '''
Longe/RB vivadis/VBD en/IN paco/NNS tiu/DT gento/NNS trankvila,/JJ de/IN Kristanismo/NNS netusita/JJ gis/IN
dek-tria/dek-tria jarcento./NNS De/IN la/DT cetera/JJ mondo/NNS forkasita/JJ per/IN marcoj/NNP kaj/CC densaj/JJ
arbaregoj,/NNP kie/RB kuras/VBP gis/IN nun/VB sovagaj/JJ urbovoj,/NNP la/DT popolo/NNS dauris/VBD adori/ii la/DT
fortojn/NNP de/IN la/DT naturo/NNS sub/IN gigantaj/JJ kverkoj,/NNP vivanta/JJ templo/NNS de/IN la/DT dioj./NNP

Tie/RB tamen/RB ekbatalis/VBD okcidenta/JJ volo/NNS kun/IN orienta/JJ pacienco./NNS En/IN la/DT mezepoko/NNS
teutonaj/JJ kavaliroj/NNP tiun/DT landon/NNS almilitis,/VBD polaj/JJ nobeloj/NNP gin/PRP ligis/VBD al/IN sia/PRP$
stato,/NNS moskova/JJ caro/NNS gin/PRP atakis./VBD Dume/RB alkuradis/VBD el/IN tuta/JJ mondo/NNS
persekutataj/JJ Hebreoj/NNP por/IN starigi/ii manlaboron/NNS kaj/CC komercon/NNS lau/IN invito/NNS
rega./JJ Tiel/RB alia/JJ gento/NNS tre/RB maljuna/JJ trovis/VBD tie/RB novan/JJ Palestinon/NNS kaj/CC fondis/VBD
urbojn/NNP au/CC plenigis/VBD ilin./PRP'''

[nltk.tag.str2tuple(t) for t in text.split()]

"""
Explanation: For moving towards a better application of Category Theory onto the Esperanto language, we used a pre-tagged corpus for this purpose.
Here is a sample of the pre-tagged data.
We relied upon the regular structure of the language to form the requisite Regular-Expressions for this purpose.
End of explanation
"""


