-
Notifications
You must be signed in to change notification settings - Fork 0
/
document.go
75 lines (53 loc) 路 1.44 KB
/
document.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package textractor
import (
"strings"
"github.com/hupe1980/go-textractor/internal"
)
type Document struct {
pages []*Page
}
func (d *Document) Pages() []*Page {
return d.pages
}
func (d *Document) Words() []*Word {
words := make([][]*Word, 0, len(d.Pages()))
for _, p := range d.Pages() {
words = append(words, p.Words())
}
return internal.Concatenate(words...)
}
func (d *Document) Lines() []*Line {
lines := make([][]*Line, 0, len(d.Pages()))
for _, p := range d.Pages() {
lines = append(lines, p.Lines())
}
return internal.Concatenate(lines...)
}
func (d *Document) Tables() []*Table {
tables := make([][]*Table, 0, len(d.Pages()))
for _, p := range d.Pages() {
tables = append(tables, p.Tables())
}
return internal.Concatenate(tables...)
}
func (d *Document) KeyValues() []*KeyValue {
keyValues := make([][]*KeyValue, 0, len(d.Pages()))
for _, p := range d.Pages() {
keyValues = append(keyValues, p.KeyValues())
}
return internal.Concatenate(keyValues...)
}
func (d *Document) Signatures() []*Signature {
signatures := make([][]*Signature, 0, len(d.Pages()))
for _, p := range d.Pages() {
signatures = append(signatures, p.Signatures())
}
return internal.Concatenate(signatures...)
}
func (d *Document) Text(optFns ...func(*TextLinearizationOptions)) string {
pageTexts := make([]string, len(d.Pages()))
for i, p := range d.Pages() {
pageTexts[i] = p.Text(optFns...)
}
return strings.Join(pageTexts, "\n")
}