pub struct DataSet { /* private fields */ }Expand description
Features of many pieces in one table: music21’s DataSet. Each piece
is a row, labelled with an id and a value of the class the set is about
– its composer, say – and each extractor gives it as many columns as
it has values. DataSet::process reads every feature of every piece,
and DataSet::to_text writes the table for a machine-learning tool.
use music21_rs::features::{DataSet, Library, OutputFormat, extractors_by_id};
use music21_rs::tinynotation::from_tiny_notation;
let mut set = DataSet::new("Composer");
set.add_extractors(extractors_by_id(&["R31", "R35"], &[Library::JSymbolic]));
set.add_data(&from_tiny_notation("4/4 c4 d e2")?, "Bach", Some("first piece"))?;
set.process();
assert_eq!(
set.to_text(OutputFormat::Csv),
"Identifier,Initial_Time_Signature_0,Initial_Time_Signature_1,Changes_of_Meter,Composer\n\
first_piece,4,4,0,Bach"
);Implementations§
Source§impl DataSet
impl DataSet
Sourcepub fn new(class_label: impl Into<String>) -> Self
pub fn new(class_label: impl Into<String>) -> Self
An empty data set about a class, named as its column is: music21’s
DataSet(classLabel=...).
Sourcepub fn class_label(&self) -> &str
pub fn class_label(&self) -> &str
The name of the class the set is about.
Sourcepub fn extractors(&self) -> &[&'static Extractor]
pub fn extractors(&self) -> &[&'static Extractor]
The extractors, in the order their columns come.
Sourcepub fn add_extractors(
&mut self,
extractors: impl IntoIterator<Item = &'static Extractor>,
)
pub fn add_extractors( &mut self, extractors: impl IntoIterator<Item = &'static Extractor>, )
Adds extractors after those already there: music21’s
addFeatureExtractors.
Sourcepub fn add_data(
&mut self,
stream: &Stream,
class_value: impl Into<String>,
id: Option<&str>,
) -> Result<()>
pub fn add_data( &mut self, stream: &Stream, class_value: impl Into<String>, id: Option<&str>, ) -> Result<()>
Adds a piece with its value of the class, prepared at once: music21’s
addData. Its id is the one given or, without one, the title of its
metadata, or nothing; spaces in it become underscores, as music21’s
getId writes them.
§Errors
A piece that cannot be prepared.
Sourcepub fn process(&mut self)
pub fn process(&mut self)
Reads every feature of every piece, standing a blank feature in for
one that cannot be read and keeping why in Self::failures:
music21’s process.
Sourcepub fn try_process(&mut self) -> Result<()>
pub fn try_process(&mut self) -> Result<()>
Reads every feature of every piece, stopping at the first that cannot
be read: music21’s process with failFast.
§Errors
The first feature that cannot be read.
Sourcepub fn features(&self) -> &[Vec<Feature>]
pub fn features(&self) -> &[Vec<Feature>]
The features read, a row for each piece and a feature for each extractor; empty until processed.
Sourcepub fn failures(&self) -> &[Failure]
pub fn failures(&self) -> &[Failure]
The features Self::process could not read.
Sourcepub fn attribute_labels(
&self,
include_class_label: bool,
include_id: bool,
) -> Vec<String>
pub fn attribute_labels( &self, include_class_label: bool, include_id: bool, ) -> Vec<String>
The column names: the id’s, each extractor’s attribute labels, and
the class’s, spaces made underscores: music21’s getAttributeLabels.
Sourcepub fn discrete_labels(
&self,
include_class_label: bool,
include_id: bool,
) -> Vec<Option<bool>>
pub fn discrete_labels( &self, include_class_label: bool, include_id: bool, ) -> Vec<Option<bool>>
Whether each column is discrete, nothing for the id’s and the class
always discrete: music21’s getDiscreteLabels.
Sourcepub fn class_position_labels(
&self,
include_id: bool,
include_class_label: bool,
) -> Vec<Option<bool>>
pub fn class_position_labels( &self, include_id: bool, include_class_label: bool, ) -> Vec<Option<bool>>
Whether each column is the class’s, nothing for the id’s: music21’s
getClassPositionLabels.
Sourcepub fn features_as_list(
&self,
include_class_label: bool,
include_id: bool,
) -> Vec<Vec<Cell>>
pub fn features_as_list( &self, include_class_label: bool, include_id: bool, ) -> Vec<Vec<Cell>>
The table, a row for each piece: its id, every value of every
feature, and its class value: music21’s getFeaturesAsList.
Sourcepub fn unique_class_values(&self) -> Vec<&str>
pub fn unique_class_values(&self) -> Vec<&str>
Each class value once, in the order first met: music21’s
getUniqueClassValues.
Sourcepub fn to_text(&self, format: OutputFormat) -> String
pub fn to_text(&self, format: OutputFormat) -> String
The table written in a format, ids and classes included, lines
joined with newlines and none after the last: music21’s getString.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DataSet
impl !Sync for DataSet
impl Freeze for DataSet
impl Send for DataSet
impl Unpin for DataSet
impl UnsafeUnpin for DataSet
impl UnwindSafe for DataSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more