summaryrefslogtreecommitdiff
path: root/lib/prob
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-10-08 12:52:33 +0100
committerNick White <git@njw.name>2019-10-08 12:52:33 +0100
commit7482157a03ed3e9d7f45e54a126b391001f34948 (patch)
tree52f87b9ca159fe4c04a0349de95ea9de82692b3c /lib/prob
parentd43c11bf653bfe3c1ad1ed277f1ec08bf155cf98 (diff)
Separate out bookpipeline from catch-all go.git repo, and rename to rescribe.xyz/bookpipeline
The dependencies from the go.git repo will follow in due course.
Diffstat (limited to 'lib/prob')
-rw-r--r--lib/prob/prob.go69
1 files changed, 0 insertions, 69 deletions
diff --git a/lib/prob/prob.go b/lib/prob/prob.go
deleted file mode 100644
index 31a484d..0000000
--- a/lib/prob/prob.go
+++ /dev/null
@@ -1,69 +0,0 @@
-package prob
-
-import (
- "io/ioutil"
- "path/filepath"
- "strconv"
- "strings"
-
- "rescribe.xyz/go.git/lib/line"
-)
-
-func getLineAvg(f string) (float64, error) {
- totalconf := float64(0)
- num := 0
-
- prob, err := ioutil.ReadFile(f)
- if err != nil {
- return 0, err
- }
-
- for _, l := range strings.Split(string(prob), "\n") {
- fields := strings.Fields(l)
-
- if len(fields) == 2 {
- conf, err := strconv.ParseFloat(fields[1], 64)
- if err != nil {
- continue
- }
- totalconf += conf
- num += 1
- }
- }
- if num <= 0 {
- return 0, nil
- }
- avg := totalconf / float64(num)
- return avg, nil
-}
-
-// Note this only processes one line at a time
-func GetLineDetails(probfn string) (line.Details, error) {
- var l line.Detail
- lines := make(line.Details, 0)
-
- avg, err := getLineAvg(probfn)
- if err != nil {
- return lines, err
- }
-
- filebase := strings.Replace(probfn, ".prob", "", 1)
-
- txt, err := ioutil.ReadFile(filebase + ".txt")
- if err != nil {
- return lines, err
- }
-
- l.Name = filepath.Base(filebase)
- l.Avgconf = avg
- l.Text = string(txt)
- l.OcrName = filepath.Base(filepath.Dir(filebase))
-
- var imgfn line.ImgPath
- imgfn.Path = filebase + ".bin.png"
- l.Img = imgfn
-
- lines = append(lines, l)
-
- return lines, nil
-}