Skip to content

Commit

Permalink
make methods and internal documentation consistent between htk and te…
Browse files Browse the repository at this point in the history
…xtgrid.
  • Loading branch information
vocatart committed Nov 26, 2024
1 parent fd0b565 commit 4a53d29
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 122 deletions.
16 changes: 8 additions & 8 deletions htk/annotations.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
package htk

// Annotation contains a starting and ending time in seconds, with a text label.
// Annotation structs contain a starting and ending time in seconds, with a text label.
type Annotation struct {
start float64
end float64
label string
}

// GetDuration gets the total duration of an annotation.
// GetDuration gets the total duration of an Annotation.
func (annotation *Annotation) GetDuration() (result float64) {
return annotation.end - annotation.start
}

// GetStart gets the start time of an annotation.
// GetStart gets the start time of an Annotation.
func (annotation *Annotation) GetStart() float64 {
return annotation.start
}

// SetStart sets the start time of an annotation.
// SetStart sets the start time of an Annotation.
func (annotation *Annotation) SetStart(start float64) {
annotation.start = start
}

// GetEnd gets the end time of an annotation.
// GetEnd gets the end time of an Annotation.
func (annotation *Annotation) GetEnd() float64 {
return annotation.end
}

// SetEnd sets the end time of an annotation.
// SetEnd sets the end time of an Annotation.
func (annotation *Annotation) SetEnd(end float64) {
annotation.end = end
}

// GetLabel gets the label of an annotation.
// GetLabel gets the label of an Annotation.
func (annotation *Annotation) GetLabel() string {
return annotation.label
}

// SetLabel sets the label of an annotation
// SetLabel sets the label of an Annotation.
func (annotation *Annotation) SetLabel(label string) {
annotation.label = label
}
38 changes: 19 additions & 19 deletions htk/lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ import (
"strings"
)

// Lab objects contain a collection of annotations.
// Lab structs are a collection of annotations.
// The HTK Label format is defined at http://www.seas.ucla.edu/spapl/weichu/htkbook/node113_mn.html
type Lab struct {
annotations []Annotation
name string
precision uint8
}

// SetAnnotations sets the annotations of a lab object.
// SetAnnotations sets the annotations field in a Lab.
func (lab *Lab) SetAnnotations(annotations []Annotation) {
lab.annotations = annotations
}

// GetAnnotations gets the annotations of a lab object.
// GetAnnotations gets the annotations field in a Lab.
func (lab *Lab) GetAnnotations() []Annotation {
return lab.annotations
}

// PushAnnotation pushes an annotation to the end of a lab object.
// PushAnnotation pushes a single Annotation into the annotations field of a Lab.
func (lab *Lab) PushAnnotation(annotation Annotation) {
lab.annotations = append(lab.annotations, annotation)
}

// AppendAnnotations appends an annotations object to the end of a lab object.
// AppendAnnotations appends an Annotation slice to the annotations field in a Lab.
func (lab *Lab) AppendAnnotations(annotations []Annotation) {
lab.annotations = append(lab.annotations, annotations...)
}

// ClearAnnotations removes all annotations from a lab object.
// ClearAnnotations removes all annotations in a Lab.
func (lab *Lab) ClearAnnotations() {
lab.annotations = []Annotation{}
lab.annotations = nil
}

