Language detection code in python
So we created a language detection program in python that just detects different languages. Our code looks great; there is no error but I am not getting the desired result. Whenever I run it on Eclipse, it starts and ends, giving us uptime and OK. It is supposed to print the text of the written text.
def compute_ratios(text):
tokens = wordpunct_tokenize(text)
words = [word.lower() for word in tokens]
langratios = {}
for language in stopwords.fileids():
stopwords_set = set(stopwords.words(language))
words_set = set (words)
common_elements = words_set.intersection(stopwords_set)
langratios[language] = len(common_elements)
return langratios
def max_ratio(text):
ratios = compute_ratios(text)
mostLang = max(ratios , key=ratios.get)
return mostLang
def main():
text = "This is cool"
x = max_ratio(text)
print(x)
+3
source to share