docextractionflow

package
v1.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hostname = docextractionflowapi.Hostname
	Version  = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate

type Intermediate struct {
	*connector.Connector
	ToDo
}

Intermediate extends and customizes the generic base connector.

func NewIntermediate

func NewIntermediate(impl ToDo) *Intermediate

NewIntermediate creates a new instance of the intermediate.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) DocExtraction

func (svc *Mock) DocExtraction(ctx context.Context) (graph *workflow.Graph, err error)

DocExtraction returns the workflow graph, or a mocked graph if MockDocExtraction was called.

func (*Mock) IdentifyChunks

func (svc *Mock) IdentifyChunks(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)

IdentifyChunks executes the mock handler.

func (*Mock) JoinDocTranscriptions

func (svc *Mock) JoinDocTranscriptions(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)

JoinDocTranscriptions executes the mock handler.

func (*Mock) JoinPageTranscriptions

func (svc *Mock) JoinPageTranscriptions(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)

JoinPageTranscriptions executes the mock handler.

func (*Mock) MockDocExtraction

func (svc *Mock) MockDocExtraction(handler func(ctx context.Context, flow *workflow.Flow, pdf []byte) (docTranscription string, pageCount int, err error)) *Mock

MockDocExtraction sets up a mock handler for the DocExtraction workflow. The handler receives typed inputs from the workflow's state and returns typed outputs. A nil handler clears the mock.

func (*Mock) MockIdentifyChunks

func (svc *Mock) MockIdentifyChunks(handler func(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)) *Mock

MockIdentifyChunks sets up a mock handler for IdentifyChunks.

func (*Mock) MockJoinDocTranscriptions

func (svc *Mock) MockJoinDocTranscriptions(handler func(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)) *Mock

MockJoinDocTranscriptions sets up a mock handler for JoinDocTranscriptions.

func (*Mock) MockJoinPageTranscriptions

func (svc *Mock) MockJoinPageTranscriptions(handler func(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)) *Mock

MockJoinPageTranscriptions sets up a mock handler for JoinPageTranscriptions.

func (*Mock) MockScanPDF

func (svc *Mock) MockScanPDF(handler func(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error)) *Mock

MockScanPDF sets up a mock handler for ScanPDF.

func (*Mock) MockTranscribeChunk

func (svc *Mock) MockTranscribeChunk(handler func(ctx context.Context, flow *workflow.Flow, page []byte, chunk docextractionflowapi.Rectangle) (listTranscriptions []string, err error)) *Mock

MockTranscribeChunk sets up a mock handler for TranscribeChunk.

func (*Mock) OnShutdown

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Mock) OnStartup

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Mock) ScanPDF

func (svc *Mock) ScanPDF(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error)

ScanPDF executes the mock handler.

func (*Mock) TranscribeChunk

func (svc *Mock) TranscribeChunk(ctx context.Context, flow *workflow.Flow, page []byte, chunk docextractionflowapi.Rectangle) (listTranscriptions []string, err error)

TranscribeChunk executes the mock handler.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove
}

Service implements docextractionflow.verify, a simulated document-extraction pipeline that exercises nested forEach fan-out (pages, then chunks) with two levels of explicit fan-in, per-chunk simulated latency, and a 5% failure rate with bounded retry.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) DocExtraction

func (svc *Service) DocExtraction(ctx context.Context) (graph *workflow.Graph, err error)

DocExtraction defines the graph: ScanPDF -forEach(pageImages as page)-> IdentifyChunks -forEach(chunks as chunk)-> TranscribeChunk -[fan-in]-> JoinPageTranscriptions -[fan-in]-> JoinDocTranscriptions.

func (*Service) IdentifyChunks

func (svc *Service) IdentifyChunks(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)

IdentifyChunks runs once per page. It simulates region detection, returning 2-5 chunk rectangles. It is the inner forEach source over chunks.

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service

Init enables a single-statement pattern for initializing the microservice.

func (*Service) JoinDocTranscriptions

func (svc *Service) JoinDocTranscriptions(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)

JoinDocTranscriptions is the outer fan-in (over all pages). It joins the page texts into the final document transcription, one page per line.

func (*Service) JoinPageTranscriptions

func (svc *Service) JoinPageTranscriptions(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)

JoinPageTranscriptions is the inner fan-in (over a page's chunks). It joins the page's chunk transcriptions and contributes the page text as the single-element listPageTexts delta (append reducer at the outer fan-in).

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Service) ScanPDF

func (svc *Service) ScanPDF(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error)

ScanPDF is the entry task. It simulates rasterizing a PDF: a ~100ms delay, then 5-22 pages of random image data (~50-150 KB each). It is the forEach source over pages.

func (*Service) TranscribeChunk

func (svc *Service) TranscribeChunk(ctx context.Context, flow *workflow.Flow, page []byte, chunk docextractionflowapi.Rectangle) (listTranscriptions []string, err error)

TranscribeChunk runs once per chunk. It simulates OCR latency (50-150ms) and a 5% failure rate; on failure it retries via flow.Retry (100 attempts, constant 500ms, no backoff). On success it contributes one transcription as the single-element listTranscriptions delta (append reducer at fan-in).

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	ScanPDF(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error)                                         // MARKER: ScanPDF
	IdentifyChunks(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)                            // MARKER: IdentifyChunks
	TranscribeChunk(ctx context.Context, flow *workflow.Flow, page []byte, chunk docextractionflowapi.Rectangle) (listTranscriptions []string, err error) // MARKER: TranscribeChunk
	JoinPageTranscriptions(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)                     // MARKER: JoinPageTranscriptions
	JoinDocTranscriptions(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)                          // MARKER: JoinDocTranscriptions
	DocExtraction(ctx context.Context) (graph *workflow.Graph, err error)                                                                                 // MARKER: DocExtraction
}

ToDo is implemented by the service or mock.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL