A portion of the disclosure of this patent document may contain material that is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent files or records, but otherwise reserves all copyright rights whatsoever. The following notice shall apply to this document: Copyright© 2005, Microsoft Corp.
The present aspects generally relate to the field of computing. More specifically, they relate to lexical, grammatical, and semantic inference mechanisms.
Computer users may know what they intend or want to express, but sometimes their intentions are not clearly communicated to a computer system, either because such users make mistakes or don't fully appreciate what they want to express. For example, in the case of developers writing computer code, namely, source code, the intended coding of source code, on the one hand, and what actually gets coded, on the other, may differ vastly. This may occur because the developer mistyped some terms and in fact intended different terms, or because the developer didn't fully realize what terms should have been provided in the source code in the first place.
Upon coding some program, developers may want to compile it (turning source code into object code), but if there are any lexical, grammatical, or semantic mistakes, the program will not compile and the developers may spend an inordinate amount of time correcting the mistakes until they are able to compile the program. Thus, these lexical, grammatical, or semantic mistakes must be addressed even before such a program becomes compilable and therefore subject to debugging.
Also, depending on the type of developer that is coding the source code, one developer may want to fix his mistakes as he is coding, while another developer may want to correct her mistakes at the end of the coding process, once the general program flow and ideas have been set in place. Any feedback regarding such mistakes should be able to accommodate different developing styles, whether by offering suggestions up front as a developer is coding or corrections at the end of the coding process that fix any mistakes. In either case, inferences have to be made as to what a developer meant as opposed to what got actually coded.
In short, inferences about developer mistakes have to be made in order for computer code to be compilable. These inferences are varied and complex and depend on a variety of factors, such as the context of the code. Such inferences may be made on a “word” level, a “grammatical” level, a “meaning” or “semantic” level, a pedagogical level (where the developer has to learn what the proper code is, as in the example of the wrong type being used), developer style level (where either suggestions or fixes are made), and so on. A variety of such inferences have to be made, and these are merely a handful of them.
In one aspect taught herein, a user's intent is inferred in interacting with a computing system, for example, in developing a computer code. First, at least one token of the computer code developed by the user is obtained. Then, an inference mechanism is used, where the inference mechanism examines such a token to find out if a mistake has been made by the user in developing that token. The mistake is determined by examining a combination of lexical and syntactic code rules, and a semantic heuristics. Upon identifying any such mistakes, a suggestion and correction are provided in order to remedy the mistake, where the inference mechanism provides the at least one suggestion or correction according to a predetermined standard.
For instance, examining the combination of the syntactic code rules and the semantic heuristics can entail the comparing of scope proximity of a token to at least another token in the code, comparing variable types in the code, examining the number of parameters and arguments in functions and function calls, respectively. Furthermore, examining the aforementioned combination can be based on feedback of how the user is developing the code and how the user has classified private and public accessibility of the code. Lastly, the inference mechanism itself is extensible so that additional syntactic code rules (and lexical rules, for that matter) and semantic heuristics can be added to the existing code rules and heuristics in order to improve inferring the user's intent.
Furthermore, lexical and syntactic code rules can be automatically gleaned from a formal specification for a language that specifies exactly what the correct rules are. Interestingly, the semantic heuristics can also be gleaned from such a formal specification, although they may also be supplemented by manually encoded input.
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used as an aid in determining the scope of the claimed subject matter.
The foregoing Summary, as well as the following Detailed Description, is better understood when read in conjunction with the appended drawings. The following figures are included:
Overview
Various aspects are discussed herein for inferring a computer user's (or more specifically, a developer's) intent in developing computer system code (or any other such code that can be compiled). In particular, an inference mechanism is provided that can infer a user's intent at least on three levels: a lexical level, a grammatical level, and a semantic level. The inference mechanism uses various rule and heuristic techniques illustrated in the figures, including type coercion, scope proximity, parameter count and arguments, and so on. The inference mechanism also has some dynamic heuristics that it derives from the published language specification for a language being analyzed.
Moreover, various inference mechanism controls are also discussed, where these controls are employed to increase inference robustness, including timing of making suggestions, the number of suggestions, and the extensibility of suggestions. Lastly, an exemplary computing environment is provided where the inference mechanism can be used.
Aspects of Lexical, Syntactical and Semantic Inference Mechanisms
According to
At the lexical level 106, tokens are examined, where a token is just any atomic piece of code, such as “int” or “float” or a “if” statement, a variable, or even a scope resolution curly bracket (“{”). Examining the lexical level for a user's intent entails inquiring whether a user might have, for example, inadvertently switched or misspelled tokens. This might happen if a user types “if ( )x” instead of “if(x)”. In such a situation, a user misplaced the “)” bracket and the “x” variable.
The compiler can also examine the grammatical level 108, which includes an inquiry into the proper arrangement of tokens according to computer language rules. The “if( )x” example, discussed above, also happens to be grammatically incorrect, since a parameter like “x” is supposed to be inside the brackets—at least according to high level computer languages like C, C++, C#, etc. There are situations where a variable may be token-wise correct but grammatically incorrect. And then, there may be situations where the two levels overlap, as in the example discussed above.
Furthermore, the compiler can also examine the semantic level 110 to try to ascertain what the user meant based on various heuristics. Such semantic examination of code includes getting at the intention of a user when that intention cannot necessarily be ascertained from the grammatical level 108 mistakes (because there may not be any such mistakes) or from lexical level 106 token misplacement (again, because such mistakes may not be apparent). In such a case, meaning can be gleaned from the way a user has previously developed code and the way the user is using code. All three levels 106, 108, and 110 can also be examined in conjunction in order to obtain a more certain result.
Importantly, within each of the three levels of inquiry considered above, there may be various sub-levels of inquiry particular to any given level. For example, in the lexical level 106 scenario, a compiler can check up to some set number of switching-of-token mistakes 112 but not more than that. Thus, in one aspect, the number of switching-of-token mistakes is set at four. This means that in the “if ( )x” example, up to four switching mistakes could be considered. In this example, two switching mistakes are made: the “)” is switched in the place of “x” and vice versa. But if there is code that requires up to five switches, then it is not considered. The reason for putting a limit on this is because given an unlimited number of switches, any meaningless code would be converted into something meaningful—or something meaningful could be converted into some else that is meaningful and means something different—but was not the intended meaning by the user.
Likewise, the other levels discussed above, namely, the grammatical level 108 and the semantic level 110 can be limited to a set number of sub-levels of inquiry 114 and 116, respectively. Thus, a grammatical error could be limited to the simplest resolution of the error using no more than four computer language rules (per the appropriate language, like C, C++, C#, etc.). And, a semantic error could be limited to the simplest resolution of the error using no more than four intention resolving heuristics. As those skilled in the art will readily appreciate, other code examining levels of inquiry can be employed, and these three levels are merely exemplary, as are their sub-levels of inquiry.
Interestingly, the suggestions 206 can be used by the type of developers that like to fix any errors as they are coding, and corrections 208 can be either accepted or rejected by the type of developers that like to code first and fix any errors at the end of the coding process. Moreover, suggestions 206 can be used by the type of developers who want to integrate the inference mechanism 202 into their development practices and depend on it to save them time writing the code manually.
In one aspect, statement completion mechanisms are provided. In reference to
The prefix statement completion mechanism is just one example of statement completion. A suffix statement completion mechanism 312 can also be used. Thus, in
Interestingly, intermediate statement completion mechanisms 308 can be used. Again, given two types of statements that may be defined in a program, namely, VeryLongName1302 and VeryLONGName2304, typing in the intermediate character designation of a statement may result in some suggestion 314. In particular, typing in “Long” will suggest 314 VeryLongName1302, while typing “LONG” will suggest VeryLONGName2304.
Even more interestingly, unique statement completion mechanisms 310 can also be used. For example, the statement VeryLongName1302 has several unique characters with respect to any other statement, in this case, VeryLONGName2304. If a user were to type a small “o” VeryLongName1302 could be suggested, whereas if the user typed an uppercase “O” VeryLONGName2304 would be suggested 314. Likewise, there are other characters that makes the two statements unique, some of which include other letters like “N”/“n” or “G”/“g” or numbers like “1”/“2”. Any unique character (whether letter, number, or any other symbol) or name may be used to obtain the desired suggestion 314 that reflects what the user intends or intended to type.
In another aspect, type coercion is performed.
Furthermore, if a user introduces a variable like “string” type (not illustrated) into the “if” statement, a coercion 404 of the “string” type into “bool” type could be made. By knowing the proper grammar of any given language and examining the semantics of the user's program, a proper type can be introduced so as to avoid confusing a complier and preventing source code from not compiling.
In still another aspect, the grammar and semantics of a user's code could be examined to suggest the correct type and number of statements to use. As
Furthermore, the suggestion of whether to use two arguments (if three arguments are used elsewhere in a program) or three arguments (if two arguments are used elsewhere in the program) could be based on the semantics of a program containing both the function call and the function itself. For example, if there are numerous two argument function calls it might be suggestive that three input parameters in the function itself is incorrect. Alternatively, if one function call has two arguments and the rest have three arguments, and the function itself is expecting three parameters, based on these semantics, it could be inferred that the function call should be changed to contain three arguments.
Moreover, the suggestion 504 made by an inference mechanism may reference the type of argument to be input. As discussed above with regard to type coercion, if a user inputs two “int” types into a function call, but a function is expecting, for example, one “int” type and a “string” type, then a suggestion can be made that the user change the latter type to a “string” type—or vice versa, depending on the semantics of the code.
In yet another aspect, in
In a further aspect, properties of parameters which are most likely to work are suggested as inputs to functions, conditionals, etc. For example, in
In one aspect, suggestions regarding a possible user mistake are made based on scope proximity. Put another way, if a parameter is typed by a user and it is not recognized by the compiler, suggestions based on relevant parameters that are close in scope are made. The an important insight of the scope proximity aspect is that parameters that are closer in scope are more relevant.
For example, in
Referring again to
In yet another aspect, suggestions are based on feedback in how parameters are used, how methods are called, and so on. For example, in
However, even though “i” was meant to be declared as an “int” type of variable, in the next line in void main( ) 906, function call Foo(i).ToUppercase( ) is made. Since it does not make sense to call “ToUpperCase” on an “int”—rather that's a proper call on a string type—the user must have meant to type “ii” in the Foo(i).ToUppercase( ) function call.
Furthermore, the proper intended use of a variable can be gleaned from function calls. If some function takes in parameters of one type, but the passed in variable to a function is of another type, an inference case be made that the passed in variable is of the wrong type and should be corrected.
Another important aspect of the inference mechanism is that when the mechanism has a suggestion to make in order to fix a mistake, it will attempt to see how “good” that suggestion is. One way it does this is by pretending the user typed the suggestion in rather than what they've actually typed. The mechanism can then see how many errors/problems are caused when using such a “suggestion”. So, for example, in the Foo(i).ToUpperCase( ) case the inference mechanism sees that “Foo(i)” is a problem. The variable “i” is of type “in” which isn't valid for the “Foo(int)” or “Foo(string)” functions. So two suggestions are proposed internally: “rename ‘in’ to ‘int’” or “replace ‘i’ with ‘ii’”. After determining this initial set of suggestions, the inference mechanism feeds both suggestions back into the code to see which is better. Renaming “in” to “int” helps a little, but then a later problem occurs since you cannot call ToUpperCase on an “int” (i.e. Foo(i).ToUpperCase( ) will be an error even if “i” is an “int”), whereas the change of ‘i’ to ‘ii’ is seen as the better choice because “Foo(ii).ToUpperCase( )” is completely valid code.
Furthermore, inference determination can be performed on a multi-level basis. For example, Foo(i).ToUperCase( ) could be called, where the “Upper” is misspelled as “Uper”. Now, the inference engine will perform multilevel inference with feedback in order to determine the best possible suggestion-taking into account the lexical propriety of “Uper” and the syntactic propriety of passing an “in” to a string function Foo(string). In short, the constantly feedback of an inference back into itself until a suggestion is found that has stayed “alive” the longest (or which has produced the largest amount of correct code) is yet another aspect the inference mechanism implements.
Aspects of Inference Mechanism Control
The inference mechanisms discussed above can be subject to a variety of controls or predetermined standards. For example, the confidence level of a suggestion or correction can be set to some default setting, as can the number of suggestions and correction presented to a user, and the time interval between a user action and a suggestion. These are merely exemplary control standards and are not meant to be limiting or exhaustive.
In another aspect, the confidence level of a suggestion can be set either by a computing system or by a user, and moreover, it can be set to some desired level.
A user may also set a certain cut-off point where suggestions are not to be made below a certain confidence level. For example, in reference to
Interestingly enough, not only can the user set 1006 the suggestion settings, but they can also be set by a computing system 1004. Vendors who come up with the numerous inference mechanisms (that may be set by the computing system), have a great deal of experience as to which suggestions work and don't work, and which suggestions are the most useful to a particular audience, such as developers, and which are not useful. However, users can supplement these vendor pre-packaged suggestion with those that suit their own purpose.
In still another aspect, a select number of suggestions are made depending on how relevant a suggestion is to a mistyped term.
In a further aspect, in
In still a further aspect,
In yet another aspect, one way to present a user with such suggestions is to allow a completion list to pop-up upon the user's hitting a period (“.”).
In still another aspect,
Exemplary Computing Environment for Token Semantic and Syntactical Inferences
Token, semantic and syntactical inferences are useful in a variety of computing environments. For example, they could be used in coding for printers, applications, or even the central processing units. Use of such inferences reduces the cost to correct errors that inherently entails any kind of coding project while at the same time increases the efficiency of users of such inferences.
Although not required, the above discussed aspects can be implemented via an operating system, for use by a developer of services for a device or object, and/or included within application or server software that operates in accordance with the various aforementioned aspects. Software may be described in the general context of computer-executable instructions, such as program modules, being executed by one or more computers, such as client workstations, servers or other devices. Generally, program modules include routines, programs, objects, components, data structures and the like that perform particular tasks or implement particular abstract data types. Typically, the functionality of the program modules may be combined or distributed as desired in various embodiments. Moreover, the aspects may be practiced with other computer system configurations and protocols. Other well known computing systems, environments, and/or configurations that may be suitable for use with the aspects include, but are not limited to, personal computers (PCs), automated teller machines, server computers, hand-held or laptop devices, multi-processor systems, microprocessor-based systems, programmable consumer electronics, network PCs, appliances, lights, environmental control elements, minicomputers, mainframe computers and the like.
With reference to
Computer 110 typically includes a variety of computer readable media. Computer readable media can be any available media that can be accessed by computer 110 and includes both volatile and nonvolatile media, removable and non-removable media. By way of example, and not limitation, computer readable media may comprise computer storage media and communication media. Computer storage media include both volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CDROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by computer 110. Communication media typically embody computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and include any information delivery media. The term “modulated data signal” means a signal that has one or more of its characteristics set or changed in such a manner as to encode information in the signal. By way of example, and not limitation, communication media include wired media such as a wired network or direct-wired connection, and wireless media such as acoustic, RF, infrared and other wireless media. Combinations of any of the above should also be included within the scope of computer readable media.
The system memory 130 includes computer storage media in the form of volatile and/or nonvolatile memory such as read only memory (ROM) 131 and random access memory (RAM) 132. A basic input/output system 133 (BIOS), containing the basic routines that help to transfer information between elements within computer 110, such as during start-up, is typically stored in ROM 131. RAM 132 typically contains data and/or program modules that are immediately accessible to and/or presently being operated on by processing unit 120. By way of example, and not limitation,
The computer 110 may also include other removable/non-removable, volatile/nonvolatile computer storage media. By way of example only,
The drives and their associated computer storage media discussed above and illustrated in
The computer 110 may operate in a networked or distributed environment using logical connections to one or more remote computers, such as a remote computer 180. The remote computer 180 may be a personal computer, a server, a router, a network PC, a peer device or other common network node, and typically includes many or all of the elements described above relative to the computer 110, although only a memory storage device 181 has been illustrated in
When used in a LAN networking environment, the computer 110 is connected to the LAN 171 through a network interface or adapter 170. When used in a WAN networking environment, the computer 110 typically includes a modem 172 or other means for establishing communications over the WAN 173, such as the Internet. The modem 172, which may be internal or external, may be connected to the system bus 121 via the user input interface 160, or other appropriate mechanism. In a networked environment, program modules depicted relative to the computer 110, or portions thereof, may be stored in the remote memory storage device. By way of example, and not limitation,
While the present aspects have been described in connection with the preferred aspects, as illustrated in the various figures, it is understood that other similar aspects may be used or modifications and additions may be made to the described aspects for performing the same function of the present aspects without deviating therefrom. For example, in one aspect, lexical, syntactical and semantic inferences were provided that gleaned a user's intended computer use. However, other equivalent aspects to these described are also contemplated by the teachings herein. Therefore, the present aspects should not be limited to any single aspect, but rather construed in breadth and scope in accordance with the appended claims.