// DumpLabels gets all labels in a lab object to a slice.
func (lab *Lab) DumpLabels() []string {
// GetLabels returns the annotations field in a Lab as a slice of strings.
func (lab *Lab) GetLabels() []string {
var result []string

for _, annotation := range lab.annotations {
Expand All @@ -54,27 +54,27 @@ func (lab *Lab) DumpLabels() []string {
return result
}

// GetName gets the name of a lab object.
// GetName gets the name of a Lab.
func (lab *Lab) GetName() string {
return lab.name
}

// SetName sets the name of a lab object.
// SetName sets the name of a Lab.
func (lab *Lab) SetName(name string) {
lab.name = name
}

// GetPrecision gets the precision of a lab object
// GetPrecision gets the precision of a Lab.
func (lab *Lab) GetPrecision() uint8 {
return lab.precision
}

// SetPrecision sets the precision of a lab object.
// SetPrecision sets the precision of a Lab.
func (lab *Lab) SetPrecision(precision uint8) {
lab.precision = precision
}

// GetDuration gets the total duration of a lab by getting the difference in global start and end.
// GetDuration gets the total duration of a Lab by getting the difference in global start and end.
func (lab *Lab) GetDuration() (result float64) {
// calculate using start and end in case lab file doesn't start at 0
start := lab.annotations[0].start
Expand All @@ -83,7 +83,7 @@ func (lab *Lab) GetDuration() (result float64) {
return end - start
}

// GetLength gets the total amount of annotations in a lab file.
// GetLength gets the total amount of annotations in a Lab.
func (lab *Lab) GetLength() (result int) {
return len(lab.annotations)
}
Expand Down Expand Up @@ -142,8 +142,8 @@ func ReadLab(path string) (Lab, error) {
return lab, err
}

// WriteLab writes a lab to a file from a given path. If the file already exists, it will be overwritten unless overwrite is set to false.
// If the path is a directory, the lab will be written to a file with the same name as the lab, in the directory.
// WriteLab writes a Lab to a file from a given path. If the file already exists, it will be overwritten unless overwrite is set to false.
// If the path is a directory, the contents will be written to a file with the same name as the Lab, in the directory.
func (lab *Lab) WriteLab(path string, overwrite ...bool) error {
// if no overwrite is specified, default to false
if len(overwrite) == 0 {
Expand Down Expand Up @@ -225,7 +225,7 @@ func (lab *Lab) ToString() string {
return result
}

// Parses the precision of a lab file based on the context of the time durations.
// parsePrecision retrieves the precision field of a Lab based on the context of the time durations.
func (lab *Lab) parsePrecision(secondTime string) {
periodIndex := strings.Index(secondTime, ".")

Expand All @@ -237,7 +237,7 @@ func (lab *Lab) parsePrecision(secondTime string) {
lab.precision = uint8(len(secondTime) - periodIndex - 1)
}

// Compare two slices to see if they are identical
// isEqualSlice compares two slices, returning true if they are identical.
func isEqualSlice(slice1, slice2 []string) bool {
// if they aren't the same length, we return false right away
if len(slice1) != len(slice2) {
Expand Down
2 changes: 1 addition & 1 deletion htk/lab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestDumpingLabels(t *testing.T) {
if err != nil {
t.Fatal(err)
}
labSlice := lab.DumpLabels()
labSlice := lab.GetLabels()

groundTruthSlice := []string{"test", "test2"}

Expand Down
16 changes: 8 additions & 8 deletions textgrid/interval.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package textgrid

// Interval - annotation that holds start and end values (in seconds), and a string value.
// Interval structs are annotations that hold a start time, end time, and text label.
type Interval struct {
xmin float64
xmax float64
text string
}

// GetDuration - Returns the duration of the interval.
// GetDuration returns the duration of an Interval.
func (interval *Interval) GetDuration() float64 {
return interval.xmax - interval.xmin
}

// GetMedian - Returns the midpoint of the interval.
// GetMedian returns the midpoint of an Interval.
func (interval *Interval) GetMedian() float64 {
return (interval.xmin + interval.xmax) / 2.0
}

// GetXmin - Returns xmin of the interval.
// GetXmin returns xmin of an Interval.
func (interval *Interval) GetXmin() float64 {
return interval.xmin
}

// GetXmax - Returns xmax of the interval.
// GetXmax returns xmax of an Interval.
func (interval *Interval) GetXmax() float64 {
return interval.xmax
}
Expand All @@ -31,17 +31,17 @@ func (interval *Interval) GetText() string {
return interval.text
}

// SetXmin - Sets the xmin value of the interval.
// SetXmin sets xmin of an Interval.
func (interval *Interval) SetXmin(xmin float64) {
interval.xmin = xmin
}

// SetXmax - Sets the xmax value of the inerval.
// SetXmax sets xmax of an Interval.
func (interval *Interval) SetXmax(xmax float64) {
interval.xmax = xmax
}

// SetText - Sets the text of the interval.
// SetText sets the text label of an Interval.
func (interval *Interval) SetText(text string) {
interval.text = text
}
10 changes: 5 additions & 5 deletions textgrid/point.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package textgrid

// Point - A point is a specific time marker with a string value.
// Point structs are annotations that represent a specific point in time, with a text label.
type Point struct {
value float64
mark string
}

// GetValue - Returns the time value of the point.
// GetValue returns value of a Point.
func (point *Point) GetValue() float64 {
return point.value
}

// GetMark - Returns the label mark of the point.
// GetMark returns the text label of a Point.
func (point *Point) GetMark() string {
return point.mark
}

// SetValue - Sets the value of the point.
// SetValue sets the value of a Point.
func (point *Point) SetValue(value float64) {
point.value = value
}

// SetMark - Sets the label mark of the point.
// SetMark sets the mark of a Point.
func (point *Point) SetMark(mark string) {
point.mark = mark
}
Loading

0 comments on commit 4a53d29

Please sign in to comment.