Skip to main content

DataSet

Struct DataSet 

Source
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

Source

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=...).

Source

pub fn class_label(&self) -> &str

The name of the class the set is about.

Source

pub fn extractors(&self) -> &[&'static Extractor]

The extractors, in the order their columns come.

Source

pub fn add_extractors( &mut self, extractors: impl IntoIterator<Item = &'static Extractor>, )

Adds extractors after those already there: music21’s addFeatureExtractors.

Source

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.

Source

pub fn len(&self) -> usize

How many pieces have been added.

Source

pub fn is_empty(&self) -> bool

Whether no piece has been added.

Source

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.

Source

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.

Source

pub fn features(&self) -> &[Vec<Feature>]

The features read, a row for each piece and a feature for each extractor; empty until processed.

Source

pub fn failures(&self) -> &[Failure]

The features Self::process could not read.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn unique_class_values(&self) -> Vec<&str>

Each class value once, in the order first met: music21’s getUniqueClassValues.

Source

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§

Source§

impl Debug for DataSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.