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

Rename the project and package name #12

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
cache-dependency-path: go.sum

- name: Test
run: go test -v -json ./... > TestResults.json
run: go test -v -json ./...

- name: Upload test results
uses: actions/upload-artifact@v3
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
# Go workspace file
go.work

# Cangjie database file
cangjie.db
# Congkit database file
congkit.db

# Project binaries
gen-db
cangjie
congkit
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BIN=cangjie
BIN=congkit
DB_GENERATOR=gen-db

.PHONY: dep dep-update dep-download build
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
# go-cangjie
Chinese input method "Cangjie" engine written in Go
# go-congkit
Chinese input method "Congkit" engine written in Go

This project aims to create an input engine for Cangjie input method using Go.
This project aims to create an input engine for Congkit input method using Go.



### Features

- Typing : Entering Cangjie radicals will list the corresponding Chinese words with the subsequence radicals.
- Typing : Entering Congkit radicals will list the corresponding Chinese words with the subsequence radicals.
- Associated Phrase and Vocabularies: Finished typing a Chinese word will show a list of associated phrases.



### Data Source

This project needs a data source for mapping Chinese characters and Cangjie radicals.
This project needs a data source for mapping Chinese characters and Congkit radicals.

The source could be borrowed from an earlier project which placed the table under Public Domain.

Cangjie Data Source: https://gitlab.freedesktop.org/cangjie/libcangjie/-/raw/master/data/table.txt
Congkit Data Source: https://gitlab.freedesktop.org/cangjie/libcangjie/-/raw/master/data/table.txt



### Description

This project provides a binary which takes the input Cangjie radicals as English characters and outputs the corresponding matching Chinese word list.
This project provides a binary which takes the input Congkit radicals as English characters and outputs the corresponding matching Chinese word list.



### Use as package

`go get github.com/antonyho/go-cangjie`
`go get github.com/antonyho/go-congkit`

```
import (
cangjie "github.com/antonyho/go-cangjie/engine"
congkit "github.com/antonyho/go-congkit/engine"
)
```

Expand All @@ -57,13 +57,13 @@ make generate

### Use as executable process
```
./cangjie [cangjie_radicals]
./congkit [congkit_radicals]

Usage of ./cangjie:
Usage of ./congkit:
-d string
Custom database file path (default "cangjie.db")
Custom database file path (default "congkit.db")
-database string
Custom database file path (default "cangjie.db")
Custom database file path (default "congkit.db")
-e Use 'Easy' input method
-easy
Use 'Easy' input method
Expand All @@ -77,32 +77,32 @@ Usage of ./cangjie:
-simplified
Output simplified Chinese word
-v int
Cangjie version(3/5) (default 5)
Congkit version(3/5) (default 5)
-version int
Cangjie version(3/5) (default 5)
Congkit version(3/5) (default 5)
```

#### Usage Example #1
```
❯ ./cangjie hqi
❯ ./congkit hqi
[我 牫 𥫻]
```

#### Usage Example #2
```
❯ ./cangjie -v=5 ykmhm
❯ ./congkit -v=5 ykmhm
[產]
```

#### Usage Example #3
```
❯ ./cangjie -v=3 yhhqm
❯ ./congkit -v=3 yhhqm
[產 産]
```

#### Usage Example #4
```
❯ ./cangjie -s oiar
❯ ./congkit -s oiar
[仓]
```

Expand Down
20 changes: 10 additions & 10 deletions cmd/db-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os"
"path"

"github.com/antonyho/go-cangjie/internal/data"
"github.com/antonyho/go-cangjie/internal/db"
"github.com/antonyho/go-congkit/internal/data"
"github.com/antonyho/go-congkit/internal/db"
)

