From e58af8b555da48c267593fbfefa0a83f663c5908 Mon Sep 17 00:00:00 2001
From: Patrick Simianer <p@simianer.de>
Date: Tue, 5 Dec 2017 15:19:26 +0100
Subject: lang

---
 lang | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

(limited to 'lang')

diff --git a/lang b/lang
index b278a1e..5caebd1 100755
--- a/lang
+++ b/lang
@@ -22,8 +22,16 @@ try:
 except:
    min_p = None
 
+try:
+    strict = bool(sys.argv[4].strip())
+except:
+    strict = False
+
 if min_p and not l:
    l = None
+
+if strict and not min_p:
+   strict = False
      
 
 factory = langdetect.detector_factory.DetectorFactory()
@@ -35,29 +43,33 @@ for line in f:
         detector = factory.create()
         detector.append(line.strip())
         ld = detector.get_probabilities()
-        print(ld)
     except:
         print("unk")
         continue
 
     done = False
-    if l and len(l) > 1:
+    if l and len(ld) > 1:
         if min_p != None:
             for i in ld:
                 if i.lang == l:
                     if i.prob >= min_p:
                         print(i.lang)
                         done = True
-                        break
+                    break
         else:
             if l in map(lambda x: x.lang, ld):
                 print(l)
-                done = True
+                continue
 
     if not done:
-        print(ld[0].lang)
-    print('---')
-
+        if not strict:
+            print(ld[0].lang)
+        else:
+            if ld[0].prob >= min_p:
+                print(ld[0].lang)
+            else:
+                print("unk")
 
 if not from_stdin:
     f.close
+
-- 
cgit v1.2.3