Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mengasingkan kod teras dalam subcrate 'onc' #4

Merged
merged 12 commits into from
Apr 24, 2024
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on: [push, pull_request]

jobs:
test-rust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '20'

- run: yarn test
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"lint": "prettier --check .",
"format": "prettier --write .",
"modulize-wasm": "node ./wasm-rs/modulize.js",
"wasm": "wasm-pack build ./wasm-rs --target web && yarn run modulize-wasm"
"wasm": "wasm-pack build ./wasm-rs --target web && yarn run modulize-wasm",
"test": "cargo test --manifest-path ./wasm-rs/Cargo.toml --workspace"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
Expand Down Expand Up @@ -42,4 +43,4 @@
"tailwind-variants": "^0.2.1",
"vite-plugin-wasm-pack": "^0.1.12"
}
}
}
2 changes: 1 addition & 1 deletion static/Imbuhan.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ awal = "me"

[[imbuhan]]
ganti.awal = { "" = "ng", "k" = "ng", "g" = "ngg", "h" = "ng", "q" = "ngq", "b" = "mb", "v" = "mv", "f" = "mf", "p" = "m", "c" = "nc", "d" = "nd", "j" = "nj", "sy" = "nsy", "t" = "n", "z" = "z", "s" = "ny" }
untuk = ["kata nama"]
untuk = ["kata kerja"]
awal = "pe"

[[imbuhan]]
Expand Down
180 changes: 18 additions & 162 deletions wasm-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions wasm-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
workspace = { members = ["onc"] }

[package]
name = "wasm-rs"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]
crate-type = ["lib", "cdylib"]

[dependencies]
clap = { version = "4.5.4", features = ["cargo"] }
itertools = "0.12.1"
nom = "7.1.3"
lazy_static = { version = "1.4.0", optional = true }
onc = { version = "0.1.0", path = "onc" }
serde = { version = "1.0.197", features = ["derive"] }
serde-wasm-bindgen = "0.6.5"
toml = "0.8.11"
wasm-bindgen = { version = "0.2.92", features = ["serde"] }

[features]
lazystatic = ["dep:lazy_static"]

[[example]]
name = "imbuhan"
required-features = ["lazystatic"]
80 changes: 80 additions & 0 deletions wasm-rs/examples/imbuhan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use std::collections::HashSet;

use wasm_rs::functions::{parse_default_tatabunyi_toml, parse_imbuhan_toml};
use wasm_rs::imbuhan::JenisKata;

lazy_static::lazy_static! {
static ref INPUTS: [(&'static str, HashSet<JenisKata>); 3] = [
("susyi", HashSet::from([JenisKata::Nama])),
("terang", HashSet::from([JenisKata::Nama, JenisKata::Kerja])),
("merah", HashSet::from([JenisKata::Sifat]))
];
}
const IMBUHAN_CONFIG: &'static str = r#"
[[imbuhan]]
ganti.awal = { "" = "ng", "k" = "ng", "g" = "ngg", "h" = "ng", "q" = "ngq", "b" = "mb", "v" = "mv", "f" = "mf", "p" = "m", "c" = "nc", "d" = "nd", "j" = "nj", "sy" = "nsy", "t" = "n", "z" = "z", "s" = "ny" }
untuk = ["kata kerja"]
awal = "me"

[[imbuhan]]
untuk = ["kata nama"]
awal = "per"

[[imbuhan]]
untuk = ["kata nama", "kata kerja"]
awal = "juru"

[[imbuhan]]
untuk = ["kata kerja", "kata sifat"]
awal = "ter"

[[imbuhan]]
untuk = ["kata sifat"]
awal = "se"

[[imbuhan]]
ganti.awal = { "" = "ng", "k" = "ng", "g" = "ngg", "h" = "ng", "q" = "ngq", "b" = "mb", "v" = "mv", "f" = "mf", "p" = "m", "c" = "nc", "d" = "nd", "j" = "nj", "sy" = "nsy", "t" = "n", "z" = "z", "s" = "ny" }
untuk = ["kata kerja"]
awal = "me"
akhir = "kan"

[[imbuhan]]
untuk = ["kata nama", "kata kerja", "kata sifat"]
awal = "ke"
akhir = "an"
"#;
const PHONOTACTIC_CONFIG: &'static str = r#"
default = "Melayu Moden"

[[phonotactic]]
name = "Melayu Moden"
definition.onset = [["sp", "spr", "sw", "sk", "skr", "st", "str", "kl", "fl", "bl", "pl", "pr", "kr", "gr", "tr", "dr", "kh", "sy", "gh", "ny", "ng", "v", "x", "q", "f", "y", "w", "m", "n", "p", "t", "c", "k", "b", "d", "j", "g", "s", "h", "l", "r"]]
definition.nucleus = [["a", "e", "i", "o", "u"]]
definition.coda = [["ks", "ns", "nk", "lf", "rt", "rd", "rt", "kh", "sy", "gh", "ng", "q", "f", "b", "m", "n", "p", "t", "k", "s", "h", "l", "r"]]
"#;

fn main() {
println!("<< Example: Imbuhan >>");
let imbuhans = parse_imbuhan_toml(IMBUHAN_CONFIG.to_string());
let phonotactic = parse_default_tatabunyi_toml(PHONOTACTIC_CONFIG.to_string());

for (n, (input, set)) in INPUTS.iter().enumerate() {
println!("\n[E.g. {}] ========", n + 1);
let input = String::from(*input);
println!("Input\t\t: {}", &input);
println!("Golongan Kata\t: {:?}", &set);

let mut items = Vec::<String>::new();

for imbuhan in &imbuhans {
if imbuhan.contains(
set.contains(&JenisKata::Nama),
set.contains(&JenisKata::Kerja),
set.contains(&JenisKata::Sifat),
) {
items.push(imbuhan.transform_string_with(&input, &phonotactic));
}
}
println!("Results\t\t: {}", items.join(", "))
}
}
Loading
Loading