Onboard complex electronic hardware requirement and code consistency detection method

By constructing a knowledge graph of complex electronic hardware requirements and codes, and using deep learning models and rule methods, the consistency detection of requirements and codes is achieved, which solves the problems of low efficiency and high misjudgment in the existing technology, and improves detection efficiency and accuracy.

CN118656052APending Publication Date: 2024-09-17NORTHWESTERN POLYTECHNICAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410733720.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

The existing technology has low efficiency and high misjudgment in the consistency detection of complex electronic hardware requirements and codes. It mainly relies on manual review and is difficult to accurately identify complex logic errors and the consistency of the hardware description language Verilog code.

Method used

By building a knowledge graph of complex electronic hardware requirements and codes, we use deep learning models and rule-based methods to extract semantic information, achieve consistency detection between requirements and code, and use the similarity of the knowledge graph to calculate the automated detection process.

Benefits of technology

It significantly improves the efficiency and accuracy of the consistency detection of complex electronic hardware requirements and codes, reduces the misjudgment rate, realizes automated detection, and improves the efficiency and accuracy of approval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118656052A
    Figure CN118656052A
Patent Text Reader

Abstract

The invention provides an airborne complex electronic hardware demand and code consistency detection method, which automatically completes demand and code consistency detection by constructing a knowledge graph corresponding to complex electronic hardware demands and codes and based on similarity calculation of the knowledge graph. According to the method, manual detection of airworthiness certification requirements and codes can be converted into an automatic detection process, the airworthiness certification time is greatly shortened, and the certification efficiency is improved. According to the method, semantic information can be accurately extracted from codes and requirements by constructing the accurate ontology model and selecting the efficient entity relationship extraction model, so that accurate detection of consistency is realized, and the misjudgment rate is remarkably reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of code consistency detection, and in particular to a method for detecting consistency between airborne complex electronic hardware requirements and codes. Background Art

[0002] Airworthiness certification is a key link in ensuring the safety and reliability of airborne systems. The airworthiness management department strictly reviews, identifies, supervises and manages the design and manufacture of airborne systems. In airborne hardware systems, complex electronic hardware represented by field programmable gate arrays (FPGAs) plays a vital role. The role of airworthiness certification is to discover and correct errors in the design process in the early stages of hardware design, thereby ensuring its safety and reliability throughout the hardware life cycle.

[0003] The design process of complex electronic hardware mainly includes requirements capture, outline design and coding stages. In this process, consistency detection between requirements and code is a crucial link, which ensures that the software code can accurately implement the established requirements and reduce the risk of deviation from the original requirements. By realizing two-way traceability between requirements and code, each step from requirement definition to code implementation to test verification is closely matched, which helps to timely discover potential problems and defects in the early stages of hardware design, thereby improving the development efficiency of complex electronic hardware.

[0004] The current requirements and code consistency detection mainly relies on methods such as manual review, static code analysis, and formal verification. Although static code analysis tools can quickly find common errors in the code, it is difficult to identify complex logical errors and is limited to specific programming languages. There is currently no static analysis tool for hardware description language Verilog requirements and code consistency detection. Although formal verification tools can provide precise mathematical verification, large or complex design verification requires a lot of time and computing resources, and professional knowledge is required to define verification properties. Therefore, in airborne systems, the consistency detection of complex electronic requirements and codes mainly relies on manual review. Since manual review mainly relies on the reviewer's experience and intuition to identify problems, it is inefficient and prone to misjudgment and artificial introduction of problems due to the reviewer's lack of understanding of the hardware design background. Summary of the invention

[0005] In view of the problems of low efficiency and high misjudgment in the prior art of manually detecting the consistency of complex electronic hardware requirements and codes, the present invention proposes a method for detecting the consistency of airborne complex electronic hardware requirements and codes, which automatically completes the consistency detection of requirements and codes based on the similarity calculation of the knowledge graph by constructing a knowledge graph corresponding to the complex electronic hardware requirements and codes. The present invention can transform the manual detection of airworthiness certification requirements and codes into an automated detection process, greatly shortening the airworthiness certification time and improving the certification efficiency. By constructing a precise ontology model and selecting an efficient entity relationship extraction model, the present invention can accurately extract semantic information from the code and requirements, thereby achieving precise detection of consistency and significantly reducing the misjudgment rate.

[0006] The technical solution of the present invention is:

[0007] A method for detecting consistency between airborne complex electronic hardware requirements and codes comprises the following steps:

[0008] Step 1: Build a demand knowledge graph, including:

[0009] Step 1.1: Preprocess the requirement text and remove the requirement text that is irrelevant to the code logic requirements;

[0010] Step 1.2: Use the five-tuple method of concept, entity, attribute, relationship, and rule to construct the demand knowledge graph ontology;

[0011] Step 1.3: Use a combination of rule-based regular expressions and manual methods to extract some entities and relationships in the requirement text to build a pre-training dataset;

[0012] Step 1.4: Use the dataset to train the deep learning model, and use the trained deep learning model to extract demand entities, relationships, and attributes;

[0013] Step 1.5: Use the neo4j database to store the demand entities, relationships, and entity attributes extracted in step 1.4 as a demand knowledge graph;

[0014] Step 2: Build a code knowledge graph, including:

[0015] Step 2.1: Preprocess the code text, including standardization, removing comments, and word segmentation;

[0016] Step 2.2: Use the five-tuple method of concept, entity, attribute, relationship, and rule to construct the code knowledge graph ontology;

[0017] Step 2.3: Use a rule-based regular expression method to extract code entities and relations in the code text;

[0018] Step 2.4: Use neo4j database to store the code entities and relationships extracted in step 2.3, as well as the code entity attributes as the code knowledge graph;

[0019] Step 3: Align the requirement knowledge graph and the code knowledge graph to eliminate ambiguity in the knowledge graph;

