openbangla / riti Goto Github PK
View Code? Open in Web Editor NEWThe Next Gen Bengali input method library written in Rust.
License: Mozilla Public License 2.0
The Next Gen Bengali input method library written in Rust.
License: Mozilla Public License 2.0
Rust currently has this two sqlite crates: rusqlite & sqlite.
This is the relevant C++ code before we started using json files.
This is the Rust code that I used to generate dictionary.json
and suffix.json
files with rusqlite crate:
extern crate rusqlite;
extern crate serde_json;
use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use rusqlite::Connection;
fn main() {
let table = vec!("A", "AA", "B", "BH",
"C", "CH", "D", "Dd", "Ddh", "Dh",
"E", "G", "Gh", "H", "I", "II",
"J", "JH", "K", "KH", "Khandatta",
"L", "M", "N", "NGA", "NN", "NYA",
"O","OI", "OU", "P", "PH",
"R", "RR", "RRH", "RRI",
"S", "SH", "SS",
"T", "TH", "TT", "TTH",
"U", "UU", "Y", "Z");
let conn = Connection::open("/home/mominul/src/OpenBangla-Keyboard/data/database.db3").unwrap();
// Dictionary
let mut dict = HashMap::new();
let mut count = 1;
for name in table {
let mut stmt = conn.prepare(&format!("SELECT * FROM {}", name)).unwrap();
let mut rows = stmt.query(&[]).unwrap();
let mut items: Vec<String> = Vec::new();
while let Some(res_row) = rows.next() {
let row = res_row.unwrap();
items.push(row.get(0));
count += 1;
}
dict.insert(name.to_ascii_lowercase(), items);
}
// Suffix dictionary
let mut suffix: HashMap<String, String> = HashMap::new();
let mut stmt = conn.prepare("SELECT * FROM Suffix").unwrap();
let mut rows = stmt.query(&[]).unwrap();
while let Some(res_row) = rows.next() {
let row = res_row.unwrap();
suffix.insert(row.get(0), row.get(1));
}
let serialized = serde_json::to_string_pretty(&dict).unwrap();
println!("Words entried in total {}", count);
let mut file = File::create("/home/mominul/src/Rust/dictionary2.json").unwrap();
file.write_all(serialized.as_bytes()).unwrap();
let serialized = serde_json::to_string(&suffix).unwrap();
let mut file = File::create("/home/mominul/src/Rust/suffix.json").unwrap();
file.write_all(serialized.as_bytes()).unwrap();
}
We currently use the serde-json
crate to parse the json files, but it is a heavy weight crate & we don't use it's main serialization feature. So we can use the json
crate which is enough and fast for our needs.
https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_raw
riti should provide such API to free the string / string values.
Quote:
The pointer which this function returns must be returned to Rust and reconstituted using CString::from_raw to be properly deallocated. Specifically, one should not use the standard C free() function to deallocate this string.
Failure to call CString::from_raw will lead to a memory leak.
Right now all the options are passed from environment variable which is kinda weird in practice. So I think if would be better to have API like:
RitiOptions* riti_options_new()
riti_options_set_optiona(RitiOptions *, bool value)
riti_options_set_optionb(RitiOptions *, const char* value)
riti_options_set_optionc(RitiOptions *, bool value)
....
riti_option_free(RitiOptions *)
void riti_context_set_options(RitiContext* context, RitiOptions* options);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.