Akron | 8e1d69b | 2021-08-12 17:38:49 +0200 | [diff] [blame^] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | |
| 6 | datok "github.com/KorAP/datokenizer" |
| 7 | "github.com/alecthomas/kong" |
| 8 | ) |
| 9 | |
| 10 | var cli struct { |
| 11 | Tokenizer string `kong:"required,short='t',help='The Double Array Tokenizer file'"` |
| 12 | } |
| 13 | |
| 14 | // Main method for command line handling |
| 15 | func main() { |
| 16 | |
| 17 | // Parse command line parameters |
| 18 | parser := kong.Must( |
| 19 | &cli, |
| 20 | kong.Name("datok"), |
| 21 | kong.Description("Double Array based tokenizer"), |
| 22 | kong.UsageOnError(), |
| 23 | ) |
| 24 | |
| 25 | _, err := parser.Parse(os.Args[1:]) |
| 26 | |
| 27 | parser.FatalIfErrorf(err) |
| 28 | |
| 29 | // Load the Datok file |
| 30 | dat := datok.LoadDatokFile(cli.Tokenizer) |
| 31 | |
| 32 | // Unable to load the datok file |
| 33 | if dat == nil { |
| 34 | os.Exit(1) |
| 35 | } |
| 36 | |
| 37 | // Program is running in a pipe |
| 38 | fileInfo, _ := os.Stdin.Stat() |
| 39 | if fileInfo.Mode()&os.ModeCharDevice == 0 { |
| 40 | |
| 41 | // Transduce from STDIN and write to STDOUT |
| 42 | dat.Transduce(os.Stdin, os.Stdout) |
| 43 | } |
| 44 | } |