Method and system for bug localization based on code knowledge graph
Disclosed are a method and a system for bug localization based on a code knowledge graph, including the steps of: extracting source codes from a Git version control system, parsing in the source codes to generate an abstract syntax tree (AST), constructing a code knowledge graph, preprocessing the summary and description of a bug report crawled from a Bugzilla bug tracking system, and performing the named entity recognition to identify bug-related entity sequence, converting the code knowledge graph and the bug-related entity sequence into vector representation through an embedding algorithm, calculating cosine similarities of vector representations between the code knowledge graph and the bug entity sequence, ranking the similarities from high to low to generate a list of suspicious methods, filtering redundant information in the source codes, identifying bug-related entity elements in the bug report, and reserving the bug-related information.
1 . A method for bug localization based on a code knowledge graph, comprising the following steps:
step 1 : extracting source codes of AspectJ, Standard Widget Toolkit (SWT) and Zxing from a Git version control system;
step 2 : parsing in the source codes through a code parser to generate an abstract syntax tree (AST) of the source codes;
step 3 : extracting entities and relationships from the AST to build the code knowledge graph;
step 4 : crawling a bug report from an open-source Bugzilla bug tracking system, and obtaining a summary and description of the bug report;
step 5 : preprocessing the summary and description of the bug report through a Natural Language Toolkit (NLTK) toolkit to obtain a bug report data set;
step 6 : performing named entity recognition on the bug report data set, and extracting a bug report entity sequence;
step 7 : performing vector representation on the bug report entity sequence and the code knowledge graph jointly through Word2Vec and a knowledge graph embedding algorithm; and
step 8 : mapping the vector representation on the bug report entity sequence and the code knowledge graph to the same vector space, calculating cosine similarities between the vector representation of the bug report entity sequence and the vector representation of the source file code knowledge graph, and ranking the cosine similarities from high to low to generate a list of suspicious bug code,
wherein bug-related files are mined through the list of suspicious bug code so that accuracy of bug localization is improved,
wherein bugs repairing is conducted through the bug-related files so that time and energy costs are reduced.
2 . The method for bug localization based on the code knowledge graph according to claim 1 , wherein in the step 2 , the source codes are parsed into the AST by using a Spoon source code parser, a control flow is moved from a source code package to a class contained in the source code package, and then to variables and suspicious bug code declared in the class, each suspicious bug code is analyzed, and parameters, the variables and comments are recorded.
3 . The method for bug localization based on the code knowledge graph according to claim 1 , wherein in the step 3 , the code knowledge graph is composed of package, class, method, parameter, variable and statement as entities, and hasPackage, has Variable, hasMethod, hasParameter, Extend, hasStatement and Call as edge types, and it is visualized through a Neo4j graph database.
4 . The method for bug localization based on the code knowledge graph according to claim 1 , wherein in the step 6 , a BIO sequence labeling suspicious bug code is used to manually label the bug report data set, and a BiLSTM-CRF is used to perform the named entity recognition, so that bug entity sequences are extracted.
5 . A system for bug localization based on a code knowledge graph, comprising a processor and a memory storing instructions executable by the processor, wherein the processor is configured to execute the instructions to implement:
a source code extraction module, a source code parsing module, a code knowledge graph construction module, a bug report crawling module, a data set construction module, a named entity recognition module, a vectorization module, and a similarity calculation module;
wherein the source code extraction module is used for extracting source codes of AspectJ, Standard Widget Toolkit (SWT) and Zxing are extracted from a Git version control system;
the source code parsing module is used for parsing in the source codes through a code parser to generate an abstract syntax tree (AST) of the source codes;
the code knowledge graph construction module is used for extracting entities and relationships from the constructed AST to construct the code knowledge graph;
the bug report crawling module is used for crawling a bug report from an open-source Bugzilla bug tracking system, and obtaining a summary and description of the bug report;
the data set construction module is used for preprocessing the summary and description of the bug report through a Natural Language Toolkit (NLTK) toolkit to obtain a bug report data set;
the named entity recognition module is used for performing named entity recognition on the bug report data set, and extracting a bug report entity sequence, comprising a labeling unit and an extraction sequence unit;
the vectorization module is used for performing vector representation on the bug report entity sequence and the code knowledge graph jointly through Word2Vec and a knowledge graph embedding algorithm; and
the similarity calculation module is used for mapping the vector representation on the bug report entity sequence and the code knowledge graph to the same vector space, calculating cosine similarities between the vector representation of the bug report entity sequence and the vector representation of the code knowledge graph, and ranking the cosine similarities from high to low to generate a list of suspicious bug code,
wherein bug-related files are mined through the list of suspicious bug code so that accuracy of bug localization is improved,
wherein bugs repairing is conducted through the bug-related files so that time and energy costs are reduced.
6 . The system for bug localization based on the code knowledge graph according to claim 5 , wherein in the source code parsing module, the source codes are parsed into the AST by using a Spoon source code parser, a control flow is moved from a source code package to a class contained in the source code package, and then to variables and suspicious bug code declared in the class, each suspicious bug code is analyzed, and parameters, the variables and comments are recorded.
7 . The system for bug localization based on the code knowledge graph according to claim 5 , wherein in the code knowledge graph construction module, the code knowledge graph is composed of package, class, method, parameter, variable and statement as entities, and hasPackage, hasVariable, hasMethod, hasParameter, Extend, hasStatement and Call as edge types, and it is visualized through a Neo4j graph database.
8 . The system for bug localization based on the code knowledge graph according to claim 5 , wherein in the named entity recognition module, a BIO sequence labeling suspicious bug code is used to manually label the bug report data set, and a BiLSTM-CRF is used to perform the named entity recognition, so that bug entity sequences are extracted.
9 . A computer device, comprising a memory, a processor and a computer program stored on the memory and runnable on the processor, wherein the processor implements the steps of the method described in claim 1 when executing the said computer program.
10 . A non-transient computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the steps of the method described in claim 1 .