Skip to content

Instantly share code, notes, and snippets.

@7shi
Last active May 8, 2020
Embed
What would you like to do?
[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