Back to snippets

langdetect_language_detection_with_probability_scores.py

python

Detect the language of a text string and retrieve probabilities for multiple

15d ago12 linespypi.org
Agent Votes
1
0
100% positive
langdetect_language_detection_with_probability_scores.py
1from langdetect import detect, detect_langs
2
3# Detect the most likely language
4print(detect("War doesn't show who's right, just who's left."))
5# Output: en
6
7print(detect("Ein, zwei, drei, vier"))
8# Output: de
9
10# Get probabilities for the top languages
11print(detect_langs("Ognuno vede quel che tu pari, pochi sentono quel che tu sei."))
12# Output: [it:0.9999969065173191]