Commits

spirit  committed 889ff6d Merge

Automated merge with ssh://bitbucket.org/tush/guess_language

  • Participants
  • Parent commits a6b3d77, d91ee55

Comments (0)

Files changed (2)

File guess_language/__init__.py

 
 __all__ = [
     "guess_language", "guess_language_tag", "guess_language_id",
-    "guess_language_name", "guess_language_info", "UNKNOWN",
+    "guess_language_name", "guess_language_info", "UNKNOWN", "use_enchant",
 ]
 
-USE_ENCHANT = True
 MAX_LENGTH = 4096
 MIN_LENGTH = 20
 MAX_GRAMS = 300
     return UNKNOWN
 
 
-def check(words, langs, use_enchant=None):
-    """Check what is the best match.
+def check_with_all(words, langs):
+    """Check what the best match is.
     """
-    if use_enchant is None:
-        use_enchant = USE_ENCHANT
+    return check_with_enchant(words, langs) or check_with_models(words, langs)
 
-    if use_enchant:
-        tag = check_with_enchant(words, langs)
-        if tag:
-            return tag
 
+check = check_with_all
+
+
+def use_enchant(use_enchant=True):
+    """Enable or disable checking with PyEnchant.
+    """
+    global check
+    check = check_with_all if use_enchant else check_with_models
+
+
+def check_with_models(words, langs):
+    """Check against known models.
+    """
     sample = " ".join(words)
 
     if len(sample) < MIN_LENGTH:

File guess_language/__main__.py

 import os
 import sys
 
-import guess_language.console_mode
+import guess_language.console_mode #@UnusedImport
 
 
 def parse_args():
     with open(file, encoding=encoding) as f:
         text = "".join(f.readlines())
 
-    guess_language.USE_ENCHANT = args.use_enchant
+    if not args.use_enchant:
+        guess_language.use_enchant(False)
     tag = guess_language.guess_language(text)
     print(tag)