var (
Expand All @@ -17,9 +17,9 @@ var (
)

const (
DefaultTarget = "cangjie.db"
DefaultTarget = "congkit.db"

SourceFileUsage = "Cangjie source table file path"
SourceFileUsage = "Congkit source table file path"
TargetFileUsage = "Target database file path"
HelpUsage = "Print usages"
)
Expand All @@ -42,22 +42,22 @@ func main() {

var sourceTable [][]string
if source == "" {
fmt.Println("Using built-in Cangjie radicals table")
fmt.Println("Using built-in Congkit radicals table")

sourceTable, err = data.ReadBuiltinTable()
if err != nil {
log.Fatalf("Failed reading data from built-in Cangjie table.\n%v\n", err)
log.Fatalf("Failed reading data from built-in Congkit table.\n%v\n", err)
}
} else {
fmt.Println("Using provided Cangjie radicals table ", source)
fmt.Println("Using provided Congkit radicals table ", source)

sourceTableFile, err := os.Open(source)
if err != nil {
log.Fatalf("Failed opening Cangjie table file %s.\n%v\n", source, err)
log.Fatalf("Failed opening Congkit table file %s.\n%v\n", source, err)
}
sourceTable, err = data.ReadTable(sourceTableFile)
if err != nil {
log.Fatalf("Failed reading data from Cangjie table.\n%v\n", err)
log.Fatalf("Failed reading data from Congkit table.\n%v\n", err)
}
}

Expand All @@ -73,7 +73,7 @@ func main() {
fmt.Printf("Target database file path: %s\n", target)

if err = db.Generate(sourceTable, target); err != nil {
log.Fatalf("Failed generating Cangjie database file.\n%v\n", err)
log.Fatalf("Failed generating Congkit database file.\n%v\n", err)
}
}

Expand Down
30 changes: 15 additions & 15 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
_ "github.com/mattn/go-sqlite3"
)

type CangjieVersion int
type CongkitVersion int

const (
CangjieV3 CangjieVersion = 3
CangjieV5 CangjieVersion = 5
CongkitV3 CongkitVersion = 3
CongkitV5 CongkitVersion = 5
)

const (
Expand All @@ -24,15 +24,15 @@ const (

type Option func(*Engine)

func WithCangjieV3() Option {
func WithCongkitV3() Option {
return func(e *Engine) {
e.CangjieVersion = CangjieV3
e.CongkitVersion = CongkitV3
}
}

func WithCangjieV5() Option {
func WithCongkitV5() Option {
return func(e *Engine) {
e.CangjieVersion = CangjieV5
e.CongkitVersion = CongkitV5
}
}

Expand Down Expand Up @@ -64,12 +64,12 @@ func WithDatabase(path string) Option {

// Engine defaults
const (
DefaultCangjieVersion = CangjieV5
DefaultDatabasePath = "./cangjie.db"
DefaultCongkitVersion = CongkitV5
DefaultDatabasePath = "./congkit.db"
)

type Engine struct {
CangjieVersion
CongkitVersion
OutputSimplified bool // Output Simplified Chinese word
Easy bool // "Easy" input method mode
Prediction bool // Predict word while typing
Expand All @@ -80,7 +80,7 @@ type Engine struct {

func New(options ...Option) *Engine {
e := &Engine{
CangjieVersion: DefaultCangjieVersion,
CongkitVersion: DefaultCongkitVersion,
OutputSimplified: false,
dbPath: DefaultDatabasePath,
}
Expand All @@ -90,7 +90,7 @@ func New(options ...Option) *Engine {
}

if _, err := os.Stat(e.dbPath); err != nil && errors.Is(err, os.ErrNotExist) {
// The Cangjie database does not exist, create an in-memory database.
// The Congkit database does not exist, create an in-memory database.
// This is a constructor. Trying not to return error here.
e.db, _ = sql.Open("sqlite3", ":memory:")
} else {
Expand Down Expand Up @@ -127,7 +127,7 @@ func (e *Engine) Encode(radicals string) (results []rune, err error) {
codes = fmt.Sprintf("%s%%", radicals)
}

rows, err := e.db.Query(e.query, e.CangjieVersion, codes)
rows, err := e.db.Query(e.query, e.CongkitVersion, codes)
if err != nil {
return
}
Expand Down Expand Up @@ -161,15 +161,15 @@ func (e *Engine) determineQuery() {
} else if e.Prediction {
e.query = GetSimplifiedCharWithPrediction
} else {
e.query = GetSimplifiedCharFromCangjie
e.query = GetSimplifiedCharFromCongkit
}
} else {
if e.Easy {
e.query = GetCharFromQuick
} else if e.Prediction {
e.query = GetCharWithPrediction
} else {
e.query = GetCharFromCangjie
e.query = GetCharFromCongkit
}
}
}
Loading
Loading