Currently only segmentation at Word Boundaries is supported.
Apache License Version 2.0
The functionality is exposed in two ways:
You can use a bufio.Scanner with the SplitWords implementation of SplitFunc.
The SplitWords function will identify the appropriate word boundaries in the input
text and the Scanner will return tokens at the appropriate place.
Sometimes you would also like information returned about the type of token.
To do this we have introduce a new type named Segmenter. It works just like Scanner
but additionally a token type is returned.
By default segment does NOT use the fastest runtime implementation. The reason is that it adds approximately 5s to compilation time and may require more than 1GB of ram on the machine performing compilation.
However, you can choose to build with the fastest runtime implementation by passing the build tag as follows:
Several components in this package are generated.
Several Ragel rules files are generated from Unicode properties files.
Ragel machine is generated from the Ragel rules.
Test tables are generated from the Unicode test files.
All of these can be generated by running:
There is support for fuzzing the segment library with go-fuzz.
Install go-fuzz if you haven’t already:
go get github.com/dvyukov/go-fuzz/go-fuzz
go get github.com/dvyukov/go-fuzz/go-fuzz-build
Build the package with go-fuzz:
Convert the Unicode provided test cases into the initial corpus for go-fuzz:
go test -v -run=TestGenerateWordSegmentFuzz -tags gofuzz_generate