From 96cac0a8c861d5cdb1bb7765cc2d20e47ebb7885 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 3 Aug 2020 20:40:04 -0400 Subject: Work on ngram sorter --- lua/telescope/sorters.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lua/telescope/sorters.lua') diff --git a/lua/telescope/sorters.lua b/lua/telescope/sorters.lua index a648007..c97a1a9 100644 --- a/lua/telescope/sorters.lua +++ b/lua/telescope/sorters.lua @@ -1,3 +1,5 @@ +local util = require('telescope.utils') + local sorters = {} @@ -31,4 +33,30 @@ end sorters.Sorter = Sorter +sorters.get_ngram_sorter = function() + return Sorter:new { + scoring_function = function(_, prompt, line) + if prompt == "" or prompt == nil then + return 1 + end + + local ok, result = pcall(function() + local ngram = util.new_ngram { N = 4 } + ngram:add(line) + + local score = ngram:score(prompt) + if score == 0 then + return -1 + end + + -- return math.pow(math.max(score, 0.0001), -1) + return score + end) + + print(prompt, line, result) + return ok and result or 1 + end + } +end + return sorters -- cgit v1.2.3