This repository was archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
54 lines (43 loc) · 1.26 KB
/
Copy pathbuild.rs
File metadata and controls
54 lines (43 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use serde::Deserialize;
use std::error::Error;
#[derive(Debug, PartialEq)]
pub enum KVariantClass {
Wrong,
SementicVariant,
Simplified,
Old,
Equal,
}
#[derive(Debug, PartialEq)]
pub struct KVariant {
pub source_ideograph: char,
pub classification: KVariantClass,
pub destination_ideograph: char,
}
#[derive(Deserialize)]
pub struct TsvRow {
lhs: String,
relation: String,
rhs: String,
}
fn main() {
// Tell Cargo that if the given file changes, to rerun this build script.
println!("cargo:rerun-if-changed=dictionaries/kVariants.txt");
compress_kvariant_txt().unwrap();
}
fn compress_kvariant_txt() -> Result<(), Box<dyn Error>> {
let reader = csv::ReaderBuilder::new()
.delimiter(b'\t')
.has_headers(false)
.from_path("dictionaries/source/kVariants.txt");
let mut writer = csv::Writer::from_path("dictionaries/compressed/kVariants.csv")?;
for result in reader?.deserialize() {
let line: TsvRow = result?;
// Extract "㨲" from "㨲 (U+3A32)"
let rhs = line.rhs.chars().nth(0).unwrap();
let lhs = line.lhs.chars().nth(0).unwrap();
writer.write_record(&[lhs.to_string(), line.relation, rhs.to_string()])?;
}
writer.flush()?;
Ok(())
}