So, we have built a language detection program in python that just detects different languages. Our code seems fine; there is no error but I am not getting the desired result. Whenever I run it on Eclipse, it runs and terminates giving us the running time and an "OK". It is supposed to print the language of the text written.
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)
main?import pdb;pdb.set_trace()at the beginning of main. Step through the code to see if anything of interest comes up. You can usenextand one line functions while using pdb to inspect what is happening with the variables that are being passed.helpwhile in pdb to see the other commands.