Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import NaturalLanguage
let string1 = """
Hello world, I love machine learning and I work as a Data Scientist in India.
機械学習で働くのが好き
"""
let string2 = " أحب العمل في التعلم الآلي"
// Initialize LanguageRecognizer
let languageRecog = NLLanguageRecognizer()
// find the dominant language
languageRecog.processString(string1)
print("Dominant language is: \(languageRecog.dominantLanguage?.rawValue)")
// identify the possible languages
languageRecog.processString(string2)
print("Possible languages are:\(languageRecog.languageHypotheses(withMaximum: 2))")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment