Witam serdecznie,
mam problem z algorytmem podpowiadania słów podczas wpisywania tekstu.
Stworzyłem sobie listę obiektów:
public class FrequentDictionary
{
public string Value { get; set; }
public int Frequent { get; set; }
public int LevenshteinLength { get; set; }
public uint IsPrivate { get; set; }
}
Zaczytałem do pamięci 3mln takich obiektów.
Następnie przy wpisywaniu każdej nowej litery obliczam odległość Levenshteina:
checkedList = frequentDictionary.Where(x => x.Value.StartsWith(text.Remove(1))).Select(item => new FrequentDictionary()
{
Value = item.Value,
Frequent = item.Frequent,
LevenshteinLength = LevenshteinDistance.Compute(text, item.Value),
});
Samo obliczanie odległości Levenshteina w ten sposób zajmuje bardzo szybko: 2-3ms.
Aby znaleźć najlepsze dopasowanie filtruję tą listę w taki sposób:
var bestMatched = checkedList.OrderBy(x => x.LevenshteinLength)
.ThenByDescending(x => x.Frequent)
.Take(5);
No i wiadomo, że tu następuje załamanie prędkości. Materializacja sortowań zajmuje do 3000ms na moim kompie.
Próbuję przerobić to na HashSet'y ale na razie z mizernym skutkiem.
Mógłby mi ktoś podpowiedzieć jakie będzie najlepsze rozwiązanie?
Pozdrawiam.