Source code search engine
AssigneeInternational Business Machines Corporation
InventorsNathan Fontenot, Fionnuala G. Gunter, Michael T. Strosaker, George C. Wilson
Life of this patent
Estimating the term…
Abstract
A source code search comprises a two-pass search. The first pass comprises a topological measure of similarity. The second pass comprises a semantic measure of similarity. The query source code is a user-selected portion of source code. The results may be ranked and output to an I/O device.
Claims14
A computer-implemented method comprising:
- creating, by an Integrated Development Environment (IDE) comprising a source code editor, build automation tools, and a debugger, a respective structural representation of each of a query source code and a target source code, wherein the query source code comprises a user-selected portion of source code in a programming language presented in the IDE on a user interface, wherein the target source code comprises a plurality of portions of source code in the programming language;
- wherein the query source code structural representation comprises a query source code abstract syntax tree, wherein the target source code structural representation comprises a target source code abstract syntax tree, and wherein respective portions of the target source code abstract syntax tree comprise a respective target source code abstract syntax subtree;
- calculating, by the IDE, a respective first similarity value for respective portions of the target source code, wherein respective first similarity values comprise respective topological measures of similarity between the query source code and respective portions of the target source code, wherein the calculating a respective first similarity value further comprises:
- calculating a first number of vertices and edges in the query source code abstract syntax tree;
- calculating a respective second number of vertices and edges in respective target source code abstract syntax subtrees;
- and
- calculating, for respective target source code abstract syntax subtrees, a respective absolute value of a difference between the first number and the respective second number;
- identifying, by the IDE, portions of the target source code having a first similarity value satisfying a first threshold;
- calculating, by the IDE, a second similarity value for each portion of the target source code having a first similarity value satisfying the first threshold, wherein the second similarity value comprises a semantic measure of similarity between the query source code and portions of the target source code having a first similarity value satisfying the first threshold;
- and
- outputting, by the IDE and to the user interface, each portion of the target source code having a second similarity value satisfying a second threshold.
A system comprising:
- a computer-readable storage medium storing instructions for an Integrated Development Environment (IDE) comprising a source code editor, build automation tools, and a debugger;
- and
- a processor configured to execute the instructions in the computer-readable storage medium to perform a method comprising:
- creating, by the IDE, a respective structural representation of each of a query source code and a target source code, wherein the query source code comprises a user-selected portion of source code in a programming language presented in the IDE on a user interface, wherein the target source code comprises a plurality of portions of source code in the programming language;
- wherein the query source code structural representation comprises a query source code abstract syntax tree, wherein the target source code structural representation comprises a target source code abstract syntax tree, and wherein respective portions of the target source code abstract syntax tree comprise a respective target source code abstract syntax subtree;
- calculating, by the IDE, a respective first similarity value for respective portions of the target source code, wherein respective first similarity values comprise respective topological measures of similarity between the query source code and respective portions of the target source code, wherein the calculating a respective first similarity value further comprises:
- calculating a first number of vertices and edges in the query source code abstract syntax tree;
- calculating a respective second number of vertices and edges in respective target source code abstract syntax subtrees;
- and
- calculating, for respective target source code abstract syntax subtrees, a respective absolute value of a difference between the first number and the respective second number;
- identifying, by the IDE, portions of the target source code having a first similarity value satisfying a first threshold;
- calculating, by the IDE, a second similarity value for each portion of the target source code having a first similarity value satisfying the first threshold, wherein the second similarity value comprises a semantic measure of similarity between the query source code and portions of the target source code having a first similarity value satisfying the first threshold;
- and
- outputting, by the IDE and to the user interface, each portion of the target source code having a second similarity value satisfying a second threshold.
A computer program product comprising a computer-readable storage medium having program instructions embodied therewith, wherein the computer-readable storage medium is not a transitory signal per se, the program instructions executable by a processor to cause the processor to perform a method comprising:
- creating, by an Integrated Development Environment (IDE) comprising a source code editor, build automation tools, and a debugger, a respective structural representation of each of a query source code and a target source code, wherein the query source code comprises a user-selected portion of source code in a programming language presented in the IDE on a user interface, wherein the target source code comprises a plurality of portions of source code in the programming language;
- wherein the query source code structural representation comprises a query source code abstract syntax tree, wherein the target source code structural representation comprises a target source code abstract syntax tree, and wherein respective portions of the target source code abstract syntax tree comprise a respective target source code abstract syntax subtree;
- calculating, by the IDE, a respective first similarity value for respective portions of the target source code, wherein respective first similarity values comprise respective topological measures of similarity between the query source code and respective portions of the target source code, wherein the calculating a respective first similarity value further comprises:
- calculating a first number of vertices and edges in the query source code abstract syntax tree;
- calculating a respective second number of vertices and edges in respective target source code abstract syntax subtrees;
- and
- calculating, for respective target source code abstract syntax subtrees, a respective absolute value of a difference between the first number and the respective second number:
- identifying, by the IDE, portions of the target source code having a first similarity value satisfying a first threshold;
- calculating, by the IDE, a second similarity value for each portion of the target source code having a first similarity value satisfying the first threshold, wherein the second similarity value comprises a semantic measure of similarity between the query source code and portions of the target source code having a first similarity value satisfying the first threshold;
- and
- outputting, by the IDE and to the user interface, each portion of the target source code having a second similarity value satisfying a second threshold.
Dependencies are inferred from the claim text.