[0020] Step 4: Based on the aligned requirement knowledge graph and code knowledge graph, perform consistency check on requirements and codes, including:

[0021] Step 4.1: Query the requirements to be tested;

[0022] Step 4.2: Use the query result of step 4.1 as input to query the code corresponding to the requirement to be tested;

[0023] Step 4.3: Extract the requirements to be tested and the code knowledge graph features;

[0024] Step 4.4: Calculate the similarity of the features extracted in step 4.3;

[0025] Step 4.5: The similarity between the requirement to be tested and the code is compared with the similarity threshold. If the similarity threshold is reached or exceeded, there is consistency between the requirement text and the code.

[0026] Furthermore, in step 1.1, the requirement text is first preprocessed based on the characteristics that the requirement explanation text has a "

COM

[0027] Furthermore, in step 1.2, the concepts of requirement ontology include specific requirements, signals, modules, levels, functions, behaviors, and signal values;

[0028] The attribute set of the requirement ontology includes: the attribute set of specific requirements = {requirement ID, requirement text}, the attribute set of modules = {module name, module behavior}, the attribute set of signals = {signal name, signal function, signal behavior, register name corresponding to the signal, register bit width corresponding to the signal}, the attribute set of functions = {function name, function characteristics}, the attribute set of levels = {level type, value corresponding to the level}, the attribute set of behaviors = {behavior name}, the attribute set of signal values ​​= {signal value};

[0029] The relationships in the requirement ontology include have, set, reset, realize, maintain, and input.

[0030] Furthermore, in step 1.4, the deep learning model includes: a word embedding layer, a bidirectional LSTM layer, a fully connected layer, and a conditional random field layer; wherein:

[0031] The input data of the word embedding layer is the required text, which is converted into word vectors by using Word2Vec and outputs a word vector sequence;

[0032] The input of the bidirectional LSTM layer is the word vector sequence from the word embedding layer. The bidirectional LSTM processes the input sequence in two directions and outputs the concatenated sequence of the bidirectional hidden states at each time step.

[0033] The input of the fully connected layer is the hidden state sequence output by the bidirectional LSTM layer. Through linear transformation, the output of the bidirectional LSTM layer is mapped to the label space, and the unstandardized label score vector corresponding to each word is output;

[0034] The input of the conditional random field layer is the label score of each word. According to the label score and label transfer constraints, the most likely label assignment of the entire label sequence is calculated, and the optimal label path of the entire sequence is output.

[0035] Furthermore, in step 2.2, the statement entity concepts in the Verilog code are divided into: module module, branch statement, assignment statement, always statement block, declaration, and loop statement;

[0036] The attribute set of module concept = {statement text content, module name, signal name, signal input and output type, signal bit width};

[0037] The attribute set of the branch statement concept = {statement text content, branch condition parameter, trigger statement after branch is established, trigger statement after branch is not established};

[0038] The attribute set of the assignment statement concept = {statement text content, assigned signal, assignment signal};

[0039] The attribute set of the always statement block concept = {statement text content, trigger signal};

[0040] The attribute set of the declaration statement concept = {statement text content, signal type, signal name, signal bit width, signal initial value};

[0041] The attribute set of the loop statement concept = {statement text content, loop condition parameters}.

[0042] Furthermore, in step 3, a rule-based approach is used to align the requirement knowledge graph and the code knowledge graph.

[0043] Furthermore, in step 4.2, the core semantic text of the requirements is used to perform a preliminary screening of the code text, wherein the entities, relationships, and attributes extracted in steps 1, 2, and 3 all belong to the core semantic text of the requirements.

[0044] Furthermore, in step 4.3, word embedding technology is used to convert the requirement text and code text into word dense vector representation, and based on the word dense vector, the vector features of the requirement text and code text are extracted.

[0045] Furthermore, in step 4.4, according to the formula

[0046] k=Ec*WE+Rc*WR+Pc*WP

[0047] Calculate the similarity k, where Ec, Rc, and Pc are the cosine similarities of entity pairs, relationship pairs, and attribute pairs of the requirement text and code text, respectively; WE, WR, and WP are the corresponding weights of entity pairs, relationship pairs, and attribute pairs.

[0048] The present invention also provides a computer-readable storage medium, on which computer program instructions are stored, and the computer program instructions are used to implement the above method when the computer is running.

[0049] Beneficial Effects

[0050] The present invention has the following effects:

[0051] 1. The present invention uses knowledge graph as a storage method for requirements and code data, which can effectively solve the problem of discretization of requirements and code data and discretization of text semantics, and realizes the structured storage of key semantic information in requirements and codes. This technical means enables airborne complex electronic airworthiness certification personnel to obtain key information in requirements and codes without reading the deep semantics of requirements and codes, thereby significantly improving the efficiency and accuracy of certification.

[0052] 2. Since the knowledge graph is constructed by using a joint entity and relationship extraction method based on deep learning and an ontology construction model, the knowledge graph can clearly represent requirements and codes, enhancing the comprehensibility of requirements and codes. A good ontology model design provides a prerequisite for the subsequent calculation of the consistency of requirements and codes, making the consistency detection of requirements and codes more accurate and efficient.

[0053] 3. Since the similarity between requirements and codes is calculated by a similarity calculation method based on knowledge graph features, the present invention can automatically calculate the degree of implementation of the code for the requirement text, efficiently and accurately judge the consistency between the code and the requirements, and significantly improve the accuracy and scalability of consistency detection between requirements and codes.

[0054] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:

[0056] Figure 1 a flow chart of the method implemented for the present application;

[0057] Figure 2 This is a framework diagram of an embodiment of the present application;

[0058] Figure 3 It is a schematic diagram of demand knowledge graph;

[0059] Figure 4 This is a schematic diagram of the code knowledge graph. DETAILED DESCRIPTION

[0060] Embodiments of the present invention are described in detail below. The embodiments are exemplary and intended to be used to explain the present invention, but should not be construed as limiting the present invention.

[0061] During the code review phase of airworthiness certification requirements, reviewers are often unfamiliar with the complex electronic hardware design background, so they need to manually compare requirements and codes one by one, making the review process inefficient and error-prone.

[0062] For example, for a complex electronic hardware requirement text:

[0063] When the input value of CPU1_706_RESET_N is 1'b0, the CPLD makes the output values ​​of reset signals such as CPU1_DDR3_RESET_N, CPU1_FLASH_RESET_N, CPU1_ETH_RESET_N and AFDX_RESET_N to 1'b0; when the input value of CPU1_706_RESET_N changes from 1'b0 to 1'b1, the output values ​​of reset signals such as CPU1_DDR3_RESET_N, CPU1_FLASH_RESET_N, CPU1_ETH_RESET_N and AFDX_RESET_N change from 1'b0 to 1'b1 after a delay of 404±40ms.

[0064] In order to check whether the requirement is met, the reviewer needs to find the specific code segment that implements the requirement text in the code file, and then find the signal CPU1_706_RESET_N in the code segment, and study the code to determine whether the code logic conforms to the requirement description logic. This process involves concurrent judgment of multiple signal states, which is prone to misjudgment due to its high complexity.

[0065] Based on this, this embodiment proposes a method for consistency detection of airborne complex electronic hardware requirements and codes based on knowledge graphs, which solves the problems of low efficiency and high misjudgment of existing manual detection of complex electronic hardware requirements and code consistency. This method realizes automatic detection of consistency between requirements and codes by constructing a knowledge graph corresponding to airborne complex electronic hardware requirements and codes, and automatically calculating the similarity of the knowledge graph. This method avoids manual participation, and thus avoids human-introduced errors in the development of complex electronic hardware; at the same time, compared with traditional manual detection solutions, it saves detection costs and improves the efficiency of requirements and code consistency detection.

[0066] Figure 1 The flowchart of the method for detecting consistency between airborne complex electronic hardware requirements and codes based on the knowledge graph used in this embodiment is shown, which specifically includes the following steps:

[0067] Step 1: Build a demand knowledge graph:

[0068] Step 1.1: Preprocessing of requirement text;

[0069] The requirement text preprocessing should eliminate the requirement text that is not related to the code logic requirements. Since the requirements for airborne complex electronic hardware are designed according to the DO254 standard, there are many texts in the requirement text that are not related to the requirements, such as functional subtitles, Comments (explanations of certain requirements), and hardware requirements that are not related to the code logic, such as "The model of the CPLD should be XXX". These texts are meaningless for code consistency detection, so these texts need to be eliminated when constructing the knowledge graph. Since the airworthiness requirements writing guide stipulates that for the text of the requirement explanation, it is necessary to add the "[COM]" mark in front of the text, and the text length of the functional subtitle of the requirement text generally does not exceed five characters. Therefore, based on the above features, the present invention uses python and its corresponding pandas library to process the original requirement text file. For the file named "original requirement text.csv", the text after the elimination operation is "preprocessed requirement text.csv", and the specific operations of the preprocessing are as follows:

[0070] import pandas as pd

[0071] df = pd.read_csv('original requirement text.csv', encoding = 'utf-8')

[0072] df = df [~ ((df ['Requirement text content']. str. starts with ('【COM')) | (df ['Requirement text content']. str. len () < = 5))]

[0073] df.to_csv('Preprocessed requirement text.csv',index=False,encoding='utf-8')

[0074] The above process cannot remove function subtitles with more than 5 characters and hardware requirement texts that are not related to the code logic, so they need to be further removed manually. After manual processing, this step obtains data entries related to the code logic, including the requirement ID and the requirement text content. These entries are saved in a file named "Requirement Logic Text.csv".

[0075] Step 1.2: Build the demand knowledge graph ontology;

[0076] The present invention constructs the ontology of the demand knowledge graph in the form of five-tuples: concept, entity, attribute, relationship, and rule. Of course, for specific instances, five-tuple modeling does not necessarily require the presence of all five elements. If a certain element has no meaning for the specific problem to be solved by the knowledge graph, or the knowledge graph in a certain field does not have all five elements, it can be defaulted according to the specific situation. This kind of ideological modeling can refine the granularity of entities and relationships, that is, concepts are only upper-level models of entities. The larger the modeling granularity of concepts, the larger the granularity of entities. The essence of five-tuple modeling is also for the subsequent extraction of <entity, relationship, entity> triples.

[0077] The concepts of the requirement ontology defined in this embodiment include specific requirements, signals, modules, levels, functions, behaviors, and signal values.

[0078] The attribute set of the requirement entity includes: the attribute set of specific requirements = {requirement ID, requirement text}, the attribute set of the module = {module name, module behavior}, the attribute set of the signal = {signal name, signal function, signal behavior, register name corresponding to the signal, register bit width corresponding to the signal}, the attribute set of the function = {function name, function characteristics}, the attribute set of the level = {level type, value corresponding to the level}, the attribute set of the behavior = {behavior name}, and the attribute set of the signal value = {signal value}.

[0079] The relationship of the requirement ontology includes having, setting, resetting, realizing, maintaining, and inputting. Since the airworthiness requirement writing guide stipulates that the module name should be used as the subject for a specific requirement. Therefore, the conventional description method of complex electronic hardware requirements is: "[module name] should make / put [signal name] [specific operation]". In this embodiment, the relationship in the concept entity is as follows: having = {(module, signal), (module, function), (module, behavior)}, setting = {(module, signal), (signal, level)}, resetting = {(signal, level)}, realizing = {(signal, function)}, maintaining = {(signal, level)}, input = {(signal, level)}. Each specific requirement and the signal, module, level, function, and behavior entities extracted from the text have a containing and being contained relationship, namely: containing = {(specific requirement), (signal, module, level, function, behavior)}. The expression here is "XX relationship = {(entity A, entity B)}", where the parentheses represent the entity pairs with the relationship, and the curly braces represent the entity pair list with the relationship.

