Skip to content

Instantly share code, notes, and snippets.

@mohdsanadzakirizvi
Created November 26, 2019 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohdsanadzakirizvi/3ab00585038ba6c17b92636734a898a5 to your computer and use it in GitHub Desktop.
Save mohdsanadzakirizvi/3ab00585038ba6c17b92636734a898a5 to your computer and use it in GitHub Desktop.
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