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

pinyin -p has debug output #16

Closed
suntong opened this issue Oct 9, 2020 · 7 comments
Closed

pinyin -p has debug output #16

suntong opened this issue Oct 9, 2020 · 7 comments

Comments

@suntong
Copy link
Contributor

suntong commented Oct 9, 2020

  • Ego version (or commit ref): v0.40.0
  • Go version: go1.14.3
  • Gcc version: gcc version 9.3.0
  • Operating system and bit: 5.4.0-33-generic x86_64

Description

Is the extra output from pinyin -p intended?

$ pinyin -p 银行
2020/10/08 22:29:30 Load the gse dictionary: "/home/tong/l/ws/Go/pkg/mod/github.com/go-ego/gse@v0.60.0/data/dict/dictionary.txt" 
2020/10/08 22:29:32 Gse dictionary loaded finished.
yin xing

This looks like debug output, and should have a way to disable it.

@vcaesar
Copy link
Member

vcaesar commented Oct 9, 2020

Many times the log is useful, not is debug. I will think about it, and I rarely used pinyin CLI, please tell me the necessary reason to remove the log.

@suntong
Copy link
Contributor Author

suntong commented Oct 9, 2020

I understand that such output can be useful, my point of views are,

  • the two output will confirm that it is reading the dictionary and the reading is successful. It confirms the file location and the success. However, its value is only good for the first use, once people know the file location and the reading will always be successful, it become more and more useless, and turns more and more into noise.
  • such logging will have negative impact on the (CLI) program speed and performance, which can be invoked frequently for short phrases.
  • It is not only related to pinyin CLI, but built within the fundamental library, so even for people not using the pinyin CLI, they will still see such output, even if they don't need/want to see it any more.
  • it is quite common for *nix tools to read config/support files, but I can't remember any of them printing so, unless in debug mode.

My suggestion is to give a verbose switch to gse, which allows people to turn such logging on and/or off programmatically at their will. I.e., we need to give the control to the end user, instead of making the decision at fundamental library level. E.g., such switch can be set in their Go source, or passed from CLI, which I will be happily add to gpy.

Please consider. thanks.

@suntong
Copy link
Contributor Author

suntong commented Oct 11, 2020

The tools/pinyin now has a verbose switch/flag:

-v Verbose. 启用详细输出模式

So now need a mechanism to pass that switch to gse.

@vcaesar
Copy link
Member

vcaesar commented Oct 11, 2020

You can

var seg gse.Segmenter 
seg.SkipLog = true

and phrase.WithGse(seg).

@suntong
Copy link
Contributor Author

suntong commented Oct 11, 2020

Thanks, but sorry I can't make it works --
suntong@32c394d

If I comment off line 73,
suntong@32c394d#diff-15e6eb3669bee1b522664fd70a8e06e0R73

// phrase.WithGse(seg)

I'll be getting nil pointer errors. Then I tried the following without commenting off line 73

pys := phrase.Paragraph(ps, seg)

but the error is the same:

$ pinyin -p 银行
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x501486]

goroutine 1 [running]:
github.com/go-ego/gse.(*Dictionary).Find(0x0, 0xc000100918, 0x3, 0x20, 0x3, 0x20)
	.../Go/pkg/mod/github.com/go-ego/gse@v0.62.0/dictionary.go:110 +0x26
github.com/go-ego/gse.(*Segmenter).Find(...)
	.../Go/pkg/mod/github.com/go-ego/gse@v0.62.0/dag.go:39
github.com/go-ego/gse.(*Segmenter).getDag(0x9b5dc0, 0xc000100a30, 0x2, 0x20, 0x2)
	.../Go/pkg/mod/github.com/go-ego/gse@v0.62.0/dag.go:62 +0xd9
github.com/go-ego/gse.(*Segmenter).cutAll(0x9b5dc0, 0x7ffd6ab34583, 0x6, 0xd0, 0xd0, 0x52c000)
	.../Go/pkg/mod/github.com/go-ego/gse@v0.62.0/dag.go:229 +0xed
github.com/go-ego/gse.(*Segmenter).CutAll(...)
	.../Go/pkg/mod/github.com/go-ego/gse@v0.62.0/gse.go:84
github.com/go-ego/gpy/phrase.cutWords(0x7ffd6ab34583, 0x6, 0x0, 0x0, 0x0, 0x1a0, 0xc00007e1a0, 0x7f4045005858)
	.../Go/pkg/mod/github.com/go-ego/gpy@v0.40.0/phrase/phrase.go:45 +0xb6
github.com/go-ego/gpy/phrase.pinyinPhrase(0x7ffd6ab34583, 0x6, 0x0, 0x0, 0x0, 0x1a0, 0x52c240)
	.../Go/pkg/mod/github.com/go-ego/gpy@v0.40.0/phrase/phrase.go:70 +0x6a
github.com/go-ego/gpy/phrase.Paragraph(0x7ffd6ab34583, 0x6, 0x0, 0x0, 0x0, 0x7ffd6ab34583, 0x6)
	.../Go/pkg/mod/github.com/go-ego/gpy@v0.40.0/phrase/paragraph.go:61 +0x77
main.main()
	.../suntong/gpy/tools/pinyin/main.go:75 +0x585

Please help. Thx!

@vcaesar
Copy link
Member

vcaesar commented Oct 12, 2020

You must seg.LoadDict().

@suntong
Copy link
Contributor Author

suntong commented Oct 12, 2020

Thanks a lot, fixed, will send in PR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants