mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
Fix match imports and simplify fuzzy threshold.
This commit is contained in:
parent
218d779b4d
commit
737563570e
@ -65,7 +65,7 @@ from autojump_utils import sanitize
|
|||||||
from autojump_utils import take
|
from autojump_utils import take
|
||||||
from autojump_utils import unico
|
from autojump_utils import unico
|
||||||
|
|
||||||
VERSION = '22.3.2'
|
VERSION = '22.3.3'
|
||||||
FUZZY_MATCH_THRESHOLD = 0.6
|
FUZZY_MATCH_THRESHOLD = 0.6
|
||||||
TAB_ENTRIES_COUNT = 9
|
TAB_ENTRIES_COUNT = 9
|
||||||
TAB_SEPARATOR = '__'
|
TAB_SEPARATOR = '__'
|
||||||
|
@ -2,11 +2,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
|
|
||||||
|
from autojump_utils import is_python3
|
||||||
|
from autojump_utils import is_windows
|
||||||
|
from autojump_utils import last
|
||||||
|
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
|
if is_python3():
|
||||||
ifilter = filter
|
ifilter = filter
|
||||||
imap = map
|
imap = map
|
||||||
os.getcwdu = os.getcwd
|
os.getcwdu = os.getcwd
|
||||||
@ -73,7 +76,7 @@ def match_consecutive(needles, haystack, ignore_case=False):
|
|||||||
regex_no_sep_end = regex_no_sep + '$'
|
regex_no_sep_end = regex_no_sep + '$'
|
||||||
regex_one_sep = regex_no_sep + sep + regex_no_sep
|
regex_one_sep = regex_no_sep + sep + regex_no_sep
|
||||||
# can't use compiled regex because of flags
|
# can't use compiled regex because of flags
|
||||||
regex_needle = regex_one_sep.join(map(re.escape, needles)).replace('\\', '\\\\') + regex_no_sep_end # noqa
|
regex_needle = regex_one_sep.join(imap(re.escape, needles)).replace('\\', '\\\\') + regex_no_sep_end # noqa
|
||||||
regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE
|
regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE
|
||||||
found = lambda entry: re.search(
|
found = lambda entry: re.search(
|
||||||
regex_needle,
|
regex_needle,
|
||||||
@ -82,10 +85,10 @@ def match_consecutive(needles, haystack, ignore_case=False):
|
|||||||
return ifilter(found, haystack)
|
return ifilter(found, haystack)
|
||||||
|
|
||||||
|
|
||||||
def match_fuzzy(needles, haystack, ignore_case=False):
|
def match_fuzzy(needles, haystack, ignore_case=False, threshold=0.6):
|
||||||
"""
|
"""
|
||||||
Performs an approximate match with the last needle against the end of
|
Performs an approximate match with the last needle against the end of
|
||||||
every path past an acceptable threshold (FUZZY_MATCH_THRESHOLD).
|
every path past an acceptable threshold.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
needles = ['foo', 'bar']
|
needles = ['foo', 'bar']
|
||||||
@ -115,6 +118,5 @@ def match_fuzzy(needles, haystack, ignore_case=False):
|
|||||||
match_percent = lambda entry: SequenceMatcher(
|
match_percent = lambda entry: SequenceMatcher(
|
||||||
a=needle,
|
a=needle,
|
||||||
b=end_dir(entry.path)).ratio()
|
b=end_dir(entry.path)).ratio()
|
||||||
meets_threshold = lambda entry: match_percent(entry) >= \
|
meets_threshold = lambda entry: match_percent(entry) >= threshold
|
||||||
FUZZY_MATCH_THRESHOLD
|
|
||||||
return ifilter(meets_threshold, haystack)
|
return ifilter(meets_threshold, haystack)
|
||||||
|
Loading…
Reference in New Issue
Block a user