mirror of
https://github.com/chubin/cheat.sh.git
synced 2026-06-20 21:26:44 +02:00
Disable language detection
This commit is contained in:
+23
-20
@@ -12,8 +12,9 @@ import os
|
||||
import re
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from polyglot.detect import Detector
|
||||
from polyglot.detect.base import UnknownLanguage
|
||||
#Language detetction disabled
|
||||
#from polyglot.detect import Detector
|
||||
#from polyglot.detect.base import UnknownLanguage
|
||||
|
||||
from config import CONFIG
|
||||
from languages_data import SO_NAME
|
||||
@@ -83,25 +84,27 @@ class Question(UpstreamAdapter):
|
||||
topic = " ".join(topic_words)
|
||||
|
||||
lang = 'en'
|
||||
try:
|
||||
query_text = topic # " ".join(topic)
|
||||
query_text = re.sub('^[^/]*/+', '', query_text.rstrip('/'))
|
||||
query_text = re.sub('/[0-9]+$', '', query_text)
|
||||
query_text = re.sub('/[0-9]+$', '', query_text)
|
||||
detector = Detector(query_text)
|
||||
supposed_lang = detector.languages[0].code
|
||||
if len(topic_words) > 2 \
|
||||
or supposed_lang in ['az', 'ru', 'uk', 'de', 'fr', 'es', 'it', 'nl']:
|
||||
lang = supposed_lang
|
||||
if supposed_lang.startswith('zh_') or supposed_lang == 'zh':
|
||||
lang = 'zh'
|
||||
elif supposed_lang.startswith('pt_'):
|
||||
lang = 'pt'
|
||||
if supposed_lang in ['ja', 'ko']:
|
||||
lang = supposed_lang
|
||||
|
||||
except UnknownLanguage:
|
||||
print("Unknown language (%s)" % query_text)
|
||||
# Question language detection disabled
|
||||
# try:
|
||||
# query_text = topic # " ".join(topic)
|
||||
# query_text = re.sub('^[^/]*/+', '', query_text.rstrip('/'))
|
||||
# query_text = re.sub('/[0-9]+$', '', query_text)
|
||||
# query_text = re.sub('/[0-9]+$', '', query_text)
|
||||
# detector = Detector(query_text)
|
||||
# supposed_lang = detector.languages[0].code
|
||||
# if len(topic_words) > 2 \
|
||||
# or supposed_lang in ['az', 'ru', 'uk', 'de', 'fr', 'es', 'it', 'nl']:
|
||||
# lang = supposed_lang
|
||||
# if supposed_lang.startswith('zh_') or supposed_lang == 'zh':
|
||||
# lang = 'zh'
|
||||
# elif supposed_lang.startswith('pt_'):
|
||||
# lang = 'pt'
|
||||
# if supposed_lang in ['ja', 'ko']:
|
||||
# lang = supposed_lang
|
||||
|
||||
# except UnknownLanguage:
|
||||
# print("Unknown language (%s)" % query_text)
|
||||
|
||||
if lang != 'en':
|
||||
topic = ['--human-language', lang, topic]
|
||||
|
||||
+6
-3
@@ -9,10 +9,13 @@ redis
|
||||
colored
|
||||
langdetect
|
||||
cffi
|
||||
polyglot
|
||||
PyICU
|
||||
pycld2
|
||||
colorama
|
||||
pyyaml
|
||||
python-Levenshtein
|
||||
pylint
|
||||
|
||||
#Disable language detection feature
|
||||
#
|
||||
#polyglot
|
||||
#PyICU
|
||||
#pycld2
|
||||
|
||||
Reference in New Issue
Block a user