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

new userphrase should be added into list after click "OK" #99

Closed
ShengYenPeng opened this issue Mar 18, 2016 · 11 comments
Closed

new userphrase should be added into list after click "OK" #99

ShengYenPeng opened this issue Mar 18, 2016 · 11 comments

Comments

@ShengYenPeng
Copy link

Hi,

I add new userphrase via "Add new phrase",
image

and I think the new phrase should appear in the list after I click "OK",
but I should click refresh button to make new phrase appear now.

The delete button works well, it just delete phrase after I delete,
I don't need to click refresh button to make phrase disappear.

@ShengYenPeng
Copy link
Author

the reason is that I just enter phrase and leave empty in bopomofo, so the phrase is pushed into ctx.
after I click refresh then the phrase is added into list.

but I think it could add phrase without bopomofo after clicking OK

@david50407
Copy link
Member

Now can only add phrase by giving both phrase and bopomofo. See #2

@david50407
Copy link
Member

Chewing can automatically remember phrases when you are typing.
You thought that you added the phrase without bopomofo successfully because you could see it after refreshing the list. But maybe it just failed and you loaded the same phrase remembered by itself (not added from chewing-editor).

@kidwm
Copy link
Member

kidwm commented Mar 22, 2016

@ShengYenPeng see #94

@ShengYenPeng
Copy link
Author

ok, thanks!

I think now that we can add phrase just by typing,
we should let chewing-editor have same behavior, because typing bopomofo is very time-consuming.
If editor found that user don't type bopomofo, maybe it can call API in libchewing to return bopomofo.

or the simplest idea is that if editor found that no bopomofo, just call refresh, so that the phrase would be added into list by libchewing.

@david50407
Copy link
Member

If editor found that user don't type bopomofo, maybe it can call API in libchewing to return bopomofo.

See chewing/libchewing#143

or the simplest idea is that if editor found that no bopomofo, just call refresh, so that the phrase would be added into list by libchewing.

But it's not always become into one phrase.
Maybe "蜘蛛人" you typed will become "蜘蛛" and "人", it's not the phrase wanted by user.

@ShengYenPeng
Copy link
Author

ok, I got it.

thanks!

@ShengYenPeng
Copy link
Author

Hi @david50407 ,

According to chewing can automatically remember phrases when you are typing and
refresh will push back these phrase into chewing-list,
I think I can use the phrase in the bottom of chewing-list to create the phrase that I want add.

I wrote some code into add function in UserphraseModel.cpp, and it seems works.

    if (ret > 0) {
        emit beginResetModel();
        userphrase_.insert(Userphrase{
            phrase,
            bopomofo
        });
        emit endResetModel();
        emit addNewPhraseCompleted(userphrase_[userphrase_.size()-1]);
    } else {
        qWarning() << "chewing_userphrase_add() returns" << ret;

        //----------  NEW  ( add userphrase without bopomofo) ------------------

        // refresh to make related phrase inserted into bottom of chewing-editor list
        refresh();

        int newPhrasePos = phrase.size()-1;
        QString tmpBopomofo;
        int idx = userphrase_.size()-1;

        bool foundMatchPhrase = false;

        //iterative searching correct phrase in userphrase list and add record bopomofo
        while(newPhrasePos >=0 ){

            foundMatchPhrase = false;            
            idx = userphrase_.size()-1;

            //searching correct phrase
            while( foundMatchPhrase == false  ){

               QString comparePhrase = userphrase_[idx].phrase_;

                if( comparePhrase.size() > newPhrasePos+ 1)
                {
                    --idx;
                    continue;
                }          


                for( int phraseShift= 0 ; phraseShift < comparePhrase.size() ; ++phraseShift  ){
                    if(  phrase[newPhrasePos - phraseShift ] != comparePhrase[ comparePhrase.size() -1-phraseShift ] ){
                        --idx;
                        break;
                    }
                    else if( phrase[newPhrasePos - phraseShift ] == comparePhrase[ comparePhrase.size() -1-phraseShift ] && phraseShift ==  comparePhrase.size()-1 )
                        foundMatchPhrase = true;
                }

             }

            // recording bopomofo
            if( newPhrasePos ==  phrase.size() -1)
                tmpBopomofo=userphrase_[idx].bopomofo_;
            else
                tmpBopomofo = userphrase_[idx].bopomofo_+" "+tmpBopomofo;

            newPhrasePos -= userphrase_[idx].phrase_.size();
        }

        //add
        if( newPhrasePos == - 1 & phrase.size() != 0)
        {
            add( phrase ,  tmpBopomofo );
        }

        //--------------------------------------------
    }

example:

1
2
3
4
8
10

@ShengYenPeng
Copy link
Author

I found that the code can't handle the invalid phrase like: "哈囉a",
and the chewing-editor would crash...

@jserv
Copy link
Member

jserv commented Mar 25, 2016

Please always clip your screenshots. We would crop pictures to concentrate on major difference.

@ShengYenPeng
Copy link
Author

OK!
I modified the screenshots.

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

No branches or pull requests

4 participants