[Python] propt-toolkit으로 fuzy complete 구현(모호 보완)

4471 단어 prompt_toolkitPython

작업 환경

> python --version
Python 3.7.1

> pipenv graph
prompt-toolkit==2.0.8
  - six [required: >=1.9.0, installed: 1.12.0]
  - wcwidth [required: Any, installed: 0.1.7]

기본 완성(WordCompuleter)



단어의 보완은 사용할 수 있다prompt_toolkit.completion.WordCompleter
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter

# 単語の候補
my_completer = WordCompleter(
    ["apple", "goole", "japan", "hoge", "hello world", "good morning"]
)

while 1:
    # hisotoryで履歴を追加
    user_input = prompt(">", completer=my_completer)
    print(user_input)

모호보전



prompt_toolkit 2.0.8 부터 모호한 검색 (fuzy find) 의 autocomple을 배웠어요.FuzzyWordCompleterWordCompleter으로 싸서 WordCompleter처럼 사용 가능
from prompt_toolkit import prompt
from prompt_toolkit.completion import FuzzyWordCompleter

# 単語の候補
my_completer = FuzzyWordCompleter(
    ["apple", "goole", "japan", "hoge", "hello world", "good morning"]
)

while 1:
    # hisotoryで履歴を追加
    user_input = prompt("> ", completer=my_completer)
    print(user_input)

참고 문헌

  • psyhon-proompt-toolkit의 간단한 자동 보충 - Steel Dragon 14106
  • https://github.com/prompt-toolkit/python-prompt-toolkit/blob/81c30157422989957c8a56b333b17ba35ab1a223/prompt_toolkit/completion/fuzzy_completer.py#L142-L168
  • 좋은 웹페이지 즐겨찾기