mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 07:17:39 +08:00
Little improvement
This commit is contained in:
parent
882810378d
commit
1639bac368
@ -17,8 +17,8 @@ __registry__ = cr = CommandRegistry(init_func=_init)
|
|||||||
|
|
||||||
@cr.register('process')
|
@cr.register('process')
|
||||||
@cr.restrict(full_command_only=True)
|
@cr.restrict(full_command_only=True)
|
||||||
def process(sentence, ctx_msg, internal=False):
|
def process(args_text, ctx_msg, internal=False):
|
||||||
sentence = sentence.strip()
|
sentence = args_text.strip()
|
||||||
potential_commands = parse_potential_commands(sentence)
|
potential_commands = parse_potential_commands(sentence)
|
||||||
potential_commands = sorted(filter(lambda x: x[0] > 60, potential_commands), key=lambda x: x[0], reverse=True)
|
potential_commands = sorted(filter(lambda x: x[0] > 60, potential_commands), key=lambda x: x[0], reverse=True)
|
||||||
if len(potential_commands) > 0:
|
if len(potential_commands) > 0:
|
||||||
@ -26,7 +26,13 @@ def process(sentence, ctx_msg, internal=False):
|
|||||||
ctx_msg['parsed_data'] = most_possible_cmd[3]
|
ctx_msg['parsed_data'] = most_possible_cmd[3]
|
||||||
cmdhub.call(most_possible_cmd[1], most_possible_cmd[2], ctx_msg)
|
cmdhub.call(most_possible_cmd[1], most_possible_cmd[2], ctx_msg)
|
||||||
else:
|
else:
|
||||||
core.echo('我暂时不理解你在说什么哦~', ctx_msg, internal)
|
if ctx_msg.get('from_voice'):
|
||||||
|
core.echo('暂时无法理解你的意思,下面将发送图灵机器人的回复……', ctx_msg, internal)
|
||||||
|
core.tuling123(sentence, ctx_msg, internal)
|
||||||
|
else:
|
||||||
|
core.echo('暂时无法理解你的意思。\n'
|
||||||
|
'由于自然语言识别还非常不完善,建议使用命令来精确控制我。\n'
|
||||||
|
'如需帮助请发送「使用帮助」。', ctx_msg, internal)
|
||||||
|
|
||||||
|
|
||||||
def _load_processors():
|
def _load_processors():
|
||||||
|
@ -26,7 +26,9 @@ def parse_potential_commands(sentence):
|
|||||||
for regex in processor[0]:
|
for regex in processor[0]:
|
||||||
for word, flag in segmentation:
|
for word, flag in segmentation:
|
||||||
if re.match(regex, word):
|
if re.match(regex, word):
|
||||||
potential_commands.append(processor[1](sentence, segmentation))
|
result = processor[1](sentence, segmentation)
|
||||||
|
if result:
|
||||||
|
potential_commands.append(result)
|
||||||
processed = True
|
processed = True
|
||||||
# A word matched, skip the rest of words
|
# A word matched, skip the rest of words
|
||||||
break
|
break
|
||||||
@ -34,5 +36,7 @@ def parse_potential_commands(sentence):
|
|||||||
# Current processor has processed, skip the rest of keywords
|
# Current processor has processed, skip the rest of keywords
|
||||||
break
|
break
|
||||||
for func in _processors_without_keyword:
|
for func in _processors_without_keyword:
|
||||||
potential_commands.append(func(sentence, segmentation))
|
result = func(sentence, segmentation)
|
||||||
|
if result:
|
||||||
|
potential_commands.append(result)
|
||||||
return potential_commands
|
return potential_commands
|
||||||
|
@ -3,14 +3,14 @@ import re
|
|||||||
from nl_processor import as_processor
|
from nl_processor import as_processor
|
||||||
|
|
||||||
_query_lang_matcher = [
|
_query_lang_matcher = [
|
||||||
re.compile('[把将]?[ ,.,。]?(.*?)[ ,.,。]?(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))翻译[成为到](\w+?[文语])(?![ ::,,.。])'),
|
re.compile('[把将]?[\s,.,。]?(.*?)[\s,.,。]?(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))?翻译[成为到](\w+?[文语])(?![\s::,,.。])'),
|
||||||
re.compile('(\w+?)[ ,.,。]?(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))?[的用](\w+?[文语])')
|
re.compile('(\w+?)[\s,.,。]?(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))?[的用](\w+?[文语])')
|
||||||
]
|
]
|
||||||
|
|
||||||
_lang_query_matcher = [
|
_lang_query_matcher = [
|
||||||
re.compile('[把将]?(?:(?:这[个]?|[下后][面]?)(?:词[组]?|句(?:子|话)?|短语))翻译[成为到](\w+?[文语])[ ::,,.。](.*)'),
|
re.compile('.*[把将]?(?:(?:这[个]?|[下后][面]?)(?:词[组]?|句(?:子|话)?|短语))?翻译[成为到]\s*(\w+?[文语])[\s::,,](.*)'),
|
||||||
re.compile('[用]?(\w+[文语])\w+?(?:说|讲|表达|表示)(.*)(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))'),
|
re.compile('[用]?(\w+[文语])\w+?(?:说|讲|表达|表示)(.*)(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))'),
|
||||||
re.compile('[用]?(\w+[文语])\w+?(?:说|讲|表达|表示)(.*)')
|
re.compile('[用]?(\w+[文语])\w+?(?:说|讲|表达|表示)(.*)'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -27,5 +27,6 @@ def _processor(sentence, segmentation):
|
|||||||
lang, query = m.group(2), m.group(1)
|
lang, query = m.group(2), m.group(1)
|
||||||
break
|
break
|
||||||
if lang and query:
|
if lang and query:
|
||||||
|
print('翻译: 目标语言:', lang, ', 待翻译文本:', query)
|
||||||
return 90, 'translate.translate_to', ' '.join((lang.strip(), query.strip(' ,,'))), None
|
return 90, 'translate.translate_to', ' '.join((lang.strip(), query.strip(' ,,'))), None
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user