diff options
author | Patrick Simianer <p@simianer.de> | 2017-12-05 15:19:26 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2017-12-05 15:19:26 +0100 |
commit | e58af8b555da48c267593fbfefa0a83f663c5908 (patch) | |
tree | 5ce8b96e79e28d227b2bbc83e855d8e1eeb5c3cb | |
parent | cba1035498554ec4ac1dd315b91a5ac988249d86 (diff) |
lang
-rwxr-xr-x | lang | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -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 + |