on master help sign in
[mod] checker : replace pycld3 by langdetect

pycld3 requires the native library cld3 langdetect is a pure python package

commitaa887eb375224da7253f3d98d20b922705e28df6 authorAlexandre Flament <alex@al-f.net> dateTue 19 Jan 2021, 21:26 (6 years ago) parent0495e15
3 files changed+13−10
requirements.txt+1−1 searx/search/checker/impl.py+10−5 utils/searx.sh+2−4
requirements.txt+1−1
@@ -9,4 +9,4 @@ pygments==2.1.3
99python-dateutil==2.8.1
1010pyyaml==5.3.1
1111requests[socks]==2.25.1
12−pycld3==0.20
12+langdetect==1.0.8
searx/search/checker/impl.py+10−5
@@ -9,7 +9,8 @@ from time import time
99from urllib.parse import urlparse
1010
1111import re
12−import cld3
12+from langdetect import detect_langs
13+from langdetect.lang_detect_exception import LangDetectException
1314import requests.exceptions
1415
1516from searx import poolrequests, logger
@@ -181,10 +182,14 @@ class ResultContainerTests:
181182 self.test_results.add_error(self.test_name, message, *args, '(' + sqstr + ')')
182183
183184 def _add_language(self, text: str) -> typing.Optional[str]:
184− r = cld3.get_language(str(text)) # pylint: disable=E1101
185− if r is not None and r.probability >= 0.98 and r.is_reliable:
186− self.languages.add(r.language)
187− self.test_results.add_language(r.language)
185+ try:
186+ r = detect_langs(str(text)) # pylint: disable=E1101
187+ except LangDetectException:
188+ return None
189+
190+ if len(r) > 0 and r[0].prob > 0.95:
191+ self.languages.add(r[0].lang)
192+ self.test_results.add_language(r[0].lang)
188193 return None
189194
190195 def _check_result(self, result):
utils/searx.sh+2−4
@@ -46,7 +46,6 @@ SEARX_PACKAGES_debian="\
4646python3-dev python3-babel python3-venv
4747uwsgi uwsgi-plugin-python3
4848git build-essential libxslt-dev zlib1g-dev libffi-dev libssl-dev
49−libprotobuf-dev protobuf-compiler
5049shellcheck"
5150
5251BUILD_PACKAGES_debian="\
@@ -59,7 +58,6 @@ SEARX_PACKAGES_arch="\
5958python python-pip python-lxml python-babel
6059uwsgi uwsgi-plugin-python
6160git base-devel libxml2
62−protobuf
6361shellcheck"
6462
6563BUILD_PACKAGES_arch="\
@@ -71,7 +69,7 @@ SEARX_PACKAGES_fedora="\
7169python python-pip python-lxml python-babel
7270uwsgi uwsgi-plugin-python3
7371git @development-tools libxml2
74−ShellCheck protobuf-compiler protobuf-devel"
72+ShellCheck"
7573
7674BUILD_PACKAGES_fedora="\
7775firefox graphviz graphviz-gd ImageMagick librsvg2-tools
@@ -84,7 +82,7 @@ SEARX_PACKAGES_centos="\
8482python36 python36-pip python36-lxml python-babel
8583uwsgi uwsgi-plugin-python3
8684git @development-tools libxml2
87−ShellCheck protobuf-compiler protobuf-devel"
85+ShellCheck"
8886
8987BUILD_PACKAGES_centos="\
9088firefox graphviz graphviz-gd ImageMagick librsvg2-tools