File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 6262 import ftlangdetect
6363
6464 def language_detector (text : str ) -> float :
65- return ftlangdetect .detect (text .lower ())["score" ]
65+ try :
66+ return ftlangdetect .detect (text .lower ())["score" ]
67+ except Exception as e :
68+ logger .info (
69+ f"Error when running ftlangdetect: '{ e } '. First 100 chars of the str were '{ text [:100 ]} '. Assuming probability of 1."
70+ )
71+ return 1.0
6672
6773 assert isinstance (language_detector ("This is a test" ), float )
6874except Exception as err :
@@ -77,7 +83,13 @@ def language_detector(text: str) -> float:
7783 import langdetect
7884
7985 def language_detector (text : str ) -> float :
80- return langdetect .detect_langs (text .lower ())[0 ].prob
86+ try :
87+ return langdetect .detect_langs (text .lower ())[0 ].prob
88+ except Exception as e :
89+ logger .info (
90+ f"Error when running langdetect: '{ e } '. First 100 chars of the str were '{ text [:100 ]} '. Assuming probability of 1."
91+ )
92+ return 1.0
8193
8294 assert isinstance (language_detector ("This is a test" ), float )
8395 except Exception as err :
You can’t perform that action at this time.
0 commit comments