Documentation
¶
Overview ¶
Package razdel provides Russian text tokenization and sentence segmentation.
Public API and offset semantics are defined in docs/contracts.md (UTF-8 byte offsets, Variant A).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sentence ¶
Sentence is a sentence span with its source text slice.
func Sentenize ¶
Sentenize splits text into sentences using upstream sentenize.py SentSegmenter rules (including list_item and dash_right). Each sentence text is strings.TrimSpace on the raw segment chunk, matching Python chunk.strip(); byte spans refer to the trimmed slice in the original UTF-8 string (docs/contracts.md). Invalid UTF-8 does not panic; Python parity is not guaranteed for such input.
Example ¶
package main
import (
"fmt"
"github.com/muonsoft/go-razdel"
)
func main() {
text := "Привет, мир! Это тест."
sentences := razdel.Sentenize(text)
for _, sent := range sentences {
fmt.Printf("%q [%d:%d]\n", sent.Text, sent.Start, sent.End)
}
}
Output: "Привет, мир!" [0:21] "Это тест." [22:38]
Example (Razdel) ¶
package main
import (
"fmt"
"github.com/muonsoft/go-razdel"
)
func main() {
text := `
- "Так в чем же дело?" - "Не ра-ду-ют".
И т. д. и т. п. В общем, вся газета
`
for _, sent := range razdel.Sentenize(text) {
fmt.Println(sent.Text)
}
}
Output: - "Так в чем же дело?" - "Не ра-ду-ют". И т. д. и т. п. В общем, вся газета
Example (TrimmedSpans) ¶
package main
import (
"fmt"
"github.com/muonsoft/go-razdel"
)
func main() {
text := " Привет. Пока. "
for _, sent := range razdel.Sentenize(text) {
fmt.Printf("%q [%d:%d]\n", sent.Text, sent.Start, sent.End)
}
}
Output: "Привет." [2:15] "Пока." [16:25]
type Span ¶
Span is a half-open byte interval into the original UTF-8 string: [Start, End). Start and End are measured in bytes; see docs/contracts.md.
type Token ¶
Token is a token span with its source text slice.
func Tokenize ¶
Tokenize splits text into tokens with behavior aligned to upstream third_party/razdel/razdel/segmenters/tokenize.py (atoms, splits, join rules). Invalid UTF-8 does not panic: each invalid byte is an OTHER atom, then the usual join rules apply (see docs/contracts.md).
Example ¶
package main
import (
"fmt"
"github.com/muonsoft/go-razdel"
)
func main() {
text := "Привет, мир!"
tokens := razdel.Tokenize(text)
for _, tok := range tokens {
fmt.Printf("%q [%d:%d]\n", tok.Text, tok.Start, tok.End)
}
}
Output: "Привет" [0:12] "," [12:13] "мир" [14:20] "!" [20:21]
Example (Product) ¶
package main
import (
"fmt"
"strings"
"github.com/muonsoft/go-razdel"
)
func main() {
text := "Кружка-термос на 0.5л (50/64 см³, 516;...)"
var parts []string
for _, tok := range razdel.Tokenize(text) {
parts = append(parts, tok.Text)
}
fmt.Println(strings.Join(parts, " | "))
}
Output: Кружка-термос | на | 0.5 | л | ( | 50/64 | см³ | , | 516 | ; | ... | )
Example (Utf8ByteOffsets) ¶
package main
import (
"fmt"
"unicode/utf8"
"github.com/muonsoft/go-razdel"
)
func main() {
text := "a ж"
fmt.Printf("bytes=%d runes=%d\n", len(text), utf8.RuneCountInString(text))
for _, tok := range razdel.Tokenize(text) {
fmt.Printf("%q [%d:%d]\n", tok.Text, tok.Start, tok.End)
}
}
Output: bytes=4 runes=3 "a" [0:1] "ж" [2:4]
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
sentenize
Code generated from third_party/razdel/razdel/segmenters/sokr.py — keep in sync with upstream.
|
Code generated from third_party/razdel/razdel/segmenters/sokr.py — keep in sync with upstream. |
|
tools
|
|
|
genupstreamfixtures
command
Command genupstreamfixtures regenerates sampled corpus fixtures under testdata/upstream from third_party/razdel.
|
Command genupstreamfixtures regenerates sampled corpus fixtures under testdata/upstream from third_party/razdel. |