Convert a noteworthy string to a list of noteworthy n-grams.

note_ngram(notes, n = 2, tally = FALSE, rests = FALSE)

Arguments

notes

a noteworthy string.

n

Number of grams. Must be >= 1 and <= number of timesteps in notes.

tally

logical, tally n-grams in a data frame. Otherwise a list.

rests

logical, exclude rests. Affects the number of timesteps.

Value

list of noteworthy objects or a tibble

Examples

x <- as_noteworthy("c r ceg dfa ceg dfa")
note_ngram(x)
#> [[1]]
#> <Noteworthy string>
#>   Format: space-delimited time
#>   Values: c
#> 
#> [[2]]
#> <Noteworthy string>
#>   Format: space-delimited time
#>   Values: c <ceg>
#> 
#> [[3]]
#> <Noteworthy string>
#>   Format: space-delimited time
#>   Values: <ceg> <dfa>
#> 
#> [[4]]
#> <Noteworthy string>
#>   Format: space-delimited time
#>   Values: <dfa> <ceg>
#> 
#> [[5]]
#> <Noteworthy string>
#>   Format: space-delimited time
#>   Values: <ceg> <dfa>
#> 
(x <- note_ngram(x, tally = TRUE))
#> # A tibble: 4 × 2
#>   ngram              n
#>   <list>         <int>
#> 1 <notwrthy [1]>     1
#> 2 <notwrthy [1]>     1
#> 3 <notwrthy [1]>     2
#> 4 <notwrthy [1]>     1
x$ngram <- as.character(x$ngram)
x
#> # A tibble: 4 × 2
#>   ngram       n
#>   <chr>   <int>
#> 1 c           1
#> 2 c ceg       1
#> 3 ceg dfa     2
#> 4 dfa ceg     1