Skip to content

Instantly share code, notes, and snippets.

@7shi
Last active May 8, 2020 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/e9c84374626a5447e1fb81668eb2fc25 to your computer and use it in GitHub Desktop.
Save 7shi/e9c84374626a5447e1fb81668eb2fc25 to your computer and use it in GitHub Desktop.
[F#] Ido dictionary converter
// https://github.com/kyegupov/ido_web_dictionary
// https://gist.github.com/7shi/de072cd867f3899aa285bc9343110bff
#load "XmlParser.fsx"
open System
open System.IO
open System.Text
open XmlParser
let dir = "ido_web_dictionary/service_data/dictionaries_by_letter"
let convert (dict:string) =
let dir = Path.Combine(dir, dict)
use sw = new StreamWriter(dict + ".txt")
let files =
Directory.GetFiles(dir)
|> Seq.filter (Path.GetExtension >> (=) ".txt")
|> Seq.sortBy Path.GetFileNameWithoutExtension
for file in files do
let mutable src = ""
let f() =
if src = "" then () else
use xp = new XmlParser(src)
while xp.Read() do
sw.Write(fromEntity xp.Text)
sw.WriteLine()
for line in File.ReadAllLines file do
if line = "" then
f()
src <- ""
elif src = "" then
src <- line
else
src <- src + " " + line
f()
convert "en-io"
convert "io-en"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment