-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.go
More file actions
40 lines (35 loc) · 835 Bytes
/
source.go
File metadata and controls
40 lines (35 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package entitydebs
import (
"slices"
"strings"
)
type (
// source wraps entities and texts, and returns a data [Frames].
source struct {
entity, texts []string
}
)
// NewSource returns a new source, consisting of the entity, its aliases and
// texts. Duplicate entities and surrounding white spaces are removed.
//
// By convention, the first entity is the most well-known.
func NewSource(entity, texts []string) source {
// De-duplicate entities
dedup := make([]string, len(entity))
for i, alias := range entity {
if !slices.Contains(dedup, alias) {
dedup[i] = alias
}
}
// Trim leading and trailing white space.
for i, alias := range dedup {
dedup[i] = strings.TrimSpace(alias)
}
for i, text := range texts {
texts[i] = strings.TrimSpace(text)
}
return source{
entity: dedup,
texts: texts,
}
}