Skip to content

Commit

Permalink
Add concatenated text output to rescribe output dir, called bookname.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjwhite committed Feb 6, 2024
1 parent 7ae64e3 commit 47bbea7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/rescribe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ func startProcess(ctx context.Context, logger *log.Logger, tessCommand string, b
return fmt.Errorf("Error looking for .hocr files: %v", err)
}

err = addFullTxt(hocrs, bookname)
if err != nil {
log.Fatalf("Error creating full txt version: %v", err)
}

for _, v := range hocrs {
err = addTxtVersion(v)
if err != nil {
Expand Down Expand Up @@ -660,6 +665,32 @@ func addTxtVersion(hocrfn string) error {
return nil
}

func addFullTxt(hocrs []string, bookname string) error {
if len(hocrs) == 0 {
return nil
}
var full string
for i, v := range hocrs {
t, err := hocr.GetText(v)
if err != nil {
return fmt.Errorf("Error getting text from hocr file %s: %v", v, err)
}
if i > 0 {
full += "\n"
}
full += t
}

dir := filepath.Dir(hocrs[0])
fn := filepath.Join(dir, bookname+".txt")
err := ioutil.WriteFile(fn, []byte(full), 0644)
if err != nil {
return fmt.Errorf("Error creating text file %s: %v", fn, err)
}

return nil
}

func uploadbook(ctx context.Context, dir string, name string, conn Pipeliner, nowipe bool) error {
_, err := os.Stat(dir)
if err != nil && !os.IsExist(err) {
Expand Down

0 comments on commit 47bbea7

Please sign in to comment.