Re: option for enabling/disabling auto-suggest feature

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Rik-4
On 04/26/2018 12:27 PM, [hidden email] wrote:
Subject:
Re: Proceeding with the GSoC Project
From:
Sudeepam Pandey [hidden email]
Date:
04/26/2018 12:12 PM
To:
Nir Krakauer [hidden email]
CC:
octave-maintainers [hidden email], Doug Stewart [hidden email], Nicholas Jankowski [hidden email]
List-Post:
[hidden email]
Precedence:
list
MIME-Version:
1.0
References:
[hidden email] [hidden email] [hidden email] [hidden email]
In-Reply-To:
[hidden email]
Message-ID:
[hidden email]
Content-Type:
multipart/alternative; boundary="f4f5e80742b8a1817b056ac52cf4"
Message:
2

Thank you Nir Krakauer for your inputs. The following is an abstract from my GSoC proposal.

Phase 1 evaluations goal
: A set of working Neural Network m-scripts, which, together,
could suggest corrections for typographic errors.

Phase 2 evaluations goal: A development version of Octave which has a command line
suggestion feature (currently there will be no mechanism available to easily select the
corrections suggested and easily enable/disable this feature).

Phase 3 evaluations goal
:
A development version of Octave with a complete and working
command line suggestion feature, open to feedback and criticisms.

Do I understand correctly that the Phase 3 implementation will have a way to enable/disable the auto-suggest feature?  This is very important.  Microsoft got burned for introducing an auto-help mechanism called Clippy (it's avatar was a paperclip) which was far, far more annoying than useful, and could not be easily disabled.  In 2010 Time magazine named it one of the 50 worst inventions of all time.  In other words, make sure users are in charge and can enable/disable this feature as they like.

--Rik


Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey


On Fri, Apr 27, 2018 at 2:01 AM, Rik <[hidden email]> wrote:
On 04/26/2018 12:27 PM, [hidden email] wrote:
Subject:
Re: Proceeding with the GSoC Project
From:
Sudeepam Pandey [hidden email]
Date:
04/26/2018 12:12 PM
To:
Nir Krakauer [hidden email]
CC:
octave-maintainers [hidden email], Doug Stewart [hidden email], Nicholas Jankowski [hidden email]
List-Post:
[hidden email]
Precedence:
list
MIME-Version:
1.0
References:
[hidden email] [hidden email] [hidden email] [hidden email]
In-Reply-To:
[hidden email]
Message-ID:
[hidden email]
Content-Type:
multipart/alternative; boundary="f4f5e80742b8a1817b056ac52cf4"
Message:
2

Thank you Nir Krakauer for your inputs. The following is an abstract from my GSoC proposal.

Phase 1 evaluations goal
: A set of working Neural Network m-scripts, which, together,
could suggest corrections for typographic errors.

Phase 2 evaluations goal: A development version of Octave which has a command line
suggestion feature (currently there will be no mechanism available to easily select the
corrections suggested and easily enable/disable this feature).

Phase 3 evaluations goal
:
A development version of Octave with a complete and working
command line suggestion feature, open to feedback and criticisms.

Do I understand correctly that the Phase 3 implementation will have a way to enable/disable the auto-suggest feature?  This is very important.  Microsoft got burned for introducing an auto-help mechanism called Clippy (it's avatar was a paperclip) which was far, far more annoying than useful, and could not be easily disabled.  In 2010 Time magazine named it one of the 50 worst inventions of all time.  In other words, make sure users are in charge and can enable/disable this feature as they like.

--Rik



Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

nrjank
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git status                            # Output with correct spelling.
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                          # Default output when incorrect spelling of the command is entered.
git: 'statsus' is not a git command. See 'git --help'.
Did you mean this?
    status

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git config --global help.autocorrect 20      # Changing the default setting

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                          # Time after which execution of the suggested command occurs = 2 sec
WARNING: You called a Git command named 'statsus', which does not exist.
Continuing under the assumption that you meant 'status'
in 2.0 seconds automatically...
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git config --global help.autocorrect 30      # Changing the default setting

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                         # Time after which execution of the suggested command occurs = 3 sec
WARNING: You called a Git command named 'statsus', which does not exist.
Continuing under the assumption that you meant 'status'
in 3.0 seconds automatically...
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Note: Since all the aspects of the suggestion feature will be governed by this separate script (didYouMean), it can also be modified later, very easily if required.

Please add in your suggestions, if the idea seems fine, then I can start looking at the code...

P Sudeepam.
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

nrjank
On Mon, Apr 30, 2018 at 3:57 PM, Sudeepam Pandey <[hidden email]> wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git status                            # Output with correct spelling.
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                          # Default output when incorrect spelling of the command is entered.
git: 'statsus' is not a git command. See 'git --help'.
Did you mean this?
    status

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git config --global help.autocorrect 20      # Changing the default setting

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                          # Time after which execution of the suggested command occurs = 2 sec
WARNING: You called a Git command named 'statsus', which does not exist.
Continuing under the assumption that you meant 'status'
in 2.0 seconds automatically...
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git config --global help.autocorrect 30      # Changing the default setting

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                         # Time after which execution of the suggested command occurs = 3 sec
WARNING: You called a Git command named 'statsus', which does not exist.
Continuing under the assumption that you meant 'status'
in 3.0 seconds automatically...
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Note: Since all the aspects of the suggestion feature will be governed by this separate script (didYouMean), it can also be modified later, very easily if required.

Please add in your suggestions, if the idea seems fine, then I can start looking at the code...

P Sudeepam.


I don't have time for a long reply, but I agree with your Note 2.  a simple flag setting command should work.  Something similar to "more on" "more off"  toggling the pager for long outputs. Might be as simple as "suggest on"/"suggest off"
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Rik-4
In reply to this post by Sudeepam Pandey
On 04/30/2018 12:57 PM, Sudeepam Pandey wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Yes, there must be an enable/disable feature.  I also agree that we should NOT implement an auto-execute option at this time.


Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.


This seems correct.  This should get us coverage of most of the obvious typos.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...


This architecture is very similar to the one that Octave already uses for unimplemented functions.  See the documentation for missing_function_hook().  The function missing_function_hook() works together with the parser.  When the parser doesn't recognize an identifier, it calls whatever has been set up as the callback function in missing_function_hook().  Currently, that function is scripts/help/__unimplemented__.  Take a look as well at __unimplemented__.m to see how it operates.

The Octave project coding convention is not to use CamelCase so perhaps your function should be __suggestions__ rather than didYouMean?

For development, you can quickly substitute your own suggestion function by pointing the missing_function_hook to your own m-file.

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

It seems to me that there may need to be a missing_property_hook () function, written in C++, that would behave like missing_function_hook when a graphics property is unrecognized.


Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.


Sure, this would work.  Alternatively, just set missing_component_hook to "" when you don't want to use it.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Take a look at the function menu().  It takes a cell array of strings as input and creates a numbered list, and then returns the selected input.  It's already coded and does precisely what you want.

--Rik
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey
In reply to this post by nrjank


On Tue, May 1, 2018 at 2:51 AM, Nicholas Jankowski <[hidden email]> wrote:
On Mon, Apr 30, 2018 at 3:57 PM, Sudeepam Pandey <[hidden email]> wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git status                            # Output with correct spelling.
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                          # Default output when incorrect spelling of the command is entered.
git: 'statsus' is not a git command. See 'git --help'.
Did you mean this?
    status

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git config --global help.autocorrect 20      # Changing the default setting

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                          # Time after which execution of the suggested command occurs = 2 sec
WARNING: You called a Git command named 'statsus', which does not exist.
Continuing under the assumption that you meant 'status'
in 2.0 seconds automatically...
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git config --global help.autocorrect 30      # Changing the default setting

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $ git statsus                         # Time after which execution of the suggested command occurs = 3 sec
WARNING: You called a Git command named 'statsus', which does not exist.
Continuing under the assumption that you meant 'status'
in 3.0 seconds automatically...
On branch master
nothing to commit, working directory clean

>sudeepam@sudeepam-HP-Pavilion-15-Notebook-PC ~/Desktop/test $

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Note: Since all the aspects of the suggestion feature will be governed by this separate script (didYouMean), it can also be modified later, very easily if required.

Please add in your suggestions, if the idea seems fine, then I can start looking at the code...

P Sudeepam.


I don't have time for a long reply, but I agree with your Note 2.  a simple flag setting command should work.  Something similar to "more on" "more off"  toggling the pager for long outputs. Might be as simple as "suggest on"/"suggest off"

Alright. I understand.
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey
In reply to this post by Rik-4


On Tue, May 1, 2018 at 3:00 AM, Rik <[hidden email]> wrote:
On 04/30/2018 12:57 PM, Sudeepam Pandey wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Yes, there must be an enable/disable feature.  I also agree that we should NOT implement an auto-execute option at this time.

Its decided then.


Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.


This seems correct.  This should get us coverage of most of the obvious typos.

Lets start the work with these then. If someone suggests something later on, we can modify it.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...


This architecture is very similar to the one that Octave already uses for unimplemented functions.  See the documentation for missing_function_hook().  The function missing_function_hook() works together with the parser.  When the parser doesn't recognize an identifier, it calls whatever has been set up as the callback function in missing_function_hook().  Currently, that function is scripts/help/__unimplemented__.  Take a look as well at __unimplemented__.m to see how it operates.

Thank you. I'll take a look and ask if I have further doubts.

The Octave project coding convention is not to use CamelCase so perhaps your function should be __suggestions__ rather than didYouMean?

Of course. That was just an example.

For development, you can quickly substitute your own suggestion function by pointing the missing_function_hook to your own m-file.

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

It seems to me that there may need to be a missing_property_hook () function, written in C++, that would behave like missing_function_hook when a graphics property is unrecognized.

I can try to implement it after I understand how missing_function_hook () works. Can't be sure at this point though. Let me take a look at missing_function_hook () first.


Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.


Sure, this would work.  Alternatively, just set missing_component_hook to "" when you don't want to use it.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Take a look at the function menu().  It takes a cell array of strings as input and creates a numbered list, and then returns the selected input.  It's already coded and does precisely what you want.

--Rik

Alright I'll take a look.

Thanks for your detailed reply Rik. This would give me a very good starting point.

Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey


On Tue, May 1, 2018 at 9:43 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 3:00 AM, Rik <[hidden email]> wrote:
On 04/30/2018 12:57 PM, Sudeepam Pandey wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Yes, there must be an enable/disable feature.  I also agree that we should NOT implement an auto-execute option at this time.

Its decided then.


Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.


This seems correct.  This should get us coverage of most of the obvious typos.

Lets start the work with these then. If someone suggests something later on, we can modify it.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...


This architecture is very similar to the one that Octave already uses for unimplemented functions.  See the documentation for missing_function_hook().  The function missing_function_hook() works together with the parser.  When the parser doesn't recognize an identifier, it calls whatever has been set up as the callback function in missing_function_hook().  Currently, that function is scripts/help/__unimplemented__.  Take a look as well at __unimplemented__.m to see how it operates.

Thank you. I'll take a look and ask if I have further doubts.

The Octave project coding convention is not to use CamelCase so perhaps your function should be __suggestions__ rather than didYouMean?

Of course. That was just an example.

For development, you can quickly substitute your own suggestion function by pointing the missing_function_hook to your own m-file.

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

It seems to me that there may need to be a missing_property_hook () function, written in C++, that would behave like missing_function_hook when a graphics property is unrecognized.

I can try to implement it after I understand how missing_function_hook () works. Can't be sure at this point though. Let me take a look at missing_function_hook () first.


Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.


Sure, this would work.  Alternatively, just set missing_component_hook to "" when you don't want to use it.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Take a look at the function menu().  It takes a cell array of strings as input and creates a numbered list, and then returns the selected input.  It's already coded and does precisely what you want.

--Rik

Alright I'll take a look.

Thanks for your detailed reply Rik. This would give me a very good starting point.

I played with __unimplemented__.m function a little and it seems like this is exactly what we need to integrate a command line suggestion into Octave. I edited the script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

As of now, there is no real 'suggestion code' in __suggestion__.m script and it returns a simple line only... the point was to show that it works for CLI and GUI as well.

Here are the results:-

GUI

>> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
>>

CLI

octave:1> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
octave:1>

A lot of discussions have been done by now and I am thankful to the community for the same. To me, it seems like I am ready to start with the actual coding part of the project.

If members of the community have anymore suggestions, concerns etc. please share them.

To my assigned GSoC mentors, Douglas Stewart and Nicholas Jankowski, should I do the following now, before the actual coding period begins...?

1) Share an updated timeline with both of you, based on the discussions so far.

2) Start a post about the discussions that went through during the community bonding period on my blog.

