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.
Claims13
A computer-implemented method of identifying similar source code components comprising:
- creating, by an Integrated Development Environment (IDE) comprising at least a source code editor, build automation tools, and a debugger, a respective structural representation of each of a user-defined query source code data set and at least one target source code data set, wherein the user-defined query source code data set comprises a selected portion of source code in a given programming language presented in the IDE on a user interface, wherein the at least one target source code data set comprises a plurality of portions of source code in the given programming language;
- wherein the user-defined query source code structural representation comprises a query source code abstract syntax tree, wherein the at least one 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 each of one or more portions of each of the at least one target source code data sets, wherein each respective first similarity value comprises a topological measure of similarity between the user-defined query source code data set and each respective portion of the at least one target source code data set, 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 each respective target source code abstract syntax subtree;
- and
- calculating, for each respective target source code abstract syntax subtree, a respective absolute value of a difference between the first number and the respective second number;
- identifying, by the IDE, portions of each of the at least one target source code data sets having a respective first similarity value satisfying a first threshold, wherein the first threshold comprises a percentage of the target source code abstract syntax subtrees associated with lowest first similarity values;
- calculating, by the IDE, a respective second similarity value for each portion of the at least one target source code data set having a respective first similarity value satisfying the first threshold, the respective second similarity value comprising a semantic measure of similarity between the user-defined query source code data set and each respective portion of the at least one target source code data set having a respective first similarity value satisfying the first threshold;
- outputting, by the IDE and to the user interface, each portion of the at least one target source code data set having a second similarity value less than or equal to a second threshold.
A system for locating similar source code components, the system comprising:
- a user interface displaying an Integrated Development Environment (IDE) comprising at least a source code editor, build automation tools, and a debugger, the user interface configured to receive a user-selected query source code, wherein the user-selected query source code comprises a selected portion of text in a given programming language;
- a storage medium containing at least one target source code, wherein the at least one target source code comprises a plurality of portions of text in the given programming language;
- and
- a processor operably coupled to the user interface and the storage medium, wherein the processor is configured to:
- generate a respective structural representation of each of the user-selected query source code and the at least one target source code;
- wherein the user-selected query source code structural representation comprises a query source code abstract syntax tree, wherein the at least one 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;
- calculate a respective topological similarity value between the user-selected query source code and one or more portions of each of the at least one target source code wherein calculating a respective topological 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 each respective target source code abstract syntax subtree;
- and
- calculating, for each respective target source code abstract syntax subtree, a respective absolute value of a difference between the first number and the respective second number;
- identify portions of the at least one target source code having a topological similarity value satisfying a first threshold, wherein the first threshold comprises a percentage of the target source code abstract syntax subtrees associated with lowest first similarity values;
- calculate a respective semantic similarity value between the query source code and each identified portion of the at least one target source code having a respective topological similarity value satisfying the first threshold;
- and
- output, to the user interface, each of the portions of the at least one target source code having a respective semantic similarity value less than or equal to a second threshold.
A computer program product for locating similar source code components, the computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by a processor to cause the processor to:
- create, for a selected query source code component and one or more target source code data sets, a query source code syntax tree and one or more target source code syntax trees, wherein the selected query source code component is a selected portion of text in a given programming language, wherein each of the one or more target source code data sets comprise a plurality of respective portions of text in the given programming language, wherein each respective portion of text of each of the one or more target source code data sets comprises a target source code syntax subtree;
- wherein the query source code syntax tree comprises a query source code abstract syntax tree, wherein the one or more target source code syntax trees comprise respective target source code abstract syntax trees, and wherein respective portions of respective target source code abstract syntax trees comprise respective target source code abstract syntax subtrees;
- calculate a respective topological similarity value between the query source code syntax tree and one or more target source code syntax subtrees of the one or more target source code syntax trees, wherein calculating a respective topological 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 each respective target source code abstract syntax subtree;
- and
- calculating, for each respective target source code abstract syntax subtree, a respective absolute value of a difference between the first number and the respective second number;
- identify respective target source code syntax subtrees having a topological similarity value satisfying a first threshold, wherein the first threshold comprises a percentage of the target source code abstract syntax subtrees associated with lowest first similarity values;
- calculate a respective semantic similarity value between the query source code syntax tree and each target source code syntax subtree having a topological similarity value satisfying the first threshold;
- and
- output, to a user interface, target source code syntax subtrees with a respective semantic similarity value below a second threshold.
Dependencies are inferred from the claim text.