-
Notifications
You must be signed in to change notification settings - Fork 1
/
detect_zawgyi.go
50 lines (43 loc) · 1.09 KB
/
detect_zawgyi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bufio"
"fmt"
"github.com/google/myanmar-tools/clients/go"
"io/ioutil"
"os"
"regexp"
)
func main() {
const ytidsFilename = "myanmar_ytids.dat"
const subFormat = "vtt"
var subs string
var ytids []string
re := regexp.MustCompile("\n00:[^\n]+\n")
zgDetector := myanmartools.NewZawgyiDetector()
fytids, err := os.Open(ytidsFilename)
if err != nil {
fmt.Println("Could not open file %s", ytidsFilename)
return
}
defer fytids.Close()
fileScanner := bufio.NewScanner(fytids)
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
ytids = append(ytids, fileScanner.Text())
}
var fname string
for _, ytid := range ytids {
fname = "subs_original/" + ytid + ".my." + subFormat
data, err := ioutil.ReadFile(fname)
if err != nil {
fmt.Printf("%s\tNOT FOUND\n", ytid)
continue
}
subs = string(data)
// Remove subtitle timestamps to speed up detection
// Not quite sure whether the time savings are actually worth it
subs = re.ReplaceAllString(subs, "")
score := zgDetector.GetZawgyiProbability(subs)
fmt.Printf("%s\t%f\n", ytid, score)
}
}