3) Share with everyone, a prototype of the 'algorithm independent' implementation that shows how this feature integrates itself with octave through my public bitbucket repository?

--P Sudeepam
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Doug Stewart-4


On Tue, May 1, 2018 at 3:42 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 9:43 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 3:00 AM, Rik <[hidden email]> wrote:
On 04/30/2018 12:57 PM, Sudeepam Pandey wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Yes, there must be an enable/disable feature.  I also agree that we should NOT implement an auto-execute option at this time.

Its decided then.


Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.


This seems correct.  This should get us coverage of most of the obvious typos.

Lets start the work with these then. If someone suggests something later on, we can modify it.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...


This architecture is very similar to the one that Octave already uses for unimplemented functions.  See the documentation for missing_function_hook().  The function missing_function_hook() works together with the parser.  When the parser doesn't recognize an identifier, it calls whatever has been set up as the callback function in missing_function_hook().  Currently, that function is scripts/help/__unimplemented__.  Take a look as well at __unimplemented__.m to see how it operates.

Thank you. I'll take a look and ask if I have further doubts.

The Octave project coding convention is not to use CamelCase so perhaps your function should be __suggestions__ rather than didYouMean?

Of course. That was just an example.

For development, you can quickly substitute your own suggestion function by pointing the missing_function_hook to your own m-file.

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

It seems to me that there may need to be a missing_property_hook () function, written in C++, that would behave like missing_function_hook when a graphics property is unrecognized.

I can try to implement it after I understand how missing_function_hook () works. Can't be sure at this point though. Let me take a look at missing_function_hook () first.


Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.


Sure, this would work.  Alternatively, just set missing_component_hook to "" when you don't want to use it.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Take a look at the function menu().  It takes a cell array of strings as input and creates a numbered list, and then returns the selected input.  It's already coded and does precisely what you want.

--Rik

Alright I'll take a look.

Thanks for your detailed reply Rik. This would give me a very good starting point.

I played with __unimplemented__.m function a little and it seems like this is exactly what we need to integrate a command line suggestion into Octave. I edited the script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

As of now, there is no real 'suggestion code' in __suggestion__.m script and it returns a simple line only... the point was to show that it works for CLI and GUI as well.

Here are the results:-

GUI

>> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
>>

CLI

octave:1> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
octave:1>

A lot of discussions have been done by now and I am thankful to the community for the same. To me, it seems like I am ready to start with the actual coding part of the project.

If members of the community have anymore suggestions, concerns etc. please share them.

To my assigned GSoC mentors, Douglas Stewart and Nicholas Jankowski, should I do the following now, before the actual coding period begins...?

1) Share an updated timeline with both of you, based on the discussions so far.


Yes
 
2) Start a post about the discussions that went through during the community bonding period on my blog.

Yes
 
3) Share with everyone, a prototype of the 'algorithm independent' implementation that shows how this feature integrates itself with octave through my public bitbucket repository?

Not sure that this is too important yet.


 
--P Sudeepam



--
DASCertificate for 206392

Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey


On Wed, May 2, 2018 at 1:48 AM, Doug Stewart <[hidden email]> wrote:


On Tue, May 1, 2018 at 3:42 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 9:43 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 3:00 AM, Rik <[hidden email]> wrote:
On 04/30/2018 12:57 PM, Sudeepam Pandey wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Yes, there must be an enable/disable feature.  I also agree that we should NOT implement an auto-execute option at this time.

Its decided then.


Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.


This seems correct.  This should get us coverage of most of the obvious typos.

Lets start the work with these then. If someone suggests something later on, we can modify it.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...


This architecture is very similar to the one that Octave already uses for unimplemented functions.  See the documentation for missing_function_hook().  The function missing_function_hook() works together with the parser.  When the parser doesn't recognize an identifier, it calls whatever has been set up as the callback function in missing_function_hook().  Currently, that function is scripts/help/__unimplemented__.  Take a look as well at __unimplemented__.m to see how it operates.

Thank you. I'll take a look and ask if I have further doubts.

The Octave project coding convention is not to use CamelCase so perhaps your function should be __suggestions__ rather than didYouMean?

Of course. That was just an example.

For development, you can quickly substitute your own suggestion function by pointing the missing_function_hook to your own m-file.

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

It seems to me that there may need to be a missing_property_hook () function, written in C++, that would behave like missing_function_hook when a graphics property is unrecognized.

