# -*- coding: utf-8 -*-
"""5_ Indian Language

Automatically generated by Colab.

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

a. word tokenization in Hindi
"""

###!pip install stanza
import stanza
stanza.download('hi')
nlp=stanza.Pipeline('hi',Processor='tokenize')
hindi_text="""इसे आज़माने के लए, नीचे अपनी भाषा और इनपुट उपकरण चुनं और लखना आरंभ
करं ."""
doc=nlp(hindi_text)
for sentence in doc.sentences:
    for word in sentence.words:
        print(word.text)

"""Generate similar sentences from a given Hindi

"""

###!pip install indic-nlp-library
from indicnlp.tokenize import indic_tokenize
text = "मुझे लकताब पढ़ना पसंद है"
synonyms = {
"लकताब": ["पुस्तक", "ग्रंथ"],
"पढ़ना": ["अध्ययन करना", "सीखना"],
"पसंद": ["अच्छा ि◌गता", " लय"]
}
tokens = indic_tokenize.trivial_tokenize(text)
similar_sentences = []
for word in tokens:
    if word in synonyms:
        for syn in synonyms[word]:
            new_tokens = tokens.copy()
            new_tokens[new_tokens.index(word)] = syn
            similar_sentences.append(" ".join(new_tokens))
print("Original:", text)
print("Similar\nSentences:")
for s in similar_sentences:
    print("-", s)

"""Identify the Indian language

"""

###!pip install langdetect
from langdetect import detect
text = """मुझे लकताब पढ़ना पसंद
है"""
language = detect(text)
print("Detected Language Code:", language)

"""ooooooooorrrrrrrrrrrrrrr

"""

###!pip install langid
import langid
text = "मुझे लकताब पढ़ना पसंद है"
lang_code, confidence = langid.classify(text)
languages = {
"hi": "Hindi",
"en": "English",
"mr": "Marathi",
"ta": "Tamil",
"te": "Telugu",
"bn": "Bengali",
"gu": "Gujarati",
"kn": "Kannada",
"ml": "Malayalam",
"pa": "Punjabi"
}
print("Language Code:", lang_code)
print("Full Name:", languages.get(lang_code, "Unknown"))
print("Confidence:", confidence)

