Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
receive -n flag instead of -c
Browse files Browse the repository at this point in the history
  • Loading branch information
high-moctane committed Mar 16, 2020
1 parent 10f0915 commit 2fa62f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ Predict a next English word.

![gif](img/terminal.gif)

## Install

0. (Recommended) Star this repository (`・ω・´)★
## Installing

1. [**IMPORTANT**] Install [Nextword-data (https://github.com/high-moctane/nextword-data)](https://github.com/high-moctane/nextword-data)

Expand All @@ -24,10 +22,10 @@ Nextword prints the most likely English words that follow the stdin sentence.
Usage of /Users/moctane/go/bin/nextword:
-g
show as many result as possible
-c
max candidates number (default 100)
-n
max candidates number (default 10)
-d string
path to the data directory (default "/Users/moctane/Assets/nextword-data")
path to the data directory (default "/path/to/nextword-data")
-h show this message
-v show version

Expand Down Expand Up @@ -57,4 +55,4 @@ $ go test
## License
MIT
MIT
31 changes: 26 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"errors"
"flag"
"fmt"
"log"
Expand All @@ -15,10 +16,14 @@ const Version = "0.0.3"
// environmental variable
const nextwordDataPath = "NEXTWORD_DATA_PATH"

// defaults
const defaultCandidateNum = 10

// flags
var versionFlag = flag.Bool("v", false, "show version")
var dataPath = flag.String("d", os.Getenv(nextwordDataPath), "path to the data directory")
var candidateNum = flag.Int("c", 10, "max candidates number")
var candidateNumC = flag.Int("c", defaultCandidateNum, "max candidates number (deprecated)")
var candidateNum = flag.Int("n", defaultCandidateNum, "max candidates number")
var helpFlag = flag.Bool("h", false, "show this message")
var greedyFlag = flag.Bool("g", false, "show as many result as possible")

Expand All @@ -44,10 +49,9 @@ func run() error {
}

// new nextword
params := &NextwordParams{
DataPath: *dataPath,
CandidateNum: *candidateNum,
Greedy: *greedyFlag,
params, err := newNextwordParams()
if err != nil {
return err
}
nw, err := NewNextword(params)
if err != nil {
Expand All @@ -70,6 +74,23 @@ func run() error {
return nil
}

func newNextwordParams() (*NextwordParams, error) {
if *candidateNum != defaultCandidateNum && *candidateNumC != defaultCandidateNum {
err := errors.New("cannot set both flag -n and -c ")
return nil, err
}
candNum := *candidateNum
if *candidateNumC != defaultCandidateNum {
candNum = *candidateNumC
}

return &NextwordParams{
DataPath: *dataPath,
CandidateNum: candNum,
Greedy: *greedyFlag,
}, nil
}

func showVersion() {
fmt.Fprintln(os.Stderr, fmt.Sprintf("nextword version %s", Version))
}
Expand Down

0 comments on commit 2fa62f7

Please sign in to comment.