lace_codebook/
lib.rs

1//! The `Codebook` is a YAML file used to associate metadata with the dataset.
2//! The user can set the priors on the structure of each state, can identify
3//! the model for each columns, and set hyper priors.
4//!
5//! Often the data has too many columns to write a codebook manually, so there
6//! are functions to guess at a default codebook given a dataset. The user can
7//! then edit the default file.
8//!
9//! # Example
10//!
11//! An Example codebook for a two-column dataset.
12//!
13//! ```
14//! # use lace_codebook::Codebook;
15//! use indoc::indoc;
16//!
17//! let codebook_str = indoc!("
18//!     ---
19//!     table_name: two column dataset
20//!     state_prior_process:
21//!       !dirichlet
22//!         alpha_prior:
23//!           shape: 1.0
24//!           rate: 1.0
25//!     view_prior_process:
26//!       !pitman_yor
27//!         alpha_prior:
28//!           shape: 1.0
29//!           rate: 1.0
30//!         d_prior:
31//!           alpha: 1.0
32//!           beta: 2.0
33//!     col_metadata:
34//!       - name: col_1
35//!         notes: first column with all fields filled in
36//!         coltype:
37//!           !Categorical
38//!             k: 3
39//!             hyper:
40//!               pr_alpha:
41//!                 shape: 1.0
42//!                 scale: 1.0
43//!             prior:
44//!                 k: 3
45//!                 alpha: 0.5
46//!             value_map: !string
47//!               0: red
48//!               1: green
49//!               2: blue
50//!       - name: col_2
51//!         notes: A binary column with optional fields left out
52//!         coltype:
53//!           !Categorical
54//!             k: 2
55//!             value_map: !u8 2
56//!     comments: An example codebook
57//!     row_names:
58//!       - A
59//!       - B
60//!       - C
61//!       - D
62//!       - E");
63//!
64//! let codebook: Codebook = serde_yaml::from_str(&codebook_str).unwrap();
65//!
66//! assert_eq!(codebook.col_metadata.len(), 2);
67//! ```
68#![warn(unused_extern_crates)]
69#![warn(
70    clippy::all,
71    clippy::imprecise_flops,
72    clippy::suboptimal_flops,
73    clippy::unseparated_literal_suffix,
74    clippy::unreadable_literal,
75    clippy::option_option,
76    clippy::implicit_clone
77)]
78
79mod codebook;
80pub mod data;
81mod error;
82mod value_map;
83
84#[cfg(feature = "formats")]
85pub mod formats;
86
87pub use codebook::*;
88pub use error::*;
89pub use value_map::{
90    CategoryIter, CategoryMap, ValueMap, ValueMapExtension,
91    ValueMapExtensionError,
92};