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

Napi #32

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Napi #32

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/jlabel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
serde = ["dep:serde"]
napi = ["dep:napi", "dep:napi-derive"]

[dependencies]
thiserror.workspace = true

serde = { version = "1", features = ["derive"], optional = true }
napi = { version = "2", optional = true }
napi-derive = { version = "2", optional = true }
11 changes: 11 additions & 0 deletions crates/jlabel/src/fullcontext_label.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#[cfg(feature = "napi")]
use napi_derive::napi;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// The structure representing a single line of HTS-style full-context label.
///
/// The parser from str, and the serializer to String are both implemented.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Label {
/// Phoneme
Expand Down Expand Up @@ -35,6 +38,7 @@ pub struct Label {

/// `Phoneme` field of full-context label.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Phoneme {
/// P1: the phoneme identity before the previous phoneme
Expand All @@ -51,6 +55,7 @@ pub struct Phoneme {

/// `Mora` field of full-context label (`A` field).
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Mora {
/// A1: the difference between accent type and position of the current mora identity
Expand All @@ -63,6 +68,7 @@ pub struct Mora {

/// `Word` field of full-context label (`B`, `C`, and `D` field).
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Word {
/// B1/C1/D1: pos (part-of-speech) of the word
Expand All @@ -77,6 +83,7 @@ pub struct Word {
///
/// F4 is undefined.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AccentPhraseCurrent {
/// F1: the number of moras in the current accent phrase
Expand All @@ -99,6 +106,7 @@ pub struct AccentPhraseCurrent {
///
/// E4/G4 is undefined.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AccentPhrasePrevNext {
/// E1/G1: the number of moras in the accent phrase
Expand All @@ -120,6 +128,7 @@ pub struct AccentPhrasePrevNext {

/// `BreathGroup` field of full-context label for current breath group (`I` field).
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BreathGroupCurrent {
/// I1: the number of accent phrases in the current breath group
Expand All @@ -142,6 +151,7 @@ pub struct BreathGroupCurrent {

/// `BreathGroup` field of full-context label for previous or next breath group (`H` and `J` field).
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BreathGroupPrevNext {
/// H1/J1: the number of accent phrases in the breath group
Expand All @@ -152,6 +162,7 @@ pub struct BreathGroupPrevNext {

/// `Utterance` field of full-context label (`K` field).
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "napi", napi(object))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Utterance {
/// K1: the number of breath groups in this utterance
Expand Down
Loading