Skip to content

Commit

Permalink
Merge pull request #70 from Garvys/task/opt_weight_draw
Browse files Browse the repository at this point in the history
Making drawing weights optional
  • Loading branch information
Alexandre Caulier authored Jan 31, 2020
2 parents 2d7a1a5 + e8f40af commit e8ff8cf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `unset_input_symbols` and `unset_output_symbols` methods to remove the symbol tables attached to a mutable fst.
- Added `emplace_arc` and `emplace_arc_unchecked` as provided methods to the `MutableFst` trait.
- Added `set_symts_from_fst` to MutableFst trait to copy the SymbolTable from another `Fst`.
- Added `print_weights` field to `DrawingConfig` to avoid print weights when desired.

### Changed
- Make `KDELTA` public outside of the crate
Expand Down
3 changes: 3 additions & 0 deletions rustfst/src/drawing_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct DrawingConfig {
pub acceptor: bool,
/// Print/draw arc weights and final weights equal to Weight::ONE.
pub show_weight_one: bool,
/// Print/draw arc weights and final weights.
pub print_weight: bool,
}

impl Default for DrawingConfig {
Expand All @@ -33,6 +35,7 @@ impl Default for DrawingConfig {
fontsize: 14,
acceptor: false,
show_weight_one: true,
print_weight: true,
}
}
}
4 changes: 2 additions & 2 deletions rustfst/src/fst_traits/serializable_fst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ where
write!(writer, "{}", state_id)?;
write!(writer, " [label = \"{}", state_id)?;
if let Some(final_weight) = fst.final_weight(state_id)? {
if config.show_weight_one || !final_weight.is_one() {
if config.print_weight && (config.show_weight_one || !final_weight.is_one()) {
write!(writer, "/{}", final_weight)?;
}
write!(writer, "\", shape = doublecircle,")?;
Expand Down Expand Up @@ -160,7 +160,7 @@ where
write!(writer, ":{}", olabel)?;
}

if config.show_weight_one || !arc.weight.is_one() {
if config.print_weight && (config.show_weight_one || !arc.weight.is_one()) {
write!(writer, "/{}", arc.weight)?;
}
writeln!(writer, "\", fontsize = {}];", config.fontsize)?;
Expand Down

0 comments on commit e8ff8cf

Please sign in to comment.