Replace zerolog with log
diff --git a/cmd/datok.go b/cmd/datok.go
index 489808b..8b75dd3 100644
--- a/cmd/datok.go
+++ b/cmd/datok.go
@@ -4,9 +4,10 @@
"fmt"
"os"
+ "log"
+
datok "github.com/KorAP/datokenizer"
"github.com/alecthomas/kong"
- "github.com/rs/zerolog/log"
)
var cli struct {
@@ -37,14 +38,12 @@
if ctx.Command() == "convert" {
tok := datok.LoadFomaFile(cli.Convert.Foma)
if tok == nil {
- log.Error().Msg("Unable to load foma file")
- os.Exit(1)
+ log.Fatalln("Unable to load foma file")
}
dat := tok.ToDoubleArray()
_, err := dat.Save(cli.Convert.Tokenizer)
if err != nil {
- log.Error().Err(err)
- os.Exit(1)
+ log.Fatalln(err)
}
fmt.Println("File successfully converted.")
os.Exit(0)
diff --git a/datokenizer.go b/datokenizer.go
index f1f8b0c..1c75a33 100644
--- a/datokenizer.go
+++ b/datokenizer.go
@@ -14,7 +14,6 @@
// Serialization is little endian.
// TODO:
-// - Write simple main function.
// - Turn sigma into an array instead of using a map.
// - replace maxSize with the check value
// - Add checksum to serialization.
@@ -37,7 +36,7 @@
"strings"
"unicode/utf8"
- "github.com/rs/zerolog/log"
+ "log"
)
const (
@@ -108,14 +107,14 @@
func LoadFomaFile(file string) *Tokenizer {
f, err := os.Open(file)
if err != nil {
- log.Error().Err(err)
+ log.Print(err)
return nil
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
- log.Error().Err(err)
+ log.Print(err)
return nil
}
defer gz.Close()
@@ -154,7 +153,7 @@
if err == io.EOF {
break
}
- log.Error().Err(err)
+ log.Print(err)
return nil
}
@@ -180,7 +179,7 @@
mode = NONE
} else if !strings.HasPrefix(line, "##foma-net") {
- log.Error().Msg("Unknown input line")
+ log.Print("Unknown input line")
break
}
continue
@@ -207,25 +206,25 @@
fmt.Println("name: " + elem[12])
*/
if elem[6] != "1" {
- log.Error().Msg("The FST needs to be deterministic")
+ log.Print("The FST needs to be deterministic")
return nil
}
if elem[9] != "1" {
- log.Error().Msg("The FST needs to be epsilon free")
+ log.Print("The FST needs to be epsilon free")
return nil
}
elemint[0], err = strconv.Atoi(elem[1])
if err != nil {
- log.Error().Msg("Can't read arccount")
+ log.Print("Can't read arccount")
return nil
}
tok.arcCount = elemint[0]
elemint[0], err = strconv.Atoi(elem[2])
if err != nil {
- log.Error().Msg("Can't read statecount")
+ log.Print("Can't read statecount")
return nil
}
@@ -331,7 +330,7 @@
} else if outSym == tok.epsilon {
nontoken = true
} else {
- log.Error().Msg(
+ log.Println(
"Unsupported transition: " +
strconv.Itoa(state) +
" -> " + strconv.Itoa(end) +
@@ -348,7 +347,7 @@
}
} else if inSym == tok.epsilon {
- log.Error().Msg("General epsilon transitions are not supported")
+ log.Println("General epsilon transitions are not supported")
return nil
}
@@ -409,7 +408,7 @@
number++
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return nil
}
@@ -445,7 +444,7 @@
}
default:
{
- log.Error().Msg("MCS not supported: " + line)
+ log.Println("MCS not supported: " + line)
return nil
}
}
@@ -454,11 +453,11 @@
} else { // Probably a new line symbol
line, err = r.ReadString('\n')
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return nil
}
if len(line) != 1 {
- log.Error().Msg("MCS not supported:" + line)
+ log.Println("MCS not supported:" + line)
return nil
}
symbol = rune('\n')
@@ -786,7 +785,7 @@
func (dat *DaTokenizer) Save(file string) (n int64, err error) {
f, err := os.Create(file)
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return 0, err
}
defer f.Close()
@@ -794,7 +793,7 @@
defer gz.Close()
n, err = dat.WriteTo(gz)
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return n, err
}
gz.Flush()
@@ -810,7 +809,7 @@
// Store magical header
all, err := wb.Write([]byte(MAGIC))
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return int64(all), err
}
@@ -836,7 +835,7 @@
bo.PutUint32(buf[12:16], uint32(len(dat.array)))
more, err := wb.Write(buf[0:16])
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return int64(all), err
}
@@ -847,21 +846,21 @@
more, err = wb.WriteRune(sym)
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return int64(all), err
}
all += more
}
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return int64(all), err
}
// Test marker - could be checksum
more, err = wb.Write([]byte("T"))
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return int64(all), err
}
all += more
@@ -871,12 +870,12 @@
bo.PutUint32(buf[0:4], dat.array[x])
more, err := wb.Write(buf[0:4])
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return int64(all), err
}
all += more
if more != 4 {
- log.Error().Msg("Can not write uint32")
+ log.Println("Can not write uint32")
return int64(all), err
}
}
@@ -889,14 +888,14 @@
func LoadDatokFile(file string) *DaTokenizer {
f, err := os.Open(file)
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return nil
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return nil
}
defer gz.Close()
@@ -927,30 +926,30 @@
_, err := r.Read(buf)
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return nil
}
if string(MAGIC) != string(buf) {
- log.Error().Msg("Not a datok file")
+ log.Println("Not a datok file")
return nil
}
more, err := io.ReadFull(r, buf[0:16])
if err != nil {
- log.Error().Err(err)
+ log.Println(err)
return nil
}
if more != 16 {
- log.Error().Msg("Read bytes do not fit")
+ log.Println("Read bytes do not fit")
return nil
}
version := bo.Uint16(buf[0:2])
if version != VERSION {
- log.Error().Msg("Version not compatible")
+ log.Println("Version not compatible")
return nil
}
@@ -975,12 +974,12 @@
_, err = io.ReadFull(r, buf[0:1])
if err != nil {
- log.Error().Err(err)
+ log.Print(err)
return nil
}
if string("T") != string(buf[0:1]) {
- log.Error().Msg("Not a datok file")
+ log.Println("Not a datok file")
return nil
}
@@ -990,12 +989,12 @@
dataArray, err := io.ReadAll(r)
if err == io.EOF {
- log.Error().Err(err)
+ log.Println(err)
return nil
}
if len(dataArray) < arraySize*4 {
- log.Error().Msg("Not enough bytes read")
+ log.Println("Not enough bytes read")
return nil
}
diff --git a/go.mod b/go.mod
index 6104f40..74df04b 100644
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,5 @@
require (
github.com/alecthomas/kong v0.2.17
- github.com/rs/zerolog v1.23.0 // indirect
github.com/stretchr/testify v1.7.0
)
diff --git a/go.sum b/go.sum
index 8942bc1..c3461cd 100644
--- a/go.sum
+++ b/go.sum
@@ -1,46 +1,17 @@
github.com/alecthomas/kong v0.2.17 h1:URDISCI96MIgcIlQyoCAlhOmrSw6pZScBNkctg8r0W0=
github.com/alecthomas/kong v0.2.17/go.mod h1:ka3VZ8GZNPXv9Ov+j4YNLkI8mTuhXyr/0ktSlqIydQQ=
-github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
-github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
-github.com/rs/zerolog v1.23.0 h1:UskrK+saS9P9Y789yNNulYKdARjPZuS35B8gJF2x60g=
-github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
-golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
-golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
-golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=