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

添加phrase dict的支持 #62

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

AlienKevin
Copy link

#56

加入了一个PinyinPhraseIter,用户提供一个词语串(已分词),拿到每个词语相应的拼音。如果一个词语中含有不支持的字符,整个词语的注音为None,不然就生成一个Some(vec![..]),vec里面是词语中每个字的注音。

# #[cfg(feature = "plain")] {
use pinyin::{ToPinyin, Pinyin};
let mut iter = ["薄荷", "是", "便宜货"].iter().to_pinyin();
let mut next_plain = || iter.next().map(|ps|
    ps.map(|ps| ps.iter().map(|p|
        Pinyin::plain(*p)).collect::<Vec<_>>()));
assert_eq!(next_plain(), Some(Some(vec!["bo", "he"])));
assert_eq!(next_plain(), Some(Some(vec!["shi"])));
assert_eq!(next_plain(), Some(Some(vec!["pian", "yi", "huo"])));
assert_eq!(next_plain(), None);

我觉得这个interface能用,但是比较别扭,欢迎提出更好的解决办法。

@AlienKevin AlienKevin mentioned this pull request Jan 13, 2023
@mozillazg
Copy link
Owner

@AlienKevin 感谢贡献!

个人感觉默认让用户输入一个分词后的词语串是有点别扭,我们是否要内置分词或依赖一个分词crate?可能把这个特性独立为一个单独的 crete 会更好点?

@upsuper @LuoZijun 麻烦大家有空的时候也帮忙看一下这个 PR ,谢谢~

@AlienKevin
Copy link
Author

@mozillazg 你说的有道理,我觉得可以支持两种API,一种是自带分词(可以用jieba-rs不过不知道准确率如何),另一种是用户提供词语串。我认为有需要提供第二种API是因为

  1. rust我目前没有找到非常广泛使用的汉语分词crate,所以可能需要先用hanlp这类的python库分好,之后用rust-pinyin来注音
  2. 不同用户需要的分词标准不同,有的需要coarse,有的需要fine grained,有的还需要custom dict,我们作为一个注音crate不可能提供所有的选择

综上,我认为rust-pinyin应该提供一个baseline的分词功能,然后用户觉得不够满意的话,可以自己先分词后,再传入rust-pinyin。

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

Successfully merging this pull request may close these issues.

2 participants