From 988658936cbcd8e92b35a66e1943bea0f9eaf3bc Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 25 Jan 2019 17:41:52 +0000 Subject: gofmt --- avg-lines/html.go | 42 +++++++++++++++++++++--------------------- avg-lines/main.go | 16 ++++++++-------- binarize/binarize.go | 2 +- bucket-lines/bucket.go | 22 ++++++++++++---------- bucket-lines/main.go | 22 +++++++++++----------- lib/hocr/hocr.go | 24 ++++++++++++------------ lib/hocr/lines.go | 12 ++++++------ lib/line/line.go | 12 ++++++------ lib/prob/prob.go | 2 +- 9 files changed, 78 insertions(+), 76 deletions(-) diff --git a/avg-lines/html.go b/avg-lines/html.go index f299830..443cc4a 100644 --- a/avg-lines/html.go +++ b/avg-lines/html.go @@ -10,12 +10,12 @@ import ( func copylineimg(fn string, l line.Detail) error { f, err := os.Create(fn) - if err != nil { - return err - } - defer f.Close() + if err != nil { + return err + } + defer f.Close() - return l.Img.CopyLineTo(f) + return l.Img.CopyLineTo(f) } func htmlout(dir string, lines line.Details) error { @@ -26,28 +26,28 @@ func htmlout(dir string, lines line.Details) error { fn := filepath.Join(dir, "index.html") f, err := os.Create(fn) - if err != nil { - return err - } - defer f.Close() - - _, err = fmt.Fprintf(f, "" + - "\n\n") - if err != nil { - return err - } + if err != nil { + return err + } + defer f.Close() + + _, err = fmt.Fprintf(f, ""+ + "\n
\n") + if err != nil { + return err + } for _, l := range lines { fn = filepath.Base(l.OcrName) + "_" + l.Name + ".png" err = copylineimg(filepath.Join(dir, fn), l) if err != nil { return err } - _, err = fmt.Fprintf(f, "\n" + - "\n" + - "\n" + - "\n" + - "\n", - l.Avgconf, l.OcrName, l.Name, fn, l.Text) + _, err = fmt.Fprintf(f, "\n"+ + "\n"+ + "\n"+ + "\n"+ + "\n", + l.Avgconf, l.OcrName, l.Name, fn, l.Text) if err != nil { return err } diff --git a/avg-lines/main.go b/avg-lines/main.go index a953598..14b21bd 100644 --- a/avg-lines/main.go +++ b/avg-lines/main.go @@ -8,8 +8,8 @@ import ( "path/filepath" "sort" - "rescribe.xyz/go.git/lib/line" "rescribe.xyz/go.git/lib/hocr" + "rescribe.xyz/go.git/lib/line" "rescribe.xyz/go.git/lib/prob" ) @@ -38,13 +38,13 @@ func main() { for _, f := range flag.Args() { var newlines line.Details switch ext := filepath.Ext(f); ext { - case ".prob": - newlines, err = prob.GetLineDetails(f) - case ".hocr": - newlines, err = hocr.GetLineDetails(f) - default: - log.Printf("Skipping file '%s' as it isn't a .prob or .hocr\n", f) - continue + case ".prob": + newlines, err = prob.GetLineDetails(f) + case ".hocr": + newlines, err = hocr.GetLineDetails(f) + default: + log.Printf("Skipping file '%s' as it isn't a .prob or .hocr\n", f) + continue } if err != nil { log.Fatal(err) diff --git a/binarize/binarize.go b/binarize/binarize.go index 0290ef4..f95ee22 100644 --- a/binarize/binarize.go +++ b/binarize/binarize.go @@ -6,8 +6,8 @@ import ( "log" "os" - "github.com/Ernyoke/Imger/threshold" "github.com/Ernyoke/Imger/imgio" + "github.com/Ernyoke/Imger/threshold" ) func main() { diff --git a/bucket-lines/bucket.go b/bucket-lines/bucket.go index bf25405..9f98887 100644 --- a/bucket-lines/bucket.go +++ b/bucket-lines/bucket.go @@ -3,8 +3,8 @@ package main import ( "fmt" "io" - "path/filepath" "os" + "path/filepath" "sort" "strconv" @@ -12,21 +12,23 @@ import ( ) type BucketSpec struct { - Min float64 + Min float64 Name string } type BucketSpecs []BucketSpec -func (b BucketSpecs) Len() int { return len(b) } -func (b BucketSpecs) Swap(i, j int) { b[i], b[j] = b[j], b[i] } + +func (b BucketSpecs) Len() int { return len(b) } +func (b BucketSpecs) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b BucketSpecs) Less(i, j int) bool { return b[i].Min < b[j].Min } type BucketStat struct { name string - num int + num int } type BucketStats []BucketStat -func (b BucketStats) Len() int { return len(b) } -func (b BucketStats) Swap(i, j int) { b[i], b[j] = b[j], b[i] } + +func (b BucketStats) Len() int { return len(b) } +func (b BucketStats) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b BucketStats) Less(i, j int) bool { return b[i].num < b[j].num } // Copies the image and text for a line into a directory based on @@ -51,7 +53,7 @@ func bucketLine(l line.Detail, buckets BucketSpecs, dirname string) (string, err avgstr = avgstr[2:] } - base := filepath.Join(dirname, todir, l.OcrName + "_" + l.Name + "_" + avgstr) + base := filepath.Join(dirname, todir, l.OcrName+"_"+l.Name+"_"+avgstr) err := os.MkdirAll(filepath.Join(dirname, todir), 0700) if err != nil { @@ -103,7 +105,7 @@ func BucketUp(lines line.Details, buckets BucketSpecs, dirname string) (BucketSt for _, b := range all { i := sort.Search(len(stats), func(i int) bool { return stats[i].name == b }) if i == len(stats) { - newstat := BucketStat { b, 0 } + newstat := BucketStat{b, 0} stats = append(stats, newstat) i = len(stats) - 1 } @@ -124,6 +126,6 @@ func PrintBucketStats(w io.Writer, stats BucketStats) { fmt.Fprintf(w, "---------------------------------\n") sort.Sort(stats) for _, s := range stats { - fmt.Fprintf(w, "Lines in %7s: %2d%%\n", s.name, 100 * s.num / total) + fmt.Fprintf(w, "Lines in %7s: %2d%%\n", s.name, 100*s.num/total) } } diff --git a/bucket-lines/main.go b/bucket-lines/main.go index 36e9101..990e84c 100644 --- a/bucket-lines/main.go +++ b/bucket-lines/main.go @@ -9,17 +9,17 @@ import ( "os" "path/filepath" - "rescribe.xyz/go.git/lib/line" "rescribe.xyz/go.git/lib/hocr" + "rescribe.xyz/go.git/lib/line" "rescribe.xyz/go.git/lib/prob" ) func main() { b := BucketSpecs{ // minimum confidence, name - { 0, "bad" }, - { 0.95, "95to98" }, - { 0.98, "98plus" }, + {0, "bad"}, + {0.95, "95to98"}, + {0.98, "98plus"}, } flag.Usage = func() { @@ -61,13 +61,13 @@ func main() { for _, f := range flag.Args() { var newlines line.Details switch ext := filepath.Ext(f); ext { - case ".prob": - newlines, err = prob.GetLineDetails(f) - case ".hocr": - newlines, err = hocr.GetLineDetails(f) - default: - log.Printf("Skipping file '%s' as it isn't a .prob or .hocr\n", f) - continue + case ".prob": + newlines, err = prob.GetLineDetails(f) + case ".hocr": + newlines, err = hocr.GetLineDetails(f) + default: + log.Printf("Skipping file '%s' as it isn't a .prob or .hocr\n", f) + continue } if err != nil { log.Fatal(err) diff --git a/lib/hocr/hocr.go b/lib/hocr/hocr.go index 0d10819..bbcf8a2 100644 --- a/lib/hocr/hocr.go +++ b/lib/hocr/hocr.go @@ -12,27 +12,27 @@ type Hocr struct { } type OcrLine struct { - Class string `xml:"class,attr"` - Id string `xml:"id,attr"` - Title string `xml:"title,attr"` + Class string `xml:"class,attr"` + Id string `xml:"id,attr"` + Title string `xml:"title,attr"` Words []OcrWord `xml:"span"` - Text string `xml:",chardata"` + Text string `xml:",chardata"` } type OcrWord struct { - Class string `xml:"class,attr"` - Id string `xml:"id,attr"` - Title string `xml:"title,attr"` + Class string `xml:"class,attr"` + Id string `xml:"id,attr"` + Title string `xml:"title,attr"` Chars []OcrChar `xml:"span"` - Text string `xml:",chardata"` + Text string `xml:",chardata"` } type OcrChar struct { - Class string `xml:"class,attr"` - Id string `xml:"id,attr"` - Title string `xml:"title,attr"` + Class string `xml:"class,attr"` + Id string `xml:"id,attr"` + Title string `xml:"title,attr"` Chars []OcrChar `xml:"span"` - Text string `xml:",chardata"` + Text string `xml:",chardata"` } // Returns the confidence for a word based on its x_wconf value diff --git a/lib/hocr/lines.go b/lib/hocr/lines.go index 84c2130..00acd1f 100644 --- a/lib/hocr/lines.go +++ b/lib/hocr/lines.go @@ -36,27 +36,27 @@ func parseLineDetails(h Hocr, i image.Image, name string) (line.Details, error) var ln line.Detail ln.Name = l.Id - ln.Avgconf = (totalconf/float64(num)) / 100 + ln.Avgconf = (totalconf / float64(num)) / 100 linetext := "" linetext = l.Text - if(noText(linetext)) { + if noText(linetext) { linetext = "" for _, w := range l.Words { - if(w.Class != "ocrx_word") { + if w.Class != "ocrx_word" { continue } linetext += w.Text + " " } } - if(noText(linetext)) { + if noText(linetext) { linetext = "" for _, w := range l.Words { - if(w.Class != "ocrx_word") { + if w.Class != "ocrx_word" { continue } for _, c := range w.Chars { - if(c.Class != "ocrx_cinfo") { + if c.Class != "ocrx_cinfo" { continue } linetext += c.Text diff --git a/lib/line/line.go b/lib/line/line.go index 3adac0a..656fbce 100644 --- a/lib/line/line.go +++ b/lib/line/line.go @@ -8,15 +8,15 @@ import ( ) type Detail struct { - Name string + Name string Avgconf float64 - Img CopyableImg - Text string + Img CopyableImg + Text string OcrName string } type CopyableImg interface { - CopyLineTo(io.Writer) (error) + CopyLineTo(io.Writer) error } type Details []Detail @@ -38,7 +38,7 @@ type ImgDirect struct { Img image.Image } -func (i ImgDirect) CopyLineTo(w io.Writer) (error) { +func (i ImgDirect) CopyLineTo(w io.Writer) error { err := png.Encode(w, i.Img) if err != nil { return err @@ -52,7 +52,7 @@ type ImgPath struct { Path string } -func (i ImgPath) CopyLineTo(w io.Writer) (error) { +func (i ImgPath) CopyLineTo(w io.Writer) error { f, err := os.Open(i.Path) if err != nil { return err diff --git a/lib/prob/prob.go b/lib/prob/prob.go index 2fd7fb9..31a484d 100644 --- a/lib/prob/prob.go +++ b/lib/prob/prob.go @@ -14,7 +14,7 @@ func getLineAvg(f string) (float64, error) { num := 0 prob, err := ioutil.ReadFile(f) - if err != nil { + if err != nil { return 0, err } -- cgit v1.2.1-24-ge1ad

%.4f%%

%s %s
%s

%.4f%%

%s %s
%s