ikawaha / kagome

Self-contained Japanese Morphological Analyzer written in pure Go
MIT License
804 stars 53 forks source link

Add working examples #299

Open ikawaha opened 1 year ago

ikawaha commented 1 year ago

see. https://github.com/ikawaha/kagome/issues/277#issuecomment-1340182326

./sample/
├── dict
│   └── userdict.txt
├── example      ← ※ folder for adding working examples
└── wasm
    ├── README.md
    ├── go.mod
    ├── kagome.html
    └── main.go
KEINOS commented 3 months ago

I wish to refactor the sample directory as below, if I may. If so, this change will ease adding other examples.

# Current
sample
├── _example
│   ├── db_search
│   │   └── main.go
│   ├── go.mod
│   ├── go.sum
│   ├── tokenize
│   │   └── main.go
│   └── wakati
│       └── main.go
├── dict
│   └── userdict.txt
└── wasm
    ├── README.md
    ├── go.mod
    ├── kagome.html
    └── main.go
# After refactor
_example
├── go.mod
├── go.sum
│
├── dict
│   └── userdict.txt
├── db_search
│   └── main.go
├── tokenize
│   └── main.go
├── wakati
│   └── main.go
└── wasm
    ├── README.md
    ├── kagome.html
    └── main.go
ikawaha commented 3 months ago

Thanks for the suggestion.

I had the current directory structure so as not to change the location of the sample user dictionary, but I thought it would be a good idea to change it.

I thought it would be better to put go.mod in each subdirectory. What do you think?

# After refactor
_example
│
├── dict (or user_dict)
│   └── userdict.txt
├── db_search
│   ├── go.mod
│   ├── go.sum
│   └── main.go
├── tokenize
│   ├── go.mod
│   ├── go.sum
│   └── main.go
├── wakati
│   ├── go.mod
│   ├── go.sum
│   └── main.go
└── wasm
    ├── go.mod
    ├── go.sum
    ├── README.md
    ├── kagome.html
    └── main.go
KEINOS commented 3 months ago

I agree.

Having go.mod and go.sum in every example directory is ideal. It looses coupling and easy to understand.

In that case we need to place go.work file for multi-module to avoid warnings from IDE/gopls.

# After refactor
_example
+├── go.work
 │
-├── dict (or user_dict)
+├── user_dict
+│   ├── go.mod
+│   ├── go.sum
+│   ├── main.go
 │   └── userdict.txt
 ├── db_search
 │   ├── go.mod
 │   ├── go.sum
 │   └── main.go
 ├── tokenize
 │   ├── go.mod
 │   ├── go.sum
 │   └── main.go
 ├── wakati
 │   ├── go.mod
 │   ├── go.sum
 │   └── main.go
 └── wasm
     ├── go.mod
     ├── go.sum
     ├── README.md
     ├── kagome.html
     └── main.go

This allows users to simply change their working directory and run the examples. If this is okay with you, I would like to make a PR of it.

ikawaha commented 3 months ago

It seems to be good, looking forward to your pull request.

Thank you!