Last active
May 8, 2020 11:03
-
-
Save 7shi/e9c84374626a5447e1fb81668eb2fc25 to your computer and use it in GitHub Desktop.
[F#] Ido dictionary converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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