mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-06-29 01:43:10 -04:00
* Use Hamming textdistance library Used Hamming textdistance to sort by closest match. * Global search UI improvements Increased dropdown height to show more results initially (and which can also be scrolled into view). Scrollbars will appear automatically as needed. Remove dropdown when Search box is cleared. * Added textdistance 4.6.2 library
28 lines
783 B
Python
28 lines
783 B
Python
from __future__ import annotations
|
|
|
|
# built-in
|
|
from itertools import permutations, product
|
|
from typing import Sequence
|
|
|
|
|
|
__all__ = ['words_combinations', 'find_ngrams']
|
|
|
|
|
|
def words_combinations(f, *texts) -> float:
|
|
m = float('Inf')
|
|
# split by words
|
|
texts = [t.split() for t in texts]
|
|
# permutations
|
|
texts = [permutations(words) for words in texts]
|
|
# combinations
|
|
for subtexts in product(*texts):
|
|
if f.equality:
|
|
words_min_cnt = len(min(subtexts, key=len))
|
|
subtexts = [t[:words_min_cnt] for t in subtexts]
|
|
subtexts = [' '.join(t) for t in subtexts]
|
|
m = min(m, f(*subtexts))
|
|
return m
|
|
|
|
|
|
def find_ngrams(input_list: Sequence, n: int) -> list[tuple]:
|
|
return list(zip(*[input_list[i:] for i in range(n)]))
|