Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fullwidth punctuation to support CJK #23

Merged
merged 2 commits into from
May 26, 2021

Conversation

wzru
Copy link
Contributor

@wzru wzru commented May 26, 2021

I tried to add fullwidth punctuation and now it seems to work well for CJK.
Here is my test code:

package main

import (
	"fmt"

	"gopkg.in/wzru/sentences.v1"
	"gopkg.in/wzru/sentences.v1/data"
)

func main() {
	var text string

	// Compiling language specific data into a binary file can be accomplished
	// by using `make <lang>` and then loading the `json` data:
	b, _ := data.Asset("data/english.json")

	// load the training data
	training, _ := sentences.LoadTraining(b)

	// create the default sentence tokenizer
	tokenizer := sentences.NewSentenceTokenizer(training)

	text = `你好。世界!` //Hello world
	sentences := tokenizer.Tokenize(text)
	for _, s := range sentences {
		fmt.Printf("'%s'\n", s.Text)
	}

	text = `你好吗?我很好。很高兴见到你!`
	// text = `How are you? i'm fine. Nice to meet you!`
	sentences = tokenizer.Tokenize(text)
	for _, s := range sentences {
		fmt.Printf("'%s'\n", s.Text)
	}
}

output:

$ go run main.go
'你好。'
'世界!'
'你好吗?'
'我很好。'
'很高兴见到你!'

Copy link
Owner

@neurosnap neurosnap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@neurosnap neurosnap merged commit fe5d64a into neurosnap:master May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants