• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

ragel/H15-Sep-2016-1,7241,577

.gitignoreH A D15-Sep-201693 1010

.travis.ymlH A D15-Sep-2016316 1612

LICENSEH A D15-Sep-201611.1 KiB202169

README.mdH A D15-Sep-20162.7 KiB9257

doc.goH A D15-Sep-20161.7 KiB461

export_test.goH A D15-Sep-2016415 2113

maketesttables.goH A D15-Sep-20165.4 KiB220178

segment.goH A D15-Sep-20169.8 KiB285162

segment_fuzz.goH A D15-Sep-2016817 239

segment_fuzz_test.goH A D15-Sep-2016925 3014

segment_test.goH A D15-Sep-20166.5 KiB242193

segment_words.goH A D15-Sep-2016752.4 KiB19,54319,244

segment_words.rlH A D15-Sep-20168.9 KiB286243

segment_words_prod.goH A D15-Sep-20162.6 MiB173,644170,086

segment_words_test.goH A D15-Sep-201617.5 KiB446412

tables_test.goH A D15-Sep-2016641.4 KiB11,99511,989

README.md

1# segment
2
3A Go library for performing Unicode Text Segmentation
4as described in [Unicode Standard Annex #29](http://www.unicode.org/reports/tr29/)
5
6## Features
7
8* Currently only segmentation at Word Boundaries is supported.
9
10## License
11
12Apache License Version 2.0
13
14## Usage
15
16The functionality is exposed in two ways:
17
181.  You can use a bufio.Scanner with the SplitWords implementation of SplitFunc.
19The SplitWords function will identify the appropriate word boundaries in the input
20text and the Scanner will return tokens at the appropriate place.
21
22		scanner := bufio.NewScanner(...)
23		scanner.Split(segment.SplitWords)
24		for scanner.Scan() {
25			tokenBytes := scanner.Bytes()
26		}
27		if err := scanner.Err(); err != nil {
28			t.Fatal(err)
29		}
30
312.  Sometimes you would also like information returned about the type of token.
32To do this we have introduce a new type named Segmenter.  It works just like Scanner
33but additionally a token type is returned.
34
35		segmenter := segment.NewWordSegmenter(...)
36		for segmenter.Segment() {
37			tokenBytes := segmenter.Bytes())
38			tokenType := segmenter.Type()
39		}
40		if err := segmenter.Err(); err != nil {
41			t.Fatal(err)
42		}
43
44## Choosing Implementation
45
46By 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.
47
48However, you can choose to build with the fastest runtime implementation by passing the build tag as follows:
49
50		-tags 'prod'
51
52## Generating Code
53
54Several components in this package are generated.
55
561.  Several Ragel rules files are generated from Unicode properties files.
572.  Ragel machine is generated from the Ragel rules.
583.  Test tables are generated from the Unicode test files.
59
60All of these can be generated by running:
61
62		go generate
63
64## Fuzzing
65
66There is support for fuzzing the segment library with [go-fuzz](https://github.com/dvyukov/go-fuzz).
67
681.  Install go-fuzz if you haven't already:
69
70		go get github.com/dvyukov/go-fuzz/go-fuzz
71		go get github.com/dvyukov/go-fuzz/go-fuzz-build
72
732.  Build the package with go-fuzz:
74
75		go-fuzz-build github.com/blevesearch/segment
76
773.  Convert the Unicode provided test cases into the initial corpus for go-fuzz:
78
79		go test -v -run=TestGenerateWordSegmentFuzz -tags gofuzz_generate
80
814.  Run go-fuzz:
82
83		go-fuzz -bin=segment-fuzz.zip -workdir=workdir
84
85## Status
86
87
88[![Build Status](https://travis-ci.org/blevesearch/segment.svg?branch=master)](https://travis-ci.org/blevesearch/segment)
89
90[![Coverage Status](https://img.shields.io/coveralls/blevesearch/segment.svg)](https://coveralls.io/r/blevesearch/segment?branch=master)
91
92[![GoDoc](https://godoc.org/github.com/blevesearch/segment?status.svg)](https://godoc.org/github.com/blevesearch/segment)