diff options
author | Nick White <git@njw.name> | 2020-01-21 16:39:36 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2020-01-21 16:39:36 +0000 |
commit | bd8e705822f859dc3c3708081aeaf0a8c9902f62 (patch) | |
tree | 549662a985c7e28c6929b00495c455d363062391 /cmd/pagegraph | |
parent | 0de321abc7bb832db09b22f937f31d30e52f4365 (diff) |
Add pagegraph tool
Diffstat (limited to 'cmd/pagegraph')
-rw-r--r-- | cmd/pagegraph/main.go | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/cmd/pagegraph/main.go b/cmd/pagegraph/main.go new file mode 100644 index 0000000..fb2648f --- /dev/null +++ b/cmd/pagegraph/main.go @@ -0,0 +1,82 @@ +package main + +import ( + "flag" + "fmt" + "log" + "os" + "path/filepath" + "strings" + + "rescribe.xyz/bookpipeline" + "rescribe.xyz/utils/pkg/hocr" +) + +func walker(confs *[]*bookpipeline.Conf) filepath.WalkFunc { + return func(path string, info os.FileInfo, err error) error { + if info.IsDir() { + return nil + } + if !strings.HasSuffix(path, ".hocr") { + return nil + } + avg, err := hocr.GetAvgConf(path) + if err != nil { + if err.Error() == "No words found" { + return nil + } + return err + } + c := bookpipeline.Conf{ + Conf: avg, + Path: path, + } + *confs = append(*confs, &c) + return nil + } +} + +func main() { + flag.Usage = func() { + fmt.Fprintln(flag.CommandLine.Output(), "Usage: pagegraph file.hocr graph.png") + flag.PrintDefaults() + } + flag.Parse() + + if flag.NArg() != 2 { + flag.Usage() + return + } + + wordconfs, err := hocr.GetWordConfs(flag.Arg(0)) + if err != nil { + log.Fatal(err) + } + var confs []*bookpipeline.Conf + for n, wc := range wordconfs { + c := bookpipeline.Conf{ + Conf: wc, + //Path: "fakepath", + Path: fmt.Sprintf("word_%d", n), + } + confs = append(confs, &c) + } + + // Structure to fit what bookpipeline.Graph needs + // TODO: probably reorganise bookpipeline to just need []*Conf + cconfs := make(map[string]*bookpipeline.Conf) + for _, c := range confs { + cconfs[c.Path] = c + } + + fn := flag.Arg(1) + f, err := os.Create(fn) + if err != nil { + log.Fatalln("Error creating file", fn, err) + } + defer f.Close() + err = bookpipeline.GraphOpts(cconfs, filepath.Base(flag.Arg(0)), "Word number", false, f) + if err != nil { + log.Fatalln("Error creating graph", err) + } +} |