I can try to implement it after I understand how missing_function_hook () works. Can't be sure at this point though. Let me take a look at missing_function_hook () first.


Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.


Sure, this would work.  Alternatively, just set missing_component_hook to "" when you don't want to use it.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Take a look at the function menu().  It takes a cell array of strings as input and creates a numbered list, and then returns the selected input.  It's already coded and does precisely what you want.

--Rik

Alright I'll take a look.

Thanks for your detailed reply Rik. This would give me a very good starting point.

I played with __unimplemented__.m function a little and it seems like this is exactly what we need to integrate a command line suggestion into Octave. I edited the script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

As of now, there is no real 'suggestion code' in __suggestion__.m script and it returns a simple line only... the point was to show that it works for CLI and GUI as well.

Here are the results:-

GUI

>> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
>>

CLI

octave:1> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
octave:1>

A lot of discussions have been done by now and I am thankful to the community for the same. To me, it seems like I am ready to start with the actual coding part of the project.

If members of the community have anymore suggestions, concerns etc. please share them.

To my assigned GSoC mentors, Douglas Stewart and Nicholas Jankowski, should I do the following now, before the actual coding period begins...?

1) Share an updated timeline with both of you, based on the discussions so far.


Yes
 
2) Start a post about the discussions that went through during the community bonding period on my blog.

Yes
 
3) Share with everyone, a prototype of the 'algorithm independent' implementation that shows how this feature integrates itself with octave through my public bitbucket repository?

Not sure that this is too important yet.


 
--P Sudeepam



--
DASCertificate for 206392


Understood Doug.

There is one last thing left for me to figure out kindly help me with the same.

Like I sad before...I edited the __unimplemented__.m script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

There are a two things that still need to be taken care of..

1) First of all, we absolutely need a on/off switch for this feature. However, __suggestion__.m will be designed as an internal function (called when an identifier is not found in the unimplemented functions list) so users cannot directly call this function.
So to design a command which can act as a switch for this feature, we can write a m script (say flag.m) which is callable from the command window with a flag value and which would save the desired flag value (indicating on/off) in a .mat file in the "..octave/scripts/help" directory (where __suggestions__.m would reside). The __suggestions__.m script would load this value as soon as it is called and act accordingly. This way the user setting will be saved and will remain protected unless they modify it themselves.
I however, don't understand what files do I have to tweak so that the parser learns to identify this function (flag.m) as a new function of octave, callable from the command window. Also, if we went along with this, what path should I set inside the flag.m file so that the .mat file in "..octave/scripts/help" directory gets updated successfully? considering that the path BEFORE "../octave/scripts/help" would be different for each user, depending on where they have saved their copy of octave.
I understand that I may have said somethings incorrectly here, or that my thinking may be wrong at some places (for example, maybe we have to have a flag.cc file and not a flag.m file) but this approach is probably how a very good on/off feature could be made. Help and suggestions would be appreciated.

2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are...
   a) How do we do it? What files do we tweak?
   b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook?

...and maybe more challenges when we start thinking how?

I really would like to include properties as well but I'm not sure if they could be done right now. Can anyone help with this?

--P Sudeepam
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Rik-4
On 05/02/2018 05:55 AM, Sudeepam Pandey wrote:


Understood Doug.

There is one last thing left for me to figure out kindly help me with the same.

Like I sad before...I edited the __unimplemented__.m script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

There are a two things that still need to be taken care of..

1) First of all, we absolutely need a on/off switch for this feature. However, __suggestion__.m will be designed as an internal function (called when an identifier is not found in the unimplemented functions list) so users cannot directly call this function.
So to design a command which can act as a switch for this feature, we can write a m script (say flag.m) which is callable from the command window with a flag value and which would save the desired flag value (indicating on/off) in a .mat file in the "..octave/scripts/help" directory (where __suggestions__.m would reside). The __suggestions__.m script would load this value as soon as it is called and act accordingly. This way the user setting will be saved and will remain protected unless they modify it themselves.
I however, don't understand what files do I have to tweak so that the parser learns to identify this function (flag.m) as a new function of octave, callable from the command window. Also, if we went along with this, what path should I set inside the flag.m file so that the .mat file in "..octave/scripts/help" directory gets updated successfully? considering that the path BEFORE "../octave/scripts/help" would be different for each user, depending on where they have saved their copy of octave.
I understand that I may have said somethings incorrectly here, or that my thinking may be wrong at some places (for example, maybe we have to have a flag.cc file and not a flag.m file) but this approach is probably how a very good on/off feature could be made. Help and suggestions would be appreciated.

I would suggest using getpref()/setpref() for the time being.  For the namespace, use "Octave".  For the actual name of the preference, maybe something like "autosuggest".  In this case, your code can use getpref to check whether the value is boolean true before continuing.  For the time being you don't even need to write an m-file to enable/disable the option.  You can just use setpref directly.  Later on, you could wrap setpref() in an m-file to give it a nice interface.


2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are...
   a) How do we do it? What files do we tweak?
The file to inspect is libinterp/corefcn/graphics.cc.

grep -n error graphics.cc | grep property