[0080] The rules in requirement ontology modeling are equivalent to "signal assignment" for the description of "signal transmission" in the requirement text.

[0081] In this embodiment, for the requirement text: "CPLD01: When the condition CPU_LocalbusLALE control signal CPU1_LAL input value is 1'b1, the CPLD should pass CPU1_LAD[4:15] to CPU1_A[4:15]; otherwise, the value of CPU1_A[4:15] is 12'b0."

[0082] The specific details of the knowledge graph constructed according to the modeling method of the demand ontology are as follows:

[0083] Specific requirement entity extraction: "CPLD01: When the condition CPU_LocalbusLALE control signal CPU1_LAL input value is 1'b1, CPLD should pass CPU1_LAD[4:15] to CPU1_A[4:15]; otherwise, the value of CPU1_A[4:15] is 12'b0."

[0084] Signal entity extraction: CPU_LocalbusLALE, CPU1_LAL, CPU1_LAD, CPU1_A;

[0085] Module entity extraction: CPLD;

[0086] Signal value entity extraction: 1'b1, 12'b0;

[0087] Level entity extraction: high level;

[0088] Relation extraction: having,transfer,input.

[0089] Step 1.3: Use a combination of rule-based regular expressions and manual methods to extract some entities and relationships in the requirement text to build a pre-training dataset;

[0090] First, we use a rule-based approach to identify entities and entity attributes with rules in the requirement text, then manually extract entities, relationships, and attributes without rules, and finally use these extracted data as a dataset to pre-train the deep learning model. The pre-trained model aims to learn how to identify entities and improve its recognition accuracy.

[0091] The conceptual entities with rules include signal, level, signal value, and signal bit width.

[0092] Assume that the demand text is demand_text:

[0093] Signal extraction based on regular expressions:

[0094]

[0095] Step 1.4: Train the pre-trained deep learning model and use the trained deep learning model to extract demand entities, relationships, and attributes.

[0096] In this embodiment, the pre-trained data extracted in step 1.3 is labeled by constructing an ontology model. For example, the module name "CPLD" is labeled as the "module" entity, and the label "should be set" is set as the "setting" relationship entity. After the original data is labeled, it is input into the deep learning model based on BiLSTM+CRM, and the model parameters are optimized by the cross entropy loss function and the adam gradient descent method. The model is iteratively trained until the performance of the model in the training set is no longer improved, and the model training is completed. Since the training process is a basic deep learning model training process, it will not be described in detail in the embodiment. This step mainly describes how to complete the extraction of entities, relationships and attributes based on the model.

[0097] Since the essence of entity and entity attribute extraction is the corresponding entity extraction under the relationship between the entity and its attribute, such as: the signal and its attribute signal name are an entity pair under the "has" relationship, that is, the signal has the signal name, this method also uses a joint relationship model based on deep learning to extract entity attributes for the signal name attribute extraction. This method combines entity extraction and relationship extraction, and the model includes the following layers:

[0098] 1. Embedding Layer

[0099] Input data: a requirement text. For example, the sentence ["CPLD","should","set","CPU1_SRESET","output value","constant","1'b1"]

[0100] This layer uses Word2Vec to convert to word vectors. Each row in the embedding matrix corresponds to the vector representation of a word.

[0101] Output data: word vector sequence, each word is converted into a dense vector. In this embodiment, the embedding dimension of the model is set to 300, and after the word embedding layer, a matrix with a shape of [number of words in the sentence, 300] is output.

[0102] 2. Bi-LSTM Layer

[0103] Input data: Sequence of word vectors from the word embedding layer.

[0104] Bidirectional LSTM processes the input sequence in two directions: one LSTM processes it forward (from left to right) and the other LSTM processes it backward (from right to left). The LSTM in each direction tries to capture the temporal dependencies in the sequence, integrating information from the previous and next contexts.

[0105] Output data: a concatenated sequence of bidirectional hidden states at each time step. Set the hidden dimension of each direction to 128, output a 256-dimensional vector for each time step, and the output of the entire sequence will be a matrix with a shape of [number of words in the sentence, 256].

[0106] 3. Fully Connected Layer

[0107] Input data: Hidden state sequence output by the bidirectional LSTM layer.

[0108] This layer includes a linear transformation for mapping the output of the bidirectional LSTM layer to the label space. For the ontology constructed in this embodiment, there are 7 possible entity tags including "specific requirements", "signal", "module", etc., and 7 relationship tags including "have", "include", and "set". This layer converts each 256-dimensional input vector into a 14-dimensional output vector.

[0109] Output data: The unnormalized label score vector corresponding to each word, with a shape of [sentence length, number of labels].

[0110] 4. Conditional Random Field Layer (CRF Layer)

[0111] Input data: The output of the fully connected layer, that is, the label score of each word.

[0112] The CRF layer uses these scores and the label transfer constraints to calculate the most likely label assignment for the entire label sequence. Dynamic programming is used to take into account the dependencies between labels to optimize the label assignment for the entire sequence.

[0113] Output data: The optimal label path of the entire sequence. This is an integer sequence, each number represents the predicted label of a word. For the "signal" entity corresponding to label 0 during model training, if the predicted score of label 0 of a word in the sentence is the highest, it means that the optimal label of the word is "signal", and the word is extracted as "signal". The above processing at each level can be implemented by the following python code:

[0114]

[0115]

[0116]

[0117] Step 1.5: Use the neo4j database to store the required knowledge graph.

[0118] Neo4j is a widely used graph database. Because it has a special query language, Cypher is used for query operations. Cypher language is highly interactive, syntax-friendly, and query-efficient, which facilitates subsequent queries on requirements and code entities. Based on these advantages, this embodiment uses the neo4j database to store the requirement knowledge graph.

