1
0
mirror of https://github.com/kmein/niveum synced 2026-03-19 03:21:10 +01:00

2 Commits

Author SHA1 Message Date
e27db27fd8 chore: update 2021-11-15 18:43:47 +01:00
683bd2f3be feat: closest word script 2021-11-15 18:43:34 +01:00
8 changed files with 67 additions and 20 deletions

View File

@@ -1,9 +1,9 @@
{
"url": "https://github.com/mozilla/nixpkgs-mozilla",
"rev": "cf58c4c67b15b402e77a2665b9e7bad3e9293cb2",
"date": "2021-11-04T18:36:55+01:00",
"path": "/nix/store/29rc235gvrhgq3xyf5m3f2dw6rij6zk1-nixpkgs-mozilla",
"sha256": "1ws4xf6234cwzr9gya7f6p2cvdk5w7w1pccl4m2viqdnws16hcc8",
"rev": "4c8fc3d7b625d2d34bfb5aedf03c131aef2f87f8",
"date": "2021-11-15T17:16:09+01:00",
"path": "/nix/store/cln0xias9nmrlqn290x3535hav2z7kl1-nixpkgs-mozilla",
"sha256": "0xp4wwzglgs5pw5fb2ryywqiq1cw3ji0zn701nn6ndxbfjsc2l1p",
"fetchSubmodules": false,
"deepClone": false,
"leaveDotGit": false

View File

@@ -1,9 +1,9 @@
{
"url": "https://github.com/NixOS/nixpkgs.git",
"rev": "f2c9cf39e5cd7f7e85f35685f4f96b4c9fd5b9f4",
"date": "2021-11-07T23:04:28+01:00",
"path": "/nix/store/n1f0r49cn2iy14jsqxsrklv2hn9wkvhs-nixpkgs",
"sha256": "10awf5ljg4xilfbvbm5dxj16clj9s5h0i3yw6djh8pk6cpnl65bx",
"rev": "b0657ddc91101c625d2cba64b6b3d22350062f39",
"date": "2021-11-15T18:36:38+01:00",
"path": "/nix/store/vidd1nazd9m2v9djh8z1m7jc9c3dg91l-nixpkgs",
"sha256": "173klgdxj086iz8477kvq5y95f3hix87ra8v3xs4ddg66sm12nrp",
"fetchSubmodules": false,
"deepClone": false,
"leaveDotGit": false

View File

@@ -1,9 +1,9 @@
{
"url": "https://github.com/NixOS/nixpkgs.git",
"rev": "ce48bcdde86eef5780a60bea55b9bc9dbd8248cd",
"date": "2021-11-06T12:02:24+01:00",
"path": "/nix/store/5wzisb6jqvxlh1gbq4mpn7kcncpm7fxj-nixpkgs",
"sha256": "18r8hblb1x94v00y5d35cvnpszvk1mwy1cccdc6mzg5piglkk6yp",
"rev": "46251a79f752ae1d46ef733e8e9760b6d3429da4",
"date": "2021-11-14T21:40:46-05:00",
"path": "/nix/store/4j2xxc8kqvnif4nhsd0f58dymj3ckryd-nixpkgs",
"sha256": "1xsp0xyrf8arjkf4wi09n96kbg0r8igsmzx8bhc1nj4nr078p0pg",
"fetchSubmodules": false,
"deepClone": false,
"leaveDotGit": false

View File

@@ -1,9 +1,9 @@
{
"url": "https://github.com/nix-community/NUR",
"rev": "8029e3c29184c624767cd63bd9eebf94835ff0e0",
"date": "2021-11-07T22:56:47+00:00",
"path": "/nix/store/09lg7x7r1g3y8cgkqccvv32d8nc4rfsm-NUR",
"sha256": "0578i0m1wis2dpkzlhsw1b2rdjkx0q3x4ay04s5rwmfbwqd05r1d",
"rev": "ebf5ede213705809cb41ddb0cd4a2568b18c3d23",
"date": "2021-11-15T17:11:02+00:00",
"path": "/nix/store/n08kjjjsx193myprd029rgmwavgqqj2g-NUR",
"sha256": "02h737vr8r32kbqmm0z4fqc7pwkrjdj6q0mg5gzfjqqgyni75g2h",
"fetchSubmodules": false,
"deepClone": false,
"leaveDotGit": false

View File

@@ -1,9 +1,9 @@
{
"url": "https://cgit.krebsco.de/stockholm",
"rev": "2fccbc483dcb6a374b96868bbfaf38fd48853d72",
"date": "2021-11-04T14:22:01+01:00",
"path": "/nix/store/sm1lvz4spvcs125vs0kma5d3h48i1h0s-stockholm",
"sha256": "0yfawlx3ldi3mzw0yznjdi8aiybvpdc131bfvqb1qj87rr29p6fc",
"rev": "c979f7009f5ff1b2d25158aff1bca0f5be2dba54",
"date": "2021-11-08T05:14:49+01:00",
"path": "/nix/store/shz2yw0p30ibmw3lgr11ckzz0y4kmz4y-stockholm",
"sha256": "13yds6hwh6ah4mks8jrg7syigfmp17ylr7706jpvdzfy9ihj81wh",
"fetchSubmodules": false,
"deepClone": false,
"leaveDotGit": false

View File

@@ -157,6 +157,7 @@ in {
scripts.wttr
scripts.sanskrit-dictionary
scripts.unicodmenu
scripts.closest
scripts.trans
scripts.liddel-scott-jones
scripts.mpv-radio

View File

@@ -174,6 +174,16 @@ in rec {
script = ./favicon.sh;
};
closest = pkgs.writers.writeDashBin "closest" ''
${pkgs.writers.writeHaskellBin "closest" {
libraries = with pkgs.haskellPackages; [ parallel optparse-applicative edit-distance ];
ghcArgs = ["-O3" "-threaded" ];
} (builtins.readFile ./distance.hs)}/bin/closest +RTS -N4 -RTS --dictionary ${pkgs.fetchurl {
url = "https://gist.github.com/MarvinJWendt/2f4f4154b8ae218600eb091a5706b5f4/raw/36b70dd6be330aa61cd4d4cdfda6234dcb0b8784/wordlist-german.txt";
sha256 = "0vr4lmlckgvj4s8sk502sknq9pf3297rvasj5sqqm05zzbdgpppj";
}} "$@"
'';
genius = wrapScript {
packages = [ pkgs.curl pkgs.gnused pkgs.pandoc ];
name = "genius";

View File

@@ -0,0 +1,36 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE RecordWildCards #-}
import Control.Arrow ((&&&))
import Control.Monad (forM_)
import Control.Parallel.Strategies (using, parList, rdeepseq)
import Data.Char (toLower)
import Data.List (sortOn)
import Options.Applicative
import Text.EditDistance (levenshteinDistance, defaultEditCosts)
data Options = Options
{ limit :: Int
, word :: String
, dictionary :: FilePath
}
optionsParser :: Parser Options
optionsParser = do
limit <- option auto (long "limit" <> short 'l' <> help "maximum edit distance to list" <> value 3 <> metavar "N")
word <- strArgument (help "the word to match" <> metavar "WORD")
dictionary <- strOption (long "dictionary" <> short 'd' <> help "the dictionary to search")
pure Options {..}
readDictionary :: FilePath -> IO [String]
readDictionary path = lines . map toLower <$> readFile path
main :: IO ()
main = do
let options = info (optionsParser <**> helper) (fullDesc <> progDesc "Find close words")
Options {..} <- execParser options
let word' = map toLower word
allWords <- readDictionary dictionary
let distances = map (levenshteinDistance defaultEditCosts word' &&& id) allWords
distances' = distances `using` parList rdeepseq
ranking = takeWhile ((<= limit) . fst) $ sortOn fst distances'
forM_ ranking $ \(theDistance, theWord) -> putStrLn (show theDistance ++ " " ++ theWord)