74:  error ("set: invalid value for %s property", pname.c_str ());
104:    error ("%s: unknown %s property %s",
116:      error ("%s: ambiguous %s property name %s; possible matches:\n\n%s",
1312:        error (R"(invalid value for color property "%s")",
1346:              error (e, R"(invalid value for color property "%s" (value = %s))",
1356:        error (R"(invalid value for color property "%s")",
1369:    error (R"(invalid value for color property "%s")",
1384:        error (R"(invalid value for double_radio property "%s")",
1411:    error (R"(invalid value for double_radio property "%s")",
1657:        error (R"(set: invalid graphics handle (= %g) for property "%s")",
1660:        error (R"(set: invalid graphics object type for property "%s")",
1851:        error ("addproperty: missing possible values for radio property");
1913:        error ("addproperty: unsupported type for dynamic property (= %s)",
1937:        error ("addproperty: invalid object type (= %s)",
2194:            error ("invalid %s property '%s'", pfx.c_str (), pname.c_str ());
2219:    error ("invalid default property specification");
3069:              error (e, "error setting default property %s", pname.c_str ());
3098:    error (R"(get: unknown property "%s")", pname.c_str ());
3141:    error (R"(set: unknown property "%s")", pname.c_str ());
3157:    error (R"(get_property: unknown property "%s")", pname.c_str ());
5031:      error ("set: expecting text graphics object or character string for %s property, found %s",
10885:            error ("set: unknown property");
11115:            error ("__go_%s__: missing value for parent property",
11988:    error ("addproperty: invalid graphics object (= %g)", h);
11995:    error ("addproperty: a '%s' property already exists in the graphics object",

Only the error statements which deal with an unknown property would need modification.  I think the idea would be to intercept the error call about an unknown property.  At each point you would first check for missing_property_hook().  If it was empty then error out in the same way as before.  Otherwise, call the function provided in missing property hook and then call error() with whatever text was returned from the suggestions.  Note, that this would just give you suggestions, it would not necessarily be possible to print a menu and have the user decide which one they wanted to change the text to.

   b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook?

If you implement it the way I suggested then the two functions are at different levels of parsing and missing_function_hook would take precedence over missing_property_hook.


...and maybe more challenges when we start thinking how?

I really would like to include properties as well but I'm not sure if they could be done right now. Can anyone help with this?

--P Sudeepam

Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey


On Wed, May 2, 2018 at 9:34 PM, Rik <[hidden email]> wrote:
On 05/02/2018 05:55 AM, Sudeepam Pandey wrote:


Understood Doug.

There is one last thing left for me to figure out kindly help me with the same.

Like I sad before...I edited the __unimplemented__.m script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

There are a two things that still need to be taken care of..

1) First of all, we absolutely need a on/off switch for this feature. However, __suggestion__.m will be designed as an internal function (called when an identifier is not found in the unimplemented functions list) so users cannot directly call this function.
So to design a command which can act as a switch for this feature, we can write a m script (say flag.m) which is callable from the command window with a flag value and which would save the desired flag value (indicating on/off) in a .mat file in the "..octave/scripts/help" directory (where __suggestions__.m would reside). The __suggestions__.m script would load this value as soon as it is called and act accordingly. This way the user setting will be saved and will remain protected unless they modify it themselves.
I however, don't understand what files do I have to tweak so that the parser learns to identify this function (flag.m) as a new function of octave, callable from the command window. Also, if we went along with this, what path should I set inside the flag.m file so that the .mat file in "..octave/scripts/help" directory gets updated successfully? considering that the path BEFORE "../octave/scripts/help" would be different for each user, depending on where they have saved their copy of octave.
I understand that I may have said somethings incorrectly here, or that my thinking may be wrong at some places (for example, maybe we have to have a flag.cc file and not a flag.m file) but this approach is probably how a very good on/off feature could be made. Help and suggestions would be appreciated.

I would suggest using getpref()/setpref() for the time being.  For the namespace, use "Octave".  For the actual name of the preference, maybe something like "autosuggest".  In this case, your code can use getpref to check whether the value is boolean true before continuing.  For the time being you don't even need to write an m-file to enable/disable the option.  You can just use setpref directly.  Later on, you could wrap setpref() in an m-file to give it a nice interface.

Here is a demo I made just now... It is able to do the job of a on/off feature. The initial try/catch block is for the first time when the preference 'autosuggestion' will not be present in the group 'Octave'. Later on, the user can turn the feature on/off using setpref();

-------------------------------------------------------------------------------------------------------------------------------------

function txt = __suggestions__(fcn)

  try
    getpref ("Octave", "autosuggestion");
  catch err
    if (strcmpi (err.message, "getpref: preference autosuggest does not exist in GROUP Octave"))
      addpref ("Octave", "autosuggestion", true);
    endif
  end

  pref = getpref ("Octave", "autosuggestion");
  if (pref == false)
    disp ("Disabled");
  elseif (pref == true)
    disp ("Did you mean any of the following...");
  endif
 
endfunction;

----------------------------------------------------------------------------------------------------------------------------------------

Note: It is a sample code, it may not strictly adhere to the Octave style of coding.


2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are...
   a) How do we do it? What files do we tweak?
The file to inspect is libinterp/corefcn/graphics.cc.

grep -n error graphics.cc | grep property

74:  error ("set: invalid value for %s property", pname.c_str ());
104:    error ("%s: unknown %s property %s",
116:      error ("%s: ambiguous %s property name %s; possible matches:\n\n%s",
1312:        error (R"(invalid value for color property "%s")",
1346:              error (e, R"(invalid value for color property "%s" (value = %s))",
1356:        error (R"(invalid value for color property "%s")",
1369:    error (R"(invalid value for color property "%s")",
1384:        error (R"(invalid value for double_radio property "%s")",
1411:    error (R"(invalid value for double_radio property "%s")",
1657:        error (R"(set: invalid graphics handle (= %g) for property "%s")",
1660:        error (R"(set: invalid graphics object type for property "%s")",
1851:        error ("addproperty: missing possible values for radio property");
1913:        error ("addproperty: unsupported type for dynamic property (= %s)",
1937:        error ("addproperty: invalid object type (= %s)",
2194:            error ("invalid %s property '%s'", pfx.c_str (), pname.c_str ());
2219:    error ("invalid default property specification");
3069:              error (e, "error setting default property %s", pname.c_str ());
3098:    error (R"(get: unknown property "%s")", pname.c_str ());
3141:    error (R"(set: unknown property "%s")", pname.c_str ());
3157:    error (R"(get_property: unknown property "%s")", pname.c_str ());
5031:      error ("set: expecting text graphics object or character string for %s property, found %s",
10885:            error ("set: unknown property");
11115:            error ("__go_%s__: missing value for parent property",
11988:    error ("addproperty: invalid graphics object (= %g)", h);
11995:    error ("addproperty: a '%s' property already exists in the graphics object",

Only the error statements which deal with an unknown property would need modification.  I think the idea would be to intercept the error call about an unknown property.  At each point you would first check for missing_property_hook().  If it was empty then error out in the same way as before.  Otherwise, call the function provided in missing property hook and then call error() with whatever text was returned from the suggestions.  Note, that this would just give you suggestions, it would not necessarily be possible to print a menu and have the user decide which one they wanted to change the text to.

   b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook?

If you implement it the way I suggested then the two functions are at different levels of parsing and missing_function_hook would take precedence over missing_property_hook.

I understand. There are a few doubts however...

1) Will this file, libinterp/corefcn/graphics.cc cover all the major properties (figure, line, axis, etc...)?
2) Can you tell me where I can find missing_function_hook() so that I could make missing_property_hook() similar to that?



...and maybe more challenges when we start thinking how?

I really would like to include properties as well but I'm not sure if they could be done right now. Can anyone help with this?

--P Sudeepam


Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Rik-4
On 05/02/2018 11:12 AM, Sudeepam Pandey wrote:
> > > On Wed, May 2, 2018 at 9:34 PM, Rik [hidden email] wrote: > > > Here is a demo I made just now... It is able to do the job of a on/off feature. The initial try/catch block is for the first time when the preference 'autosuggestion' will not be present in the group 'Octave'. Later on, the user can turn the feature on/off using setpref(); > > ------------------------------------------------------------------------------------------------------------------------------------- > > function txt = __suggestions__(fcn) > > try > getpref ("Octave", "autosuggestion"); > catch err > if (strcmpi (err.message, "getpref: preference autosuggest does not exist in GROUP Octave")) > addpref ("Octave", "autosuggestion", true); > endif > end > > pref = getpref ("Octave", "autosuggestion"); > if (pref == false) > disp ("Disabled"); > elseif (pref == true) > disp ("Did you mean any of the following..."); > endif > > endfunction; > > ---------------------------------------------------------------------------------------------------------------------------------------- > > Note: It is a sample code, it may not strictly adhere to the Octave style of coding.
Looks good.  For performance, you can use the try/catch block to get the value of the preference just once.  See below

  pref = false;
  try
    pref = getpref ("Octave", "autosuggestion");
  catch err
    if (strcmp (err.message, "getpref: preference autosuggest does not exist in GROUP Octave"))
      addpref ("Octave", "autosuggestion", true);
      pref = true;
    endif
  end

  if (pref == true)
    disp ("Did you mean any of the following...");
  else
    disp ("Disabled");
  endif
 
endfunction

>> >> 2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are... >> a) How do we do it? What files do we tweak? >> b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook? > > If you implement it the way I suggested then the two functions are at different levels of parsing and missing_function_hook would take precedence over missing_property_hook. > > > I understand. There are a few doubts however... > > 1) Will this file, libinterp/corefcn/graphics.cc cover all the major properties (figure, line, axis, etc...)?
Yes.

> 2) Can you tell me where I can find missing_function_hook() so that I could make missing_property_hook() similar to that?
See libinterp/corefcn/variables.cc:2581.

--Rik

Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey


On 3 May 2018 2:16 a.m., "Rik" <[hidden email]> wrote:
On 05/02/2018 11:12 AM, Sudeepam Pandey wrote:
> > > On Wed, May 2, 2018 at 9:34 PM, Rik [hidden email] wrote: > > > Here is a demo I made just now... It is able to do the job of a on/off feature. The initial try/catch block is for the first time when the preference 'autosuggestion' will not be present in the group 'Octave'. Later on, the user can turn the feature on/off using setpref(); > > ------------------------------------------------------------------------------------------------------------------------------------- > > function txt = __suggestions__(fcn) > > try > getpref ("Octave", "autosuggestion"); > catch err > if (strcmpi (err.message, "getpref: preference autosuggest does not exist in GROUP Octave")) > addpref ("Octave", "autosuggestion", true); > endif > end > > pref = getpref ("Octave", "autosuggestion"); > if (pref == false) > disp ("Disabled"); > elseif (pref == true) > disp ("Did you mean any of the following..."); > endif > > endfunction; > > ---------------------------------------------------------------------------------------------------------------------------------------- > > Note: It is a sample code, it may not strictly adhere to the Octave style of coding.
Looks good.  For performance, you can use the try/catch block to get the value of the preference just once.  See below

  pref = false;
  try

    pref = getpref ("Octave", "autosuggestion");
  catch err
    if (strcmp (err.message, "getpref: preference autosuggest does not exist in GROUP Octave"))

      addpref ("Octave", "autosuggestion", true);
      pref = true;
    endif
  end


  if (pref == true)
    disp ("Did you mean any of the following...");
  else
    disp ("Disabled");
  endif
 
endfunction

Done already. Realized it after I sent this email.

>> >> 2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are... >> a) How do we do it? What files do we tweak? >> b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook? > > If you implement it the way I suggested then the two functions are at different levels of parsing and missing_function_hook would take precedence over missing_property_hook. > > > I understand. There are a few doubts however... > > 1) Will this file, libinterp/corefcn/graphics.cc cover all the major properties (figure, line, axis, etc...)?
Yes.


> 2) Can you tell me where I can find missing_function_hook() so that I could make missing_property_hook() similar to that?
See libinterp/corefcn/variables.cc:2581.

Thank you for that. I'll check it out.


--Rik


Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey
In reply to this post by Doug Stewart-4


On Wed, May 2, 2018 at 1:48 AM, Doug Stewart <[hidden email]> wrote:


On Tue, May 1, 2018 at 3:42 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 9:43 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 3:00 AM, Rik <[hidden email]> wrote:
On 04/30/2018 12:57 PM, Sudeepam Pandey wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Yes, there must be an enable/disable feature.  I also agree that we should NOT implement an auto-execute option at this time.

Its decided then.


Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.


This seems correct.  This should get us coverage of most of the obvious typos.

Lets start the work with these then. If someone suggests something later on, we can modify it.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...


This architecture is very similar to the one that Octave already uses for unimplemented functions.  See the documentation for missing_function_hook().  The function missing_function_hook() works together with the parser.  When the parser doesn't recognize an identifier, it calls whatever has been set up as the callback function in missing_function_hook().  Currently, that function is scripts/help/__unimplemented__.  Take a look as well at __unimplemented__.m to see how it operates.

Thank you. I'll take a look and ask if I have further doubts.

The Octave project coding convention is not to use CamelCase so perhaps your function should be __suggestions__ rather than didYouMean?

Of course. That was just an example.

For development, you can quickly substitute your own suggestion function by pointing the missing_function_hook to your own m-file.

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

It seems to me that there may need to be a missing_property_hook () function, written in C++, that would behave like missing_function_hook when a graphics property is unrecognized.

I can try to implement it after I understand how missing_function_hook () works. Can't be sure at this point though. Let me take a look at missing_function_hook () first.


Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.


Sure, this would work.  Alternatively, just set missing_component_hook to "" when you don't want to use it.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Take a look at the function menu().  It takes a cell array of strings as input and creates a numbered list, and then returns the selected input.  It's already coded and does precisely what you want.

--Rik

Alright I'll take a look.

Thanks for your detailed reply Rik. This would give me a very good starting point.

I played with __unimplemented__.m function a little and it seems like this is exactly what we need to integrate a command line suggestion into Octave. I edited the script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

As of now, there is no real 'suggestion code' in __suggestion__.m script and it returns a simple line only... the point was to show that it works for CLI and GUI as well.

Here are the results:-

GUI

>> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
>>

CLI

octave:1> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
octave:1>

A lot of discussions have been done by now and I am thankful to the community for the same. To me, it seems like I am ready to start with the actual coding part of the project.

If members of the community have anymore suggestions, concerns etc. please share them.

To my assigned GSoC mentors, Douglas Stewart and Nicholas Jankowski, should I do the following now, before the actual coding period begins...?

1) Share an updated timeline with both of you, based on the discussions so far.


Yes
 
2) Start a post about the discussions that went through during the community bonding period on my blog.

Yes
 
3) Share with everyone, a prototype of the 'algorithm independent' implementation that shows how this feature integrates itself with octave through my public bitbucket repository?

Not sure that this is too important yet.


 
--P Sudeepam



--
DASCertificate for 206392


Here[1] is an updated version of my timeline. Please review and notify me of any changes that you would like to see.

My schedule is getting hectic these days due to the approaching end-semester examinations of the university. Kindly allow me to continue with the rest of the work of the project (including the initial blog post) after my exams are over. Thank you.

[1]: https://docs.google.com/document/d/185MwknCxITC7Te6eDgs_8dmbIvVMYJcmWDHA0eTLi7Q/edit?usp=sharing

-- P Sudeepam

Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey


On Mon, May 7, 2018 at 1:03 AM, Sudeepam Pandey <[hidden email]> wrote:


On Wed, May 2, 2018 at 1:48 AM, Doug Stewart <[hidden email]> wrote:


On Tue, May 1, 2018 at 3:42 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 9:43 PM, Sudeepam Pandey <[hidden email]> wrote:


On Tue, May 1, 2018 at 3:00 AM, Rik <[hidden email]> wrote:
On 04/30/2018 12:57 PM, Sudeepam Pandey wrote:


On Fri, Apr 27, 2018 at 3:13 AM, Nicholas Jankowski <[hidden email]> wrote:
On Thu, Apr 26, 2018 at 4:46 PM, Sudeepam Pandey <[hidden email]> wrote:




Yes, I'll make sure that the auto-suggest feature has an easy enable/disable option. Maybe something like a command/ shortcut key to disable/enable the feature.

How may depend on how you implement it. if you made it strictly a GUI popup, then a GUI switch could make sense. if it will be inline with the interpreter, then it needs to be functional for --no-gui users. a shortcut key may be too dependent on your terminal of choice. So a command similar to 'more on' 'more off' may be the simplest and most portable. As per my message in the other thread, you should review how others have done it before.

Okay, so I was looking at some implementations of suggestion feature. I examined the suggestion feature of git, mercurial, and gcc. Most thoroughly, the one of git. I have also seen how MATLAB displays suggestions (the result that is, not the code). My research is ongoing but here are some initial observations.

- The most common algorithm for finding which words to suggest seems to be edit distance.
- I haven't figured out how gcc and hg turn on/ turn off this feature yet, but here is how git does it...

...when git realizes that the user has entered a command which it does not recognize, it pops up a 'did you mean' suggestion which has been calculated based on the edit distance algorithm. By default, it simply pops out a did you mean suggestion and does nothing more...git can however be customized to execute the suggested command directly after some time delay which can be defined using the help.autocorrect <time> command. Here is an example...

I strongly suggest that we implement some command to enable/disable the feature but do not add auto-execute like git...

Yes, there must be an enable/disable feature.  I also agree that we should NOT implement an auto-execute option at this time.

Its decided then.


Although I am still doing my research, here are my initial suggestions (based on some research and the discussions so far) about what the command line suggestion feature should be like....

1) The command line suggestion feature is triggered, whenever the interpreter realizes that it has to throw a...
   - "error: '<typo>' undefined near..." error
   - "error: set: unknown <axes/line etc..> property <property name>" error
   - others? (suggestions welcome)

I don't think that looking at other softwares to see when their suggestion features are triggered would be very useful because the errors and structures of all softwares are different after-all. The essence however, for every software, probably is that the compiler/interpreter of the software doesn't understand the meaning of a particular identifier that it has encountered. Therefore, I believe, that the errors we are looking for are the kind of errors where octave interpreter realizes that it doesn't understand what a particular word that the user has written means (and hence, is most probably a typo). The two errors mentioned above probably cover most of the cases. If anyone thinks that they do not, please suggest.


This seems correct.  This should get us coverage of most of the obvious typos.

Lets start the work with these then. If someone suggests something later on, we can modify it.

2) Immediately after the aforementioned errors are thrown, a script (say didYouMean) is called with the misspelled function/property name/ keyword... etc...


This architecture is very similar to the one that Octave already uses for unimplemented functions.  See the documentation for missing_function_hook().  The function missing_function_hook() works together with the parser.  When the parser doesn't recognize an identifier, it calls whatever has been set up as the callback function in missing_function_hook().  Currently, that function is scripts/help/__unimplemented__.  Take a look as well at __unimplemented__.m to see how it operates.

Thank you. I'll take a look and ask if I have further doubts.

The Octave project coding convention is not to use CamelCase so perhaps your function should be __suggestions__ rather than didYouMean?

Of course. That was just an example.

For development, you can quickly substitute your own suggestion function by pointing the missing_function_hook to your own m-file.

Note 1: This would require adding a small piece of code to the main file that generates these error messages on the command window. Can anyone help me figure out what files these are?

It seems to me that there may need to be a missing_property_hook () function, written in C++, that would behave like missing_function_hook when a graphics property is unrecognized.

I can try to implement it after I understand how missing_function_hook () works. Can't be sure at this point though. Let me take a look at missing_function_hook () first.


Note 2: To add a on/off feature. This script should be callable from the command window, with a simple flag value (0/1) to (turn off/turn on) this feature. I am not very sure about this but I suppose that if the on/off feature is implemented in this way, then it would not require separate implementations for GUI and CLI. The flag value will be permanent and can only be changed by calling the script with the appropriate argument from the command window.

3) If the flag value is 0 then further execution of the script does not take place and nothing is printed on the octave command window. User can continue with whatever they were doing.

4) If the flag value was 1, a separate script is called, which calculates what functions/keywords to suggest based on the edit distance (to begin with), or Neural Networks (at a later stage maybe) or some other better algorithm (if we happen to find one). This algorithm should have minimum speed-accuracy trade-off. Since the algorithm will be written down in a separate script, it should be easier to modify later on as technology evolves.


Sure, this would work.  Alternatively, just set missing_component_hook to "" when you don't want to use it.

4) The suggestion(s) are returned to the previous script (didYouMean) in the form of a list (in an array that is). Let the array that stores the suggestions be named 'suggestions' The script then generates something like this on the command window...

ex: say the particular misspelled word was 'akuse'

>> akuse
>> error: 'akuse' undefined near line 1 column 1
Did you mean any of the following...
1) amuse
2) abuse
3) amused
Enter the corresponding number to execute the command...
>>1 #say user enters 1

5) The user types 1 and presses enter...didYouMean execute the command corresponding to suggestions(1).

Take a look at the function menu().  It takes a cell array of strings as input and creates a numbered list, and then returns the selected input.  It's already coded and does precisely what you want.

--Rik

Alright I'll take a look.

Thanks for your detailed reply Rik. This would give me a very good starting point.

I played with __unimplemented__.m function a little and it seems like this is exactly what we need to integrate a command line suggestion into Octave. I edited the script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

As of now, there is no real 'suggestion code' in __suggestion__.m script and it returns a simple line only... the point was to show that it works for CLI and GUI as well.

Here are the results:-

GUI

>> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
>>

CLI

octave:1> cld
did you mean: clc
error: 'cld' undefined near line 1 column 1
octave:1>

A lot of discussions have been done by now and I am thankful to the community for the same. To me, it seems like I am ready to start with the actual coding part of the project.

If members of the community have anymore suggestions, concerns etc. please share them.

To my assigned GSoC mentors, Douglas Stewart and Nicholas Jankowski, should I do the following now, before the actual coding period begins...?

1) Share an updated timeline with both of you, based on the discussions so far.


Yes
 
2) Start a post about the discussions that went through during the community bonding period on my blog.

Yes
 
3) Share with everyone, a prototype of the 'algorithm independent' implementation that shows how this feature integrates itself with octave through my public bitbucket repository?

Not sure that this is too important yet.


 
--P Sudeepam



--
DASCertificate for 206392


Here[1] is an updated version of my timeline. Please review and notify me of any changes that you would like to see.

My schedule is getting hectic these days due to the approaching end-semester examinations of the university. Kindly allow me to continue with the rest of the work of the project (including the initial blog post) after my exams are over. Thank you.

[1]: https://docs.google.com/document/d/185MwknCxITC7Te6eDgs_8dmbIvVMYJcmWDHA0eTLi7Q/edit?usp=sharing

-- P Sudeepam


I'm a little anxious because I received no word from the maintainers. Is the new time-line alright?

Also, am I allowed to work a little less this week because of my ongoing examinations? I promise to make up in the following weeks..
Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey
In reply to this post by Rik-4


On Wed, May 2, 2018 at 9:34 PM, Rik <[hidden email]> wrote:
On 05/02/2018 05:55 AM, Sudeepam Pandey wrote:


Understood Doug.

There is one last thing left for me to figure out kindly help me with the same.

Like I sad before...I edited the __unimplemented__.m script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

There are a two things that still need to be taken care of..

1) First of all, we absolutely need a on/off switch for this feature. However, __suggestion__.m will be designed as an internal function (called when an identifier is not found in the unimplemented functions list) so users cannot directly call this function.
So to design a command which can act as a switch for this feature, we can write a m script (say flag.m) which is callable from the command window with a flag value and which would save the desired flag value (indicating on/off) in a .mat file in the "..octave/scripts/help" directory (where __suggestions__.m would reside). The __suggestions__.m script would load this value as soon as it is called and act accordingly. This way the user setting will be saved and will remain protected unless they modify it themselves.
I however, don't understand what files do I have to tweak so that the parser learns to identify this function (flag.m) as a new function of octave, callable from the command window. Also, if we went along with this, what path should I set inside the flag.m file so that the .mat file in "..octave/scripts/help" directory gets updated successfully? considering that the path BEFORE "../octave/scripts/help" would be different for each user, depending on where they have saved their copy of octave.
I understand that I may have said somethings incorrectly here, or that my thinking may be wrong at some places (for example, maybe we have to have a flag.cc file and not a flag.m file) but this approach is probably how a very good on/off feature could be made. Help and suggestions would be appreciated.

I would suggest using getpref()/setpref() for the time being.  For the namespace, use "Octave".  For the actual name of the preference, maybe something like "autosuggest".  In this case, your code can use getpref to check whether the value is boolean true before continuing.  For the time being you don't even need to write an m-file to enable/disable the option.  You can just use setpref directly.  Later on, you could wrap setpref() in an m-file to give it a nice interface.


2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are...
   a) How do we do it? What files do we tweak?
The file to inspect is libinterp/corefcn/graphics.cc.

grep -n error graphics.cc | grep property

74:  error ("set: invalid value for %s property", pname.c_str ());
104:    error ("%s: unknown %s property %s",
116:      error ("%s: ambiguous %s property name %s; possible matches:\n\n%s",
1312:        error (R"(invalid value for color property "%s")",
1346:              error (e, R"(invalid value for color property "%s" (value = %s))",
1356:        error (R"(invalid value for color property "%s")",
1369:    error (R"(invalid value for color property "%s")",
1384:        error (R"(invalid value for double_radio property "%s")",
1411:    error (R"(invalid value for double_radio property "%s")",
1657:        error (R"(set: invalid graphics handle (= %g) for property "%s")",
1660:        error (R"(set: invalid graphics object type for property "%s")",
1851:        error ("addproperty: missing possible values for radio property");
1913:        error ("addproperty: unsupported type for dynamic property (= %s)",
1937:        error ("addproperty: invalid object type (= %s)",
2194:            error ("invalid %s property '%s'", pfx.c_str (), pname.c_str ());
2219:    error ("invalid default property specification");
3069:              error (e, "error setting default property %s", pname.c_str ());
3098:    error (R"(get: unknown property "%s")", pname.c_str ());
3141:    error (R"(set: unknown property "%s")", pname.c_str ());
3157:    error (R"(get_property: unknown property "%s")", pname.c_str ());
5031:      error ("set: expecting text graphics object or character string for %s property, found %s",
10885:            error ("set: unknown property");
11115:            error ("__go_%s__: missing value for parent property",
11988:    error ("addproperty: invalid graphics object (= %g)", h);
11995:    error ("addproperty: a '%s' property already exists in the graphics object",

Only the error statements which deal with an unknown property would need modification.  I think the idea would be to intercept the error call about an unknown property.  At each point you would first check for missing_property_hook().  If it was empty then error out in the same way as before.  Otherwise, call the function provided in missing property hook and then call error() with whatever text was returned from the suggestions.  Note, that this would just give you suggestions, it would not necessarily be possible to print a menu and have the user decide which one they wanted to change the text to.

All, particularly, Nicholas, Doug, and Rik, I have been able to figure out what error statements would need modifications to make the suggestion feature work for graphic properties. One thing that I could do, is call my suggestion script before the call to the error function and have it return possible correction(s) which could then be passed to the error message to show some suggestions to the users. This, obviously, is an initial thought and the actual UI could be made different.
Regardless of what the UI is made to look like, it will be essential to call the suggestion script (an m-script) from within this c++ file. Could anyone of you explain/point to some article or documentation that explains, how I could call one of my m-scripts from within a c++ file with the incorrect spelling and a flag and have it return some suggestions back? My c++ is not very strong but thankfully, using the above method, a call from this file is all that I would need to do using c++. Every other thing will be handled very well using m-scripts.



   b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook?

If you implement it the way I suggested then the two functions are at different levels of parsing and missing_function_hook would take precedence over missing_property_hook.


...and maybe more challenges when we start thinking how?

I really would like to include properties as well but I'm not sure if they could be done right now. Can anyone help with this?

--P Sudeepam


Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Rik-4
On 06/17/2018 11:58 AM, Sudeepam Pandey wrote:


On Wed, May 2, 2018 at 9:34 PM, Rik <[hidden email]> wrote:
On 05/02/2018 05:55 AM, Sudeepam Pandey wrote:


Understood Doug.

There is one last thing left for me to figure out kindly help me with the same.

Like I sad before...I edited the __unimplemented__.m script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

There are a two things that still need to be taken care of..

1) First of all, we absolutely need a on/off switch for this feature. However, __suggestion__.m will be designed as an internal function (called when an identifier is not found in the unimplemented functions list) so users cannot directly call this function.
So to design a command which can act as a switch for this feature, we can write a m script (say flag.m) which is callable from the command window with a flag value and which would save the desired flag value (indicating on/off) in a .mat file in the "..octave/scripts/help" directory (where __suggestions__.m would reside). The __suggestions__.m script would load this value as soon as it is called and act accordingly. This way the user setting will be saved and will remain protected unless they modify it themselves.
I however, don't understand what files do I have to tweak so that the parser learns to identify this function (flag.m) as a new function of octave, callable from the command window. Also, if we went along with this, what path should I set inside the flag.m file so that the .mat file in "..octave/scripts/help" directory gets updated successfully? considering that the path BEFORE "../octave/scripts/help" would be different for each user, depending on where they have saved their copy of octave.
I understand that I may have said somethings incorrectly here, or that my thinking may be wrong at some places (for example, maybe we have to have a flag.cc file and not a flag.m file) but this approach is probably how a very good on/off feature could be made. Help and suggestions would be appreciated.

I would suggest using getpref()/setpref() for the time being.  For the namespace, use "Octave".  For the actual name of the preference, maybe something like "autosuggest".  In this case, your code can use getpref to check whether the value is boolean true before continuing.  For the time being you don't even need to write an m-file to enable/disable the option.  You can just use setpref directly.  Later on, you could wrap setpref() in an m-file to give it a nice interface.


2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are...
   a) How do we do it? What files do we tweak?
The file to inspect is libinterp/corefcn/graphics.cc.

grep -n error graphics.cc | grep property

74:  error ("set: invalid value for %s property", pname.c_str ());
104:    error ("%s: unknown %s property %s",
116:      error ("%s: ambiguous %s property name %s; possible matches:\n\n%s",
1312:        error (R"(invalid value for color property "%s")",
1346:              error (e, R"(invalid value for color property "%s" (value = %s))",
1356:        error (R"(invalid value for color property "%s")",
1369:    error (R"(invalid value for color property "%s")",
1384:        error (R"(invalid value for double_radio property "%s")",
1411:    error (R"(invalid value for double_radio property "%s")",
1657:        error (R"(set: invalid graphics handle (= %g) for property "%s")",
1660:        error (R"(set: invalid graphics object type for property "%s")",
1851:        error ("addproperty: missing possible values for radio property");
1913:        error ("addproperty: unsupported type for dynamic property (= %s)",
1937:        error ("addproperty: invalid object type (= %s)",
2194:            error ("invalid %s property '%s'", pfx.c_str (), pname.c_str ());
2219:    error ("invalid default property specification");
3069:              error (e, "error setting default property %s", pname.c_str ());
3098:    error (R"(get: unknown property "%s")", pname.c_str ());
3141:    error (R"(set: unknown property "%s")", pname.c_str ());
3157:    error (R"(get_property: unknown property "%s")", pname.c_str ());
5031:      error ("set: expecting text graphics object or character string for %s property, found %s",
10885:            error ("set: unknown property");
11115:            error ("__go_%s__: missing value for parent property",
11988:    error ("addproperty: invalid graphics object (= %g)", h);
11995:    error ("addproperty: a '%s' property already exists in the graphics object",

Only the error statements which deal with an unknown property would need modification.  I think the idea would be to intercept the error call about an unknown property.  At each point you would first check for missing_property_hook().  If it was empty then error out in the same way as before.  Otherwise, call the function provided in missing property hook and then call error() with whatever text was returned from the suggestions.  Note, that this would just give you suggestions, it would not necessarily be possible to print a menu and have the user decide which one they wanted to change the text to.

All, particularly, Nicholas, Doug, and Rik, I have been able to figure out what error statements would need modifications to make the suggestion feature work for graphic properties. One thing that I could do, is call my suggestion script before the call to the error function and have it return possible correction(s) which could then be passed to the error message to show some suggestions to the users. This, obviously, is an initial thought and the actual UI could be made different.
Regardless of what the UI is made to look like, it will be essential to call the suggestion script (an m-script) from within this c++ file. Could anyone of you explain/point to some article or documentation that explains, how I could call one of my m-scripts from within a c++ file with the incorrect spelling and a flag and have it return some suggestions back? My c++ is not very strong but thankfully, using the above method, a call from this file is all that I would need to do using c++. Every other thing will be handled very well using m-scripts.

As a first pass, I would implement exactly the methodology we have for missing_function_hook.  In pt-id.cc the function is

  void
  tree_identifier::eval_undefined_error (void)
  {
    int l = line ();
    int c = column ();

    maybe_missing_function_hook (name ());

    if (l == -1 && c == -1)
      error_with_id ("Octave:undefined-function",
                     "'%s' undefined", name ().c_str ());
    else
      error_with_id ("Octave:undefined-function",
                     "'%s' undefined near line %d column %d",
                     name ().c_str (), l, c);
  }

The list of calls to error() in graphics.cc above should be examined to find only the ones that elicit "unknown property".  For these errors I would create a local function err_unknown_property().  err_unknown_property would be the analog to eval_undefined_error above.  It would first call maybe_missing_property_hook (name ()) and then call error_with_id().  The function maybe_missing_property_hook should look like maybe_missing_function_hook in variables.cc

void
maybe_missing_function_hook (const std::string& name)
{
  // Don't do this if we're handling errors.
  if (buffer_error_messages == 0 && ! Vmissing_function_hook.empty ())
    {
      octave::symbol_table& symtab
        = octave::__get_symbol_table__ ("maybe_missing_function_hook");

      octave_value val = symtab.find_function (Vmissing_function_hook);

      if (val.is_defined ())
        {
          // Ensure auto-restoration.
          octave::unwind_protect frame;
          frame.protect_var (Vmissing_function_hook);

          // Clear the variable prior to calling the function.
          const std::string func_name = Vmissing_function_hook;
          Vmissing_function_hook.clear ();

          // Call.
          octave::feval (func_name, octave_value (name));
        }
    }
}

You will also need something like this from variables.cc adapted to graphics.cc

static std::string Vmissing_function_hook = "__unimplemented__";

DEFUN (missing_function_hook, args, nargout,
       doc: /* -*- texinfo -*-
@deftypefn  {} {@var{val} =} missing_function_hook ()
@deftypefnx {} {@var{old_val} =} missing_function_hook (@var{new_val})
@deftypefnx {} {} missing_function_hook (@var{new_val}, "local")
Query or set the internal variable that specifies the function to call when
an unknown identifier is requested.

When called from inside a function with the @qcode{"local"} option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
@seealso{missing_component_hook}
@end deftypefn */)
{
  return SET_INTERNAL_VARIABLE (missing_function_hook);
}

Hope this helps,
Rik




   b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook?

If you implement it the way I suggested then the two functions are at different levels of parsing and missing_function_hook would take precedence over missing_property_hook.


...and maybe more challenges when we start thinking how?

I really would like to include properties as well but I'm not sure if they could be done right now. Can anyone help with this?

--P Sudeepam



Reply | Threaded
Open this post in threaded view
|

Re: option for enabling/disabling auto-suggest feature

Sudeepam Pandey


On Tue, Jun 19, 2018 at 10:24 PM, Rik <[hidden email]> wrote:
On 06/17/2018 11:58 AM, Sudeepam Pandey wrote:


On Wed, May 2, 2018 at 9:34 PM, Rik <[hidden email]> wrote:
On 05/02/2018 05:55 AM, Sudeepam Pandey wrote:


Understood Doug.

There is one last thing left for me to figure out kindly help me with the same.

Like I sad before...I edited the __unimplemented__.m script a little so that, whenever octave fails to find an identifier among the unimplemented functions list as well, it calls my __suggestion__.m script, and this has worked nicely to produce a "Did you mean?" suggestion in the Octave command window in both GUI and CLI.

There are a two things that still need to be taken care of..

1) First of all, we absolutely need a on/off switch for this feature. However, __suggestion__.m will be designed as an internal function (called when an identifier is not found in the unimplemented functions list) so users cannot directly call this function.
So to design a command which can act as a switch for this feature, we can write a m script (say flag.m) which is callable from the command window with a flag value and which would save the desired flag value (indicating on/off) in a .mat file in the "..octave/scripts/help" directory (where __suggestions__.m would reside). The __suggestions__.m script would load this value as soon as it is called and act accordingly. This way the user setting will be saved and will remain protected unless they modify it themselves.
I however, don't understand what files do I have to tweak so that the parser learns to identify this function (flag.m) as a new function of octave, callable from the command window. Also, if we went along with this, what path should I set inside the flag.m file so that the .mat file in "..octave/scripts/help" directory gets updated successfully? considering that the path BEFORE "../octave/scripts/help" would be different for each user, depending on where they have saved their copy of octave.
I understand that I may have said somethings incorrectly here, or that my thinking may be wrong at some places (for example, maybe we have to have a flag.cc file and not a flag.m file) but this approach is probably how a very good on/off feature could be made. Help and suggestions would be appreciated.

I would suggest using getpref()/setpref() for the time being.  For the namespace, use "Octave".  For the actual name of the preference, maybe something like "autosuggest".  In this case, your code can use getpref to check whether the value is boolean true before continuing.  For the time being you don't even need to write an m-file to enable/disable the option.  You can just use setpref directly.  Later on, you could wrap setpref() in an m-file to give it a nice interface.


2) Another thing that bothers me is the absence of missing_property_hook() function...the approach that we have discussed does not work when we make a typo while typing a graphic/line property etc.. We can choose to add a missing_property_hook() function but this would have additional challenges. Examples are...
   a) How do we do it? What files do we tweak?
The file to inspect is libinterp/corefcn/graphics.cc.

grep -n error graphics.cc | grep property

74:  error ("set: invalid value for %s property", pname.c_str ());
104:    error ("%s: unknown %s property %s",
116:      error ("%s: ambiguous %s property name %s; possible matches:\n\n%s",
1312:        error (R"(invalid value for color property "%s")",
1346:              error (e, R"(invalid value for color property "%s" (value = %s))",
1356:        error (R"(invalid value for color property "%s")",
1369:    error (R"(invalid value for color property "%s")",
1384:        error (R"(invalid value for double_radio property "%s")",
1411:    error (R"(invalid value for double_radio property "%s")",
1657:        error (R"(set: invalid graphics handle (= %g) for property "%s")",
1660:        error (R"(set: invalid graphics object type for property "%s")",
1851:        error ("addproperty: missing possible values for radio property");
1913:        error ("addproperty: unsupported type for dynamic property (= %s)",
1937:        error ("addproperty: invalid object type (= %s)",
2194:            error ("invalid %s property '%s'", pfx.c_str (), pname.c_str ());
2219:    error ("invalid default property specification");
3069:              error (e, "error setting default property %s", pname.c_str ());
3098:    error (R"(get: unknown property "%s")", pname.c_str ());
3141:    error (R"(set: unknown property "%s")", pname.c_str ());
3157:    error (R"(get_property: unknown property "%s")", pname.c_str ());
5031:      error ("set: expecting text graphics object or character string for %s property, found %s",
10885:            error ("set: unknown property");
11115:            error ("__go_%s__: missing value for parent property",
11988:    error ("addproperty: invalid graphics object (= %g)", h);
11995:    error ("addproperty: a '%s' property already exists in the graphics object",

Only the error statements which deal with an unknown property would need modification.  I think the idea would be to intercept the error call about an unknown property.  At each point you would first check for missing_property_hook().  If it was empty then error out in the same way as before.  Otherwise, call the function provided in missing property hook and then call error() with whatever text was returned from the suggestions.  Note, that this would just give you suggestions, it would not necessarily be possible to print a menu and have the user decide which one they wanted to change the text to.

All, particularly, Nicholas, Doug, and Rik, I have been able to figure out what error statements would need modifications to make the suggestion feature work for graphic properties. One thing that I could do, is call my suggestion script before the call to the error function and have it return possible correction(s) which could then be passed to the error message to show some suggestions to the users. This, obviously, is an initial thought and the actual UI could be made different.
Regardless of what the UI is made to look like, it will be essential to call the suggestion script (an m-script) from within this c++ file. Could anyone of you explain/point to some article or documentation that explains, how I could call one of my m-scripts from within a c++ file with the incorrect spelling and a flag and have it return some suggestions back? My c++ is not very strong but thankfully, using the above method, a call from this file is all that I would need to do using c++. Every other thing will be handled very well using m-scripts.

As a first pass, I would implement exactly the methodology we have for missing_function_hook.  In pt-id.cc the function is

  void
  tree_identifier::eval_undefined_error (void)
  {
    int l = line ();
    int c = column ();

    maybe_missing_function_hook (name ()); [1]

    if (l == -1 && c == -1)
      error_with_id ("Octave:undefined-function",
                     "'%s' undefined", name ().c_str ());
    else
      error_with_id ("Octave:undefined-function",
                     "'%s' undefined near line %d column %d",
                     name ().c_str (), l, c);
  }

[1]: Thank you for helping Rik, can you please explain the exact purpose of the 'name ()' function here? Is it returning the identifier which was not recognized by the parser? Also, am I correct to think that we are able to directly call the 'maybe_missing_function_hook' here, because we have declared it as a free/global function in the variables.cc file and its header has been included in pt-id.cc? Please correct me if I'm wrong about this.

 
The list of calls to error() in graphics.cc above should be examined to find only the ones that elicit "unknown property".  For these errors I would create a local function err_unknown_property().  err_unknown_property would be the analog to eval_undefined_error above.  It would first call maybe_missing_property_hook (name ()) and then call error_with_id().  The function maybe_missing_property_hook should look like maybe_missing_function_hook in variables.cc

I realize that we have discussed the idea of a missing_property_hook() before as well (in this very thread). I do understand the flow that you have mentioned above and honestly, I have been trying to implement that. The thing is, I do not understand the code of missing_function_hook() very well and this is what has been preventing me to code up a missing_property_hook() that is exactly like the missing_function_hook().

For example, I do understand that....
          // Call.
          octave::feval (func_name, octave_value (name));
is somehow calling the m-script that the missing_function_hook points to, but I am not sure why this particular line has been written this way. The same can be said for other lines that are present in the two code snippets included below.

void
maybe_missing_function_hook (const std::string& name)
{
  // Don't do this if we're handling errors.
  if (buffer_error_messages == 0 && ! Vmissing_function_hook.empty ())
    {
      octave::symbol_table& symtab
        = octave::__get_symbol_table__ ("maybe_missing_function_hook");

      octave_value val = symtab.find_function (Vmissing_function_hook);

      if (val.is_defined ())
        {
          // Ensure auto-restoration.
          octave::unwind_protect frame;
          frame.protect_var (Vmissing_function_hook);

          // Clear the variable prior to calling the function.
          const std::string func_name = Vmissing_function_hook;
          Vmissing_function_hook.clear ();

          // Call.
          octave::feval (func_name, octave_value (name));
        }
    }
} 
 
You will also need something like this from variables.cc adapted to graphics.cc

static std::string Vmissing_function_hook = "__unimplemented__";

DEFUN (missing_function_hook, args, nargout,
       doc: /* -*- texinfo -*-
@deftypefn  {} {@var{val} =} missing_function_hook ()
@deftypefnx {} {@var{old_val} =} missing_function_hook (@var{new_val})
@deftypefnx {} {} missing_function_hook (@var{new_val}, "local")
Query or set the internal variable that specifies the function to call when
an unknown identifier is requested.

When called from inside a function with the @qcode{"local"} option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
@seealso{missing_component_hook}
@end deftypefn */)
{
  return SET_INTERNAL_VARIABLE (missing_function_hook);
}

Hope this helps,
Rik

As a solution, maybe I could code the local function err_unknown_property () and have it call the function missing_property_hook (), as discussed. However, for now, the only thing that missing_property_hook() would do, is trigger the suggestion feature by calling my __suggestions__.m script that displays the possible corrections for the misspelled identifiers. No auto-restoration (see code) etc. Maybe we can include a FIXME note with this and later on, someone who understands the code of missing_function_hook() very well could make the missing_property_hook() look exactly like the missing_function_hook().

However, I am willing to code an exact missing_property_hook() myself, but like I said, I would not be able to do so without some help. I would be thankful and would do the exact code if you or anyone else,
- could tell me how I should work my way to understand these two pieces of code,
- or, could explain the code of missing_function_hook() in detail,
- or maybe tell me what lines would be exactly the same and what lines would be modified and how they are modified.

Thankyou,
Sudeepam





   b) If we finally make it, what does the parser prioritize when it doesn't recognize an identifier? missing_function_hook or the missing_property_hook?

If you implement it the way I suggested then the two functions are at different levels of parsing and missing_function_hook would take precedence over missing_property_hook.


...and maybe more challenges when we start thinking how?

I really would like to include properties as well but I'm not sure if they could be done right now. Can anyone help with this?

--P Sudeepam




12