[0119] Import the data obtained in step 1.4 into the neo4j database in batches using cypher statements in the form of "Requirement Entity Attributes.csv" and "Requirement Entity Relationships.csv" files.

[0120] Step 2: Build a code knowledge graph:

[0121] Step 2.1: Code text preprocessing:

[0122] Preprocess the code, including standardization, comment removal, word segmentation and other steps.

[0123] The standardization of codes is to process different representations of codes with the same semantics into the same representation according to the rules in knowledge graph modeling. For details, see the ontology construction rules in step 2.2.

[0124] Step 2.2: Build the code knowledge graph ontology:

[0125] The present invention adopts the framework of five tuples of concepts, attributes, relationships, entities and rules to construct the code knowledge graph ontology.

[0126] The statement entity concepts in the Verilog code are divided into: module, branch statement, assignment statement, always statement block, declaration, loop statement. The attribute set of the module concept = {statement text content, module name, signal name, signal input and output type, signal bit width}; the attribute set of the branch statement concept = {statement text content, branch condition parameter, trigger statement after branch is established, trigger statement after branch is not established}; the attribute set of the assignment statement concept = {statement text content, assigned signal, assignment signal}; the attribute set of the always statement block concept = {statement text content, trigger signal}; the attribute set of the declaration statement concept = {statement text content, signal type, signal name, signal bit width, signal initial value}; the attribute set of the loop statement concept = {statement text content, loop condition parameter}; especially note that the signal input and output types in the module module refer to output type signals and input type signals, and the signal type in the declaration statement refers to the specific type of signal, including wire and reg, which refer to different contents.

[0127] The relationships among code texts are: assignment = {signal, signal}, has = {module, signal}, equal = {(signal, signal value), (signal, signal)}, unequal = {(signal, signal value), (signal, signal)}.

[0128] The rules of the code body are: when the signal value bit width is 1, it is stipulated that when its value is "1", the signal is equivalent to a high level, and when the value is "0", it is equivalent to a low level. The keyword "postedge" in the Verilog code is equivalent to "the signal changes from a low level to a high level", that is, the code: "postedge A" is equivalent to "A=1'b0; A=1'b1;", and "negedge" is equivalent to "the signal changes from a high level to a low level", that is, the code: "negedge A" is equivalent to "A=1'b1; A=1'b0;". Since the semantics of "postedge" and "negedge" are quite different from the corresponding descriptions in the requirement text, this embodiment uniformly replaces "postedge" and "negeedge" with their corresponding code representations during the code standardization stage. The static semantics of "<=" in the Verilog code is equivalent to "=". The code entity is a specific instance extracted from the code data based on the code concept. These rules are used for the standardized representation of the code.

[0129] Step 2.3: Use a rule-based regular expression method to extract code entities and relations in the code text.

[0130] Since the description of code text is relatively fixed and has certain rules, the ontology constructed based on step 2.2 in this embodiment uses a rule-based approach to extract entities and relationships between entities in the code text.

[0131] For the module module, this embodiment uses the following regular expression to match the module name, signal name, signal type (input and output), signal bit width and other information.

[0132] module_pattern=r"module\s+(\w+)\s*\((.*?)\);"

[0133] For branch statements, this embodiment uses the following regular expressions to match branch condition parameters and trigger statements after the branch is established and trigger statements after the branch is not established.

[0134] if_pattern=r"if\s*\((.*?)\)\s*begin(.*?)end"

[0135] For the assignment statement, this embodiment matches the assigned signal and the assignment signal through the following regular expression.

[0136] assign_pattern=r"assign\s+(\w+)\s*=\s*(.*?);"

[0137] For the always statement block, this embodiment matches the trigger signal through the following regular expression.

[0138] always_pattern=r"always\s*@\((.*?)\)\s*begin(.*?)end"

[0139] For declaration statements, this embodiment matches the signal declaration type, declared signal name, signal bit width, and signal initial value through the following regular expression.

[0140] signal_declaration_pattern=r"(\w+)\s+(\w+)\s*=\s*(.*?);"

[0141] For loop statements, this embodiment matches loop condition parameters through regular expressions.

[0142] for_pattern=r"for\s*\((.*?)\)\s*begin(.*?)end"

[0143] The entities and entity attributes are output in the form of entity triples, and code <entity, relationship, attribute> triples and code entity relationship <entity, relationship, entity> triples are obtained. The above triple data are stored in the "code entity attribute.csv" and "code entity relationship.csv" files respectively.

[0144] For the requirement text in step 1.2, the corresponding code is:

[0145]

[0146] For this code, the specific details of the knowledge graph construction method in steps 2.1 to 2.3 are as follows:

[0147] Entity and its corresponding attribute extraction:

[0148] module module, branch statement, assignment statement, always statement block, declaration, loop statement.

[0149] Always statement = (CPU_LocalbusLALE = 1'b0; CPU_LocalbusLALE = 1'b1;)

[0150] If statement = (CPU1_LAL == 1'b1, CPU1_LAL! = 1'b1)

[0151] Assignment statement 1 = (CPU1_A[4:15], CPU1_LAD[4:15])

