Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Jan 4, 2024
1 parent 7ece286 commit 0be3c84
Show file tree
Hide file tree
Showing 22 changed files with 115,824 additions and 107 deletions.
6 changes: 3 additions & 3 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type base struct {
confidence float64 // Confidence for the block
blockType types.BlockType // Type of the block
boundingBox *BoundingBox // Bounding box information
polygon []*Point // Polygon information
polygon Polygon // 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))
polygon := make(Polygon, len(b.Geometry.Polygon))
for i, p := range b.Geometry.Polygon {
polygon[i] = &Point{
x: float64(p.X),
Expand Down Expand Up @@ -63,7 +63,7 @@ func (b *base) BoundingBox() *BoundingBox {
}

// Polygon returns the polygon information of the block.
func (b *base) Polygon() []*Point {
func (b *base) Polygon() Polygon {
return b.polygon
}

Expand Down
2 changes: 1 addition & 1 deletion base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestBase(t *testing.T) {
})

t.Run("PolygonMethod", func(t *testing.T) {
polygon := []*Point{{1, 2}, {3, 4}}
polygon := Polygon{{1, 2}, {3, 4}}
b := base{polygon: polygon}
assert.Equal(t, polygon, b.Polygon(), "Polygon method does not return expected value")
})
Expand Down
72 changes: 33 additions & 39 deletions examples/analyze_document_for_llm/sample_output.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Request for Verification of Employment
Privacy Act Notice: This information is to be used by the agency collecting it or its assignees in determining whether you qualify as a prospective mortgagor under its program. It will not be disclosed outside the agency except as required and permitted by law. You do not have to provide this information, but if you do not your application for approval as a prospec- tive mortgagor or borrower may be delayed or rejected. The information requested in this form is authorized by Title 38, USC, Chapter 37 (if VA); by 12 USC, Section 1701 et. seq. (if HUD/FHA); by 42 USC, Section 1452b (if HUD/CPD); and Title 42 USC, 1471 et. seq., or 7 USC, 1921 et. seq. (if USDA/FmHA).
Instructions: Lender - Complete items 1 through 7. Have applicant complete item 8. Forward directly to employer named in item 1. Employer - Please complete either Part II or Part III as applicable. Complete Part IV and return directly to lender named in item 2. The form is to be transmitted directly to the lender and is not to be transmitted through the applicant or any other party.


Part I - Request

1. To (Name and address of employer) Alejandro Rosalez 123 Any Street, Any Town, USA
Expand All @@ -19,9 +17,7 @@ I certify that this verification has been sent directly to the employer and has

5. Date 12/12/2006

6. Lender's Number (Optional) 5555-5555-5555

I have applied for a mortgage loan and stated that I am now or was formerly employed by you. My signature below authorizes verification of this information.
6. Lender's Number (Optional) 5555-5555-5555 I have applied for a mortgage loan and stated that I am now or was formerly employed by you. My signature below authorizes verification of this information.

7. Name and Address of Applicant (include employee or badge number) Paulo Santos 123 Any Street, Any Town, USA

Expand All @@ -43,54 +39,54 @@ Part II - Verification of Present Employment

14. If Overtime or Bonus is Applicable,

Annual [X]
[X] Annual

Hourly [ ]
[ ] Hourly

Pay Grade

10

Is Its Continuance Likely?

Monthly [ ]
[ ] Monthly

Other (Specify) [ ]
[ ] Other (Specify)

Type

Monthly Amount

Overtime

Yes [X]
[X] Yes

No [ ]
[ ] No

Weekly [ ]
[ ] Weekly

Bonus

Yes [ ]
[ ] Yes

No [X]

Base Pay $ 520

15. If paid hourly - average hours per week 40 hours

12B. Gross Earnings
[X] No

Type

Year To Date

12B. Gross Earnings

Past Year

Past Year

Base Pay $ 520

Rations $ 162

15. If paid hourly - average hours per week 40 hours

Base Pay

$
Expand Down Expand Up @@ -123,10 +119,10 @@ $

30.00

17. Projected amount of next pay increase $ 5600

Quarters $ 986

17. Projected amount of next pay increase $ 5600

Commissions

$
Expand All @@ -143,42 +139,42 @@ Pro Pay $ 123

18. Date of applicant's last pay increase 09/08/2006

Overseas or Combat $ 645
Total

Bonus

$

$ 70.00

20.00

$ 80.00

$

20.00

$

15.00
$

19. Amount of last pay increase $ 4800
90.00

Total
15.00

$ 70.00
Variable Housing Allowance $ 587

$ 80.00
Overseas or Combat $ 645

$
19. Amount of last pay increase $ 4800

90.00

Variable Housing Allowance $ 587
20. Remarks (If employee was off work for any length of time, please indicate time period and reason) Not Applicable
Part III - Verification of Previous Employment


21. Date Hired 04/04/2004

23. Salary/Wage at Termination Per (Year) (Month) (Week)
21. Date Hired 04/04/200423. Salary/Wage at Termination Per (Year) (Month) (Week)

22. Date Terminated 01/03/2005

Expand All @@ -194,11 +190,7 @@ Bonus 4000

25. Position Held Device Operator

Part IV - Authorized Signature - Federal statutes provide severe penalties for any fraud, intentional misrepresentation, or criminal connivance

or conspiracy purposed to influence the issuance of any guaranty or insurance by the VA Secretary, the U.S.D.A., FmHA/FHA Commissioner, or

the HUD/CPD Assistant Secretary.
Part IV - Authorized Signature - Federal statutes provide severe penalties for any fraud, intentional misrepresentation, or criminal connivance or conspiracy purposed to influence the issuance of any guaranty or insurance by the VA Secretary, the U.S.D.A., FmHA/FHA Commissioner, or the HUD/CPD Assistant Secretary.

26. Signature of Employer Richard Roe

Expand All @@ -211,4 +203,6 @@ the HUD/CPD Assistant Secretary.
29. Print or type name signed in Item 26 Richard Roe

30. Phone No. 555-0100


Form 1005 July 96
9 changes: 1 addition & 8 deletions examples/analyze_document_signatures/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"log"
"os"
"strings"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/textract"
Expand Down Expand Up @@ -56,13 +55,7 @@ func main() {
for _, s := range p.Signatures() {
fmt.Printf("ID: %s\n", s.ID())
fmt.Printf("BoundingBox: %s\n", s.BoundingBox())

points := make([]string, len(s.Polygon()))
for i, point := range s.Polygon() {
points[i] = point.String()
}

fmt.Printf("Polygon: [%s]\n", strings.Join(points, ", "))
fmt.Printf("Polygon: %s\n", s.Polygon())
fmt.Println()
}

Expand Down
7 changes: 6 additions & 1 deletion expense_document.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package textractor

type ExpenseDocument struct {
document *Document
document *Document
summaryField []*ExpenseField
}

func (ed *ExpenseDocument) SummaryFields() []*ExpenseField {
return ed.summaryField
}
3 changes: 3 additions & 0 deletions expense_field.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package textractor

type ExpenseField struct{}
12 changes: 12 additions & 0 deletions geometry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package textractor
import (
"fmt"
"math"
"strings"
)

type BoundingBox struct {
Expand Down Expand Up @@ -121,6 +122,17 @@ func NewEnclosingBoundingBox[T BoundingBoxAccessor](accessors ...T) *BoundingBox
}
}

type Polygon []*Point

func (p Polygon) String() string {
points := make([]string, len(p))
for i, point := range p {
points[i] = point.String()
}

return fmt.Sprintf("[%s]", strings.Join(points, ", "))
}

// Point represents a 2D point.
type Point struct {
x, y float64
Expand Down
4 changes: 2 additions & 2 deletions identity_document_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type IdentityDocumentField struct {
fieldType IdentityDocumentFieldType
value string
confidence float32
confidence float64
normalizedValue *NormalizedIdentityDocumentFieldValue
raw types.IdentityDocumentField
}
Expand All @@ -26,7 +26,7 @@ func (idf *IdentityDocumentField) Value() string {
}

// Confidence returns the confidence score associated with the field extraction.
func (idf *IdentityDocumentField) Confidence() float32 {
func (idf *IdentityDocumentField) Confidence() float64 {
return idf.confidence
}

Expand Down
4 changes: 2 additions & 2 deletions identity_document_filed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func TestIdentityDocumentField(t *testing.T) {
identityField := &IdentityDocumentField{
fieldType: IdentityDocumentFieldType(aws.ToString(rawField.Type.Text)),
value: aws.ToString(rawField.ValueDetection.Text),
confidence: aws.ToFloat32(rawField.ValueDetection.Confidence),
confidence: float64(aws.ToFloat32(rawField.ValueDetection.Confidence)),
normalizedValue: normalizedValue,
raw: rawField,
}

// Test methods of IdentityDocumentField
assert.Equal(t, IdentityDocumentFieldTypeDateOfBirth, identityField.FieldType())
assert.Equal(t, "1990-01-01T15:04:05", identityField.Value())
assert.Equal(t, float32(0.95), identityField.Confidence())
assert.InDelta(t, 0.95, identityField.Confidence(), 0.000001)
assert.True(t, identityField.IsNormalized())
assert.Equal(t, normalizedValue, identityField.NormalizedValue())
}
Expand Down
2 changes: 1 addition & 1 deletion identity_document_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (idp *identityDocumentParser) createFields() ([]*IdentityDocumentField, map
field := &IdentityDocumentField{
fieldType: fieldType,
value: aws.ToString(f.ValueDetection.Text),
confidence: aws.ToFloat32(f.ValueDetection.Confidence),
confidence: float64(aws.ToFloat32(f.ValueDetection.Confidence)),
raw: f,
}

Expand Down
12 changes: 10 additions & 2 deletions key_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (kv *KeyValue) BoundingBox() *BoundingBox {
return NewEnclosingBoundingBox[BoundingBoxAccessor](kv.Key(), kv.Value())
}

func (kv *KeyValue) Polygon() []*Point {
func (kv *KeyValue) Polygon() Polygon {
// TODO
panic("not implemented")
}
Expand All @@ -61,13 +61,21 @@ func (kv *KeyValue) Text(optFns ...func(*TextLinearizationOptions)) string {
}

keyText := kv.Key().Text()
keyText = fmt.Sprintf("%s%s%s", opts.KeyPrefix, keyText, opts.KeySuffix)

valueText := kv.Value().Text()
valueText = fmt.Sprintf("%s%s%s", opts.ValuePrefix, valueText, opts.ValueSuffix)

if len(keyText) == 0 && len(valueText) == 0 {
return ""
}

return fmt.Sprintf("%s %s", keyText, valueText)
text := fmt.Sprintf("%s%s%s", keyText, opts.SameParagraphSeparator, valueText)
if kv.Value().SelectionElement() != nil {
text = fmt.Sprintf("%s%s%s", valueText, opts.SameParagraphSeparator, keyText)
}

return fmt.Sprintf("%s%s%s", opts.KeyValuePrefix, text, opts.KeyValueSuffix)
}

func (kv *KeyValue) String() string {
Expand Down
2 changes: 1 addition & 1 deletion layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func groupElementsHorizontally(elements []LayoutChild, overlapRatio float64) [][
func partOfSameParagraph(child1, child2 LayoutChild, options TextLinearizationOptions) bool {
if child1 != nil && child2 != nil {
return math.Abs(child1.BoundingBox().Left()-child2.BoundingBox().Left()) <= options.HeuristicHTolerance*child1.BoundingBox().Width() &&
math.Abs(child1.BoundingBox().Top()-child2.BoundingBox().Top()) <= options.HeuristicOverlapRatio*math.Min(child1.BoundingBox().Height(), child2.BoundingBox().Height())
math.Abs(child1.BoundingBox().Top()+child1.BoundingBox().Height()-child2.BoundingBox().Top()) <= options.HeuristicOverlapRatio*math.Min(child1.BoundingBox().Height(), child2.BoundingBox().Height())
}

return false
Expand Down

0 comments on commit 0be3c84

Please sign in to comment.