summaryrefslogtreecommitdiff
path: root/lang
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2017-12-05 15:19:26 +0100
committerPatrick Simianer <p@simianer.de>2017-12-05 15:19:26 +0100
commite58af8b555da48c267593fbfefa0a83f663c5908 (patch)
tree5ce8b96e79e28d227b2bbc83e855d8e1eeb5c3cb /lang
parentcba1035498554ec4ac1dd315b91a5ac988249d86 (diff)
lang
Diffstat (limited to 'lang')
-rwxr-xr-xlang26
1 files changed, 19 insertions, 7 deletions
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
+