[0152] Assignment statement 2 = (CPU1_A[4:15], 12'b0)

[0153] Relation extraction:

[0154] Assignment = (CPU1_A[4:15], CPU1_LAD[4:15])

[0155] Assignment = (CPU1_A[4:15], 12'b0)

[0156] equal = (CPU1_LAL, 1'b1)

[0157] Not equal = (CPU1_A[4:15], 12'b0)

[0158] Step 2.4: Use neo4j database to store the code knowledge graph.

[0159] Neo4j is a widely used graph database. Because it has a special query language, Cypher is used for query operations. The Cypher language is highly interactive, grammatically friendly, and highly efficient, which facilitates subsequent queries on requirements and code entities. Based on these advantages, this embodiment uses the neo4j database to store the code knowledge graph.

[0160] After the above steps, the data obtained in step 2.3 is imported into the neo4j database in batches through cypher statements. Assume that the storage paths of the "code entity attributes.csv" and "code entity relationships.csv" files are "file: / / / path / to / code_entities_attributes.csv" and "code entity relationships.csv" files are "file: / / / path / to / code_entities_attributes.csv" and "code_entities_relationships.csv" files respectively.

[0161] file: / / / path / to / code_entities_relationships.csv, use the following cypher statement to complete the data import.

[0162] LOAD CSV WITH HEADERS FROM"file: / / / path / to / code_entities_attributes.csv"AS line

[0163] CREATE(:Entity{id:line.entity_id,property1:line.property1,property2:line.property2})

[0164] LOAD CSV WITH HEADERS FROM"file: / / / path / to / code_entities_relationships.csv"AS line

[0165] MATCH(e1:Entity{id:line.entity1_id}),(e2:Entity{id:line.entity2_id})

[0166] CREATE(e1)-[:Relationship{type:line.relationship_type,property1:line.property1,property2:line.property2}]->(e2)

[0167] Step 3: Align the requirements knowledge graph and the code knowledge graph

[0168] Knowledge graph alignment aims to eliminate ambiguity in knowledge graphs. Since the entities, relationships, and attributes of requirements are different from those of codes, there are differences between the construction of requirements ontology and the construction of code ontology, that is, in the knowledge graph, the same semantic content may present different textual expressions. The task of knowledge alignment is to match the entities in the requirements knowledge graph with the corresponding entities in the code knowledge graph to ensure their consistency, thereby facilitating the subsequent consistency detection of requirements and codes.

[0169] The graph alignment in this embodiment mainly focuses on entity alignment, which is mainly completed in a rule-based manner. For the "set" and "set" in the requirement text, after disambiguation processing, they are set to unified semantics, and the description of the setting relationship in the requirement mainly corresponds to the "assign" assignment operation in the code. The "if" and "when" in the requirement text correspond to the "if" branch statement in the code text. The "otherwise" in the requirement text corresponds to the "else" branch statement in the code text. The high level, low level, and high impedance state described in the requirement text are equivalent to the level values ​​1'b1, 1'b0, and 1'bz, respectively. The requirement text "transfer" is equivalent to the "assignment" relationship in the code. When a signal in the requirement text inputs or outputs a value, it means that the value is passed to the signal, then the "input" and "output" relationships in the requirement text can be converted into "transfer" relationships to facilitate consistency with the code. For example: the requirement "the output value of the A signal is 1'b0" and the requirement "transfer the value of 1'b0 to the output signal" are both represented by the code as "output A=1'b0".

[0170] Step 4: Check the consistency between requirements and code.

[0171] After completing steps 1 to 3, you can obtain the core semantic triple files representing the requirement text and code text after knowledge alignment: requirement entity relationship triple.csv, requirement entity attribute triple.csv, code entity relationship triple.csv, code entity attribute triple.csv.

[0172] In this embodiment, the triple file is stored in the neo4j database to obtain the knowledge graph of the requirements and the knowledge graph of the code. Next, the consistency check of the requirements and the code is implemented based on the triple file:

[0173] Step 4.1: Query the requirements to be tested:

[0174] First, the requirement text to be queried is indexed by the requirement ID attribute. Assuming that the requirement ID to be detected is CPLD_01, the key information of the requirement corresponding to the ID is queried through the built-in cypher language of neo4j.

[0175] MATCH(n:Requirement{id:'CPLD_01'})-[:HAS_ENTITY]->(e:Entity),

[0176] (n)-[:HAS_RELATIONSHIP]->(r:Relationship),

[0177] (n)-[:HAS_ATTRIBUTE]->(a:Attribute)

[0178] RETURN n.text as RequirementText,e,r,a;

[0179] Step 4.2: Query the code corresponding to the requirements to be tested:

[0180] The query result of step 4.1 is used as the query input of step 4.2. The present invention uses the core semantic text of the requirement to perform preliminary screening of the code text, so as to avoid comparing the requirement text with all the code texts one by one. The entities, relationships, and attributes extracted through steps 1, 2, and 3 all belong to the core semantic text of the requirement. Assume that the core semantics of the requirement CPLD_01 queried in step 4.1 are: CPLD, Cop_Trst_N, Wd_Rst_N, Cpu_Trst_N; then use the above corresponding core entities as query input to query the code text entities related to the requirement entity. For example, the cypher statement for querying the entity corresponding to the code text corresponding to the signal name Cop_Trst_N in the requirement text is as follows:

[0181] MATCH(req:Requirement{name:'Cop_Trst_N'})-[:RELATED_TO]->(codeEntity)

[0182] RETURN codeEntity,labels(codeEntity),keys(codeEntity),codeEntity.properties;

[0183] Step 4-3: Extraction of features of the requirements and code knowledge graph to be tested:

[0184] The present invention adopts word embedding technology to complete the word dense vector representation of the requirement text and the code text, thereby extracting the vector features of the requirement text and the code text.

[0185] First, we use web crawler technology to obtain text data related to hardware electronics to build a complex electronic hardware corpus; then we use Skip-Gram, which is suitable for small prediction libraries, to predict contexts through central words. In this embodiment, we use the Gensim library in python to train the Word2Vec model.

[0186] Use the trained model to build dense vector representations of words for the core semantic entity words queried in steps 4.1 and 4.2. Assuming the trained Word2Vec model is model, for the entity queried in step 4.3, use the following dense vector representation of the completed word:

[0187] model=Word2Vec.load('word2vec.model')

[0188] vector_cpld=model.wv['CPLD']

[0189] vector_cop_trst_n=model.wv['Cop_Trst_N']

[0190] vector_wd_rst_n=model.wv['Wd_Rst_N']

[0191] vector_cpu_trst_n=model.wv['Cpu_Trst_N']

[0192] Step 4.4: Similarity calculation:

[0193] Calculate the cosine similarity of entities and relations after completing the dense vector representation of the word.

[0194] The calculation formula for text cosine similarity is as follows:

[0195] Cosine Similarity(A,B)=A*B / ||A||*||B||

[0196] A*B is the dot product of word vector A and word vector B, and ||A|| and ||B|| are the Euclidean norms of these two vectors.

[0197] First, select the entity pairs, attribute pairs, and relationship pairs of the requirement text and code text to be compared, and calculate the cosine similarity of the vector representations of the entity pairs, attribute pairs, and relationship pairs. In this embodiment, the cosine similarity is calculated using the NumPy library in Python. For example: for the requirement text in step one: "When the input value of CPU1_LAL is 1'b1, the CPLD should transfer CPU1_LAD[4:15] to CPU1_A[4:15]", the extracted entity relationship triples are: <CPU1_LAD, transfer, CPU1_A>; <CPU1_LAL, input, 1'b1>; The entity attribute triples are <CPU1_LAD, signal bit width, [4:15]>, <CPU1_A, signal bit width, [4:15]>;

[0198] Its corresponding code is "output CPU_LAL; if(CPU1_LAL == 1'b1) CPU1_A[4:15] = CPU1_LAD[4:15];", and the entity relationship triples extracted according to the example of the present invention are: <CPU1_LAL, equal, 1'b1>, <CPU1_LAD, assignment, CPU1_A>, and the entity attribute triples are <CPU1_LAD, signal bit width, [4:15]>, <CPU1_A, signal bit width, [4:15]>.

[0199] Manually complete the disambiguation of the triples in the requirement knowledge graph and the code knowledge graph according to the rules in step 3. For example, replace "assignment" with "transfer".

[0200] In this embodiment, the above requirement entity relationship triple <CPU1_LAL, input, 1'b1> and the code entity relationship triple <CPU1_LAL, equal, 1'b1> are taken to form: the entity pair <requirement signal text CPU1_LAL, code signal text CPU1_LAL>, the relationship pair <input, equal>, and the attribute pair <the signal type of CPU1_LAL is output signal, the signal type of CPU1_LAL is output>.

[0201] Calculate the vectors of the above text through the Word2vec model trained in step 4.3. Suppose the vector representation of the requirement text in an entity pair is vec1, and the vector representation of the code text is vec2. The similarity calculation of this pair of entity pairs is:

[0202] import numpy as np

[0203] # Calculate the cosine distance

[0204] cosine_distance = np.linalg.norm(vec1 - vec2)

[0205] # Calculate the Euclidean norm of the vector

[0206] norm_1 = np.linalg.norm(vec1)

[0207] norm_2 = np.linalg.norm(vec1)

[0208] # Calculate cosine similarity

[0209] cosine_similarity=1-cosine_distance / np.sqrt(np.square(norm_2)+np.square(norm_2))

[0210] Assume that the cosine similarities of entity pairs, relationship pairs, and attribute pairs of the requirement text and the code text are Ec, Rc, and Pc respectively. The weights of the similarities of entity pairs, relationship pairs, and attribute pairs in the consistency of the requirement text and the code text are WE, WR, and WP respectively;

[0211] The calculation formula for the requirement text similarity k is:

[0212] k=Ec*WE+Rc*WR+Pc*WP.

[0213] Step 4.5: Compare the similarity between the requirements to be tested and the code with the similarity threshold

[0214] For a requirement, entity pairs, relationship pairs, and attribute pairs have different weights on the similarity between the requirement and the text. The present invention uses a large number of experiments using airborne complex electronic hardware requirements and code data to prove that when the weights of entity pairs, relationship pairs, and attribute pairs are 0.3, 0.4, and 0.3 respectively, and the similarity threshold is 0.8, the similarity accuracy between the requirement and the code reaches up to 92%;

[0215] Assume that the requirement text to be detected is: CPLD should set the output value of the reset signal CPU1_SRESET to be always 1'b1.

[0216] The requirements are preprocessed and entity relationship extracted to obtain key entities: CPLD, CPU1_SRESET, 1'b1; key relationships: setting = {CPLD, CPU1_SRESET}, output = {CPU1_SRESET, 1'b1}; attributes: CPLD = {module name: CPLD, contains signal: CPU1_SRESET}, CPU1_SRESET = {signal name: CPU1_SRESET, signal type: output signal}.

[0217] In this example, by querying the entity of the requirement, we successfully retrieved the corresponding code entity and obtained the following detailed list of entities, relationships, and attributes.

[0218] Entities: CPLD, CPU1_SRESET, 1'b1, output; Relationship: assignment = {CPLD, CPU1_SRESET}, assignment = {CPU1_SRESET, 1'b1}; Attributes: CPU1_SRESET = {signal name: CPU1_SRESET, signal type: output}, CPLD = {module name: CPLD, contains signal: CPU1_SRESET}.

[0219] In this example, we calculate the cosine similarity between entity pairs, relationship pairs, and attribute pairs in the requirements and the code, and compare the calculation results with the established similarity score threshold. If the similarity value exceeds 0.8, it indicates that there is consistency between the requirement text and the code; if the similarity value is lower than 0.8, it indicates that there may be a conflict between the code and the requirements.

[0220] The above embodiment provides a method for detecting consistency between airborne complex electronic hardware requirements and codes, which can be implemented by computer program instructions, which can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific manner to implement the method. These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operating steps are executed on the computer or other programmable device to implement the method.

[0221] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations on the present invention. A person skilled in the art may change, modify, replace and modify the above embodiments within the scope of the present invention without departing from the principles and intent of the present invention.

Claims

1. A method for checking the consistency of airborne complex electronic hardware requirements and codes, Features: The following steps are involved: Step 1: Build a demand knowledge graph, including: Step 1.1: Preprocess the requirement text and remove the requirement text that is irrelevant to the code logic requirements; Step 1.2: Use the five-tuple method of concept, entity, attribute, relationship, and rule to construct the demand knowledge graph ontology; Step 1.3: Use a combination of rule-based regular expressions and manual methods to extract some entities and relationships in the requirement text to build a pre-training dataset; Step 1.4: Use the dataset to train the deep learning model, and use the trained deep learning model to extract demand entities, relationships, and attributes; Step 1.5: Use the neo4j database to store the demand entities, relationships, and entity attributes extracted in step 1.4 to build a demand knowledge graph; Step 2: Build a code knowledge graph, including: Step 2.1: Preprocess the code text, including standardization, removing comments, and word segmentation; Step 2.2: Use the five-tuple method of concept, entity, attribute, relationship, and rule to construct the code knowledge graph ontology; Step 2.3: Use a rule-based regular expression method to extract code entities and relations in the code text; Step 2.4: Use the neo4j database to store the code entities and relationships extracted in step 2.3, as well as the code entity attributes, to build a code knowledge graph; Step 3: Align the requirement knowledge graph and the code knowledge graph to eliminate ambiguity in the knowledge graph; Step 4: Based on the aligned requirement knowledge graph and code knowledge graph, perform consistency check on requirements and codes, including: Step 4.1: Query the requirements to be tested; Step 4.2: Use the query result of step 4.1 as input to query the code corresponding to the requirement to be tested; Step 4.3: Extract the requirements to be tested and the code knowledge graph features; Step 4.4: Calculate the similarity of the features extracted in step 4.3; Step 4.5: The similarity between the requirement to be tested and the code is compared with the similarity threshold. If the similarity threshold is reached or exceeded, there is consistency between the requirement text and the code.

2. According to claim 1, a method for detecting consistency between airborne complex electronic hardware requirements and codes, Features: In step 1.1, the requirement text is first preprocessed based on the characteristics that the requirement explanation text has a "[COM]" mark before it and the function subtitle text of the requirement text is no longer than five characters. Then, the function subtitles with more than 5 characters and the hardware requirement text that is not related to the code logic are manually removed.

3. According to the method for detecting consistency between airborne complex electronic hardware requirements and codes as described in claim 1, Features: In step 1.2, the concepts of requirement ontology include specific requirements, signals, modules, levels, functions, behaviors, and signal values; The attribute set of the requirement ontology includes: the attribute set of specific requirements = {requirement ID, requirement text}, the attribute set of modules = {module name, module behavior}, the attribute set of signals = {signal name, signal function, signal behavior, register name corresponding to the signal, register bit width corresponding to the signal}, the attribute set of functions = {function name, function characteristics}, the attribute set of levels = {level type, value corresponding to the level}, the attribute set of behaviors = {behavior name}, the attribute set of signal values ​​= {signal value}; The relationships in the requirement ontology include have, set, reset, realize, maintain, and input.

4. According to claim 1, a method for detecting consistency between airborne complex electronic hardware requirements and codes, Features: In step 1.4, the deep learning model includes: word embedding layer, bidirectional LSTM layer, fully connected layer and conditional random field layer; among them: The input data of the word embedding layer is the required text, which is converted into word vectors by using Word2Vec and outputs a word vector sequence; The input of the bidirectional LSTM layer is the word vector sequence from the word embedding layer. The bidirectional LSTM processes the input sequence in two directions and outputs the concatenated sequence of the bidirectional hidden states at each time step. The input of the fully connected layer is the hidden state sequence output by the bidirectional LSTM layer. Through linear transformation, the output of the bidirectional LSTM layer is mapped to the label space, and the unstandardized label score vector corresponding to each word is output; The input of the conditional random field layer is the label score of each word. According to the label score and label transfer constraints, the most likely label assignment of the entire label sequence is calculated, and the optimal label path of the entire sequence is output.

5. According to claim 1, a method for detecting consistency between airborne complex electronic hardware requirements and codes, Features: In step 2.2, the statement entity concepts in the Verilog code are divided into: module module, branch statement, assignment statement, always statement block, declaration, and loop statement; The attribute set of module concept = {statement text content, module name, signal name, signal input and output type, signal bit width}; The attribute set of the branch statement concept = {statement text content, branch condition parameter, trigger statement after branch is established, trigger statement after branch is not established}; The attribute set of the assignment statement concept = {statement text content, assigned signal, assignment signal}; The attribute set of the always statement block concept = {statement text content, trigger signal}; The attribute set of the declaration statement concept = {statement text content, signal type, signal name, signal bit width, signal initial value}; The attribute set of the loop statement concept = {statement text content, loop condition parameters}.

6. According to claim 1, a method for detecting consistency between airborne complex electronic hardware requirements and codes, Features: In step 3, a rule-based approach is used to align the requirement knowledge graph and the code knowledge graph.

7. According to claim 1, a method for detecting consistency between airborne complex electronic hardware requirements and codes, Features: In step 4.2, the core semantic text of the requirements is used to perform a preliminary screening of the code text, where the entities, relationships, and attributes extracted in steps 1, 2, and 3 all belong to the core semantic text of the requirements.

8. According to claim 1, a method for detecting consistency between airborne complex electronic hardware requirements and codes, Features: In step 4.3, word embedding technology is used to convert the requirement text and code text into word dense vector representation, and based on the word dense vector, the vector features of the requirement text and code text are extracted.

9. A method for detecting consistency between airborne complex electronic hardware requirements and codes according to claim 8, Features: In step 4.4, according to the formula k=Ec*WE+Rc*WR+Pc*WP Calculate the similarity k, where Ec, Rc, and Pc are the cosine similarities of entity pairs, relationship pairs, and attribute pairs of the requirement text and code text, respectively; WE, WR, and WP are the corresponding weights of entity pairs, relationship pairs, and attribute pairs.

10. A computer-readable storage medium having computer program instructions stored thereon, Features: The computer program instructions are used to implement any one of the methods of claims 1 to 9 when executed by a computer.