Merged in feature/postprocessing (pull request #114)
Feature/postprocessing * tests * passtest * fixshorttests * mosttests * improvingbasedockerfile * testspeeds * testing * host * canparallel * clean * passfullsuite * singlepagemax * test * findfeatures * findstables * tbls * tablestoo * tablestoo * lateraltests * tableloc * cleanup * inlinetable * childids * cleanup * tests
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package documenttext
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
documenttypes "queryorchestration/internal/document/types"
|
||||
)
|
||||
|
||||
func (s *Service) getDocumentText(ctx context.Context, doc documenttypes.File) (io.Reader, error) {
|
||||
pagesNum, err := doc.GetPageCount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
textPages := make([]string, pagesNum)
|
||||
for i := range pagesNum {
|
||||
text, err := s.getPageText(ctx, doc, i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textPages[i] = text
|
||||
}
|
||||
|
||||
text, err := s.mergeDocument(textPages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return text, nil
|
||||
}
|
||||
|
||||
func (s *Service) mergeDocument(pages []string) (io.Reader, error) {
|
||||
var builder strings.Builder
|
||||
for i, page := range pages {
|
||||
builder.WriteString(fmt.Sprintf("Start of Page No. = %d\n\n", i+1))
|
||||
builder.WriteString(page)
|
||||
builder.WriteString("\n\n")
|
||||
}
|
||||
return strings.NewReader(builder.String()), nil
|
||||
}
|
||||
Reference in New Issue
Block a user