Work on ngram sorter

This commit is contained in:
TJ DeVries
2020-08-03 20:40:04 -04:00
parent fa0382d93e
commit 96cac0a8c8
9 changed files with 486 additions and 61 deletions

View File

@@ -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