-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.go
78 lines (67 loc) 路 1.97 KB
/
base.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
76
77
78
package textractor
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/textract/types"
)
// base represents the base information shared among different types of blocks.
type base struct {
id string // Identifier for the block
confidence float32 // Confidence for the block
blockType types.BlockType // Type of the block
boundingBox *BoundingBox // Bounding box information
polygon []*Point // Polygon information
page *Page // Page information
raw types.Block // Raw block data
}
// newBase creates a new base instance from the provided Textract block and page information.
func newBase(b types.Block, p *Page) base {
polygon := make([]*Point, len(b.Geometry.Polygon))
for i, p := range b.Geometry.Polygon {
polygon[i] = &Point{
x: p.X,
y: p.Y,
}
}
return base{
id: aws.ToString(b.Id),
confidence: aws.ToFloat32(b.Confidence),
blockType: b.BlockType,
boundingBox: &BoundingBox{
height: b.Geometry.BoundingBox.Height,
left: b.Geometry.BoundingBox.Left,
top: b.Geometry.BoundingBox.Top,
width: b.Geometry.BoundingBox.Width,
},
polygon: polygon,
page: p,
raw: b,
}
}
// ID returns the identifier of the block.
func (b *base) ID() string {
return b.id
}
// Confidence returns the confidence of the block.
func (b *base) Confidence() float32 {
return b.confidence
}
// BlockType returns the type of the block.
func (b *base) BlockType() types.BlockType {
return b.blockType
}
// BoundingBox returns the bounding box information of the block.
func (b *base) BoundingBox() *BoundingBox {
return b.boundingBox
}
// Polygon returns the polygon information of the block.
func (b *base) Polygon() []*Point {
return b.polygon
}
// PageNumber returns the page number associated with the block.
func (b *base) PageNumber() int {
return b.page.Number()
}
// Raw returns the raw block data.
func (b *base) Raw() types.Block {
return b.raw
}