Skip to content

Commit

Permalink
Update usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sg0hsmt committed Jan 15, 2022
1 parent aaa6e0a commit 1acf372
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,59 @@ BudouX-Go supported plain text only, not supports html inputs.

https://sg0hsmt.github.io/budoux-go/

https://go.dev/play/p/PWcZH3eULL6

## Requirement

Go 1.11 or later.

## Usage

See [example_test.go](./example_test.go) and [cli](./cmd/).
Import budoux and models.

```go
import (
"github.com/sg0hsmt/budoux-go"
"github.com/sg0hsmt/budoux-go/models"
)
```

Split sentences with internal model.

```go
func Example() {
model := models.DefaultJapaneseModel()
words := budoux.Parse(model, "これはテストです。")

fmt.Printf("%q", words)
// Output:
// ["これは" "テストです。"]
}
```

Load model from json file and split sentences using the loaded model.

```go
func Example() {
var model budoux.Model

// You can use your own custom model.
buf, err := ioutil.ReadFile(path_to_json)
if err != nil {
log.Fatalln("read model:", err)
}

if err := json.Unmarshal(buf, &model); err != nil {
log.Fatalln("unmarshal model:", err)
}

words := budoux.Parse(model, "これはテストです。")

fmt.Printf("%q", words)
// Output:
// ["これは" "テストです。"]
}
```

## Test

Expand Down

0 comments on commit 1acf372

Please sign in to comment.