2020-01-09 01:21:09 +01:00
|
|
|
package classify
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2020-04-17 21:20:38 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2020-01-09 01:21:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Label represents a MediaFile label (automatically created).
|
|
|
|
type Label struct {
|
|
|
|
Name string `json:"label"` // Label name
|
|
|
|
Source string `json:"source"` // Where was this label found / detected?
|
|
|
|
Uncertainty int `json:"uncertainty"` // >= 0
|
|
|
|
Priority int `json:"priority"` // >= 0
|
|
|
|
Categories []string `json:"categories"` // List of similar labels
|
|
|
|
}
|
|
|
|
|
2020-07-11 23:43:29 +02:00
|
|
|
// LocationLabel returns a new location label.
|
2020-01-09 01:21:09 +01:00
|
|
|
func LocationLabel(name string, uncertainty int, priority int) Label {
|
|
|
|
if index := strings.Index(name, " / "); index > 1 {
|
|
|
|
name = name[:index]
|
|
|
|
}
|
|
|
|
|
|
|
|
if index := strings.Index(name, " - "); index > 1 {
|
|
|
|
name = name[:index]
|
|
|
|
}
|
|
|
|
|
2020-05-14 11:57:26 +02:00
|
|
|
label := Label{Name: name, Source: SrcLocation, Uncertainty: uncertainty, Priority: priority}
|
2020-01-09 01:21:09 +01:00
|
|
|
|
|
|
|
return label
|
|
|
|
}
|
2020-04-17 21:20:38 +02:00
|
|
|
|
|
|
|
// Title returns a formatted label title as string.
|
|
|
|
func (l Label) Title() string {
|
2020-04-26 14:31:33 +02:00
|
|
|
return txt.Title(txt.Clip(l.Name, txt.ClipDefault))
|
2020-04-17 21:20:38 +02:00
|
|
|
}
|