class_docstr: Detect the language used in a snippet of text.
    
class_docstr_tok: ["Detect","the","language","used","in","a","snippet","of","text","."]
docstr: Decide which language is used to write the text.
  
  The method tries first to detect the language with high reliability. If
  that is not possible, the method switches to best effort strategy.
  
  
  Args:
    text (string): A snippet of text, the longer it is the more reliable we
                   can detect the language used to write the text.
docstr_tok: ["Decide","which","language","is","used","to","write","the","text",".","The","method","tries","first","to","detect","the","language","with","high","reliability",".","If","that","is","not","possible",",","the","method","switches","to","best","effort","strategy",".","Args",":","text","(","string",")",":","A","snippet","of","text",",","the","longer","it","is","the","more","reliable","we","can","detect","the","language","used","to","write","the","text","."]
code: def detect(self, text):
      """Decide which language is used to write the text.
  
      The method tries first to detect the language with high reliability. If
      that is not possible, the method switches to best effort strategy.
  
  
      Args:
        text (string): A snippet of text, the longer it is the more reliable we
                       can detect the language used to write the text.
      """
      t = text.encode("utf-8")
      reliable, index, top_3_choices = cld2.detect(t, bestEffort=False)
  
      if not reliable:
          self.reliable = False
          reliable, index, top_3_choices = cld2.detect(
              t, bestEffort=True
          )
  
          if not self.quiet:
              if not reliable:
                  raise UnknownLanguage(
                      "Try passing a longer snippet of text"
                  )
              else:
                  logger.warning(
                      "Detector is not able to detect the language reliably."
                  )
  
      self.languages = [Language(x) for x in top_3_choices]
      self.language = self.languages[0]
      return self.language
  
file_path: polyglot/polyglot/detect/base.py
imports: import logging
  from icu import Locale
  import pycld2
label_desc: Use image node_id 3 for calling the Detector obj's underlying member method code with example usage: obj.detect(text) and returns: self