WO2023138270A1 - Form specification recommendation method, apparatus and system - Google Patents

Form specification recommendation method, apparatus and system Download PDF

Info

Publication number
WO2023138270A1
WO2023138270A1 PCT/CN2022/139299 CN2022139299W WO2023138270A1 WO 2023138270 A1 WO2023138270 A1 WO 2023138270A1 CN 2022139299 W CN2022139299 W CN 2022139299W WO 2023138270 A1 WO2023138270 A1 WO 2023138270A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
user
formal
candidate
specifications
Prior art date
Application number
PCT/CN2022/139299
Other languages
French (fr)
Chinese (zh)
Inventor
杨宸骅
梁广泰
吴添勇
Original Assignee
华为云计算技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为云计算技术有限公司 filed Critical 华为云计算技术有限公司
Publication of WO2023138270A1 publication Critical patent/WO2023138270A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/10Requirements analysis; Specification techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/335Filtering based on additional data, e.g. user or group profiles
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/436Semantic checking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • G06N3/0455Auto-encoder networks; Encoder-decoder networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/0464Convolutional networks [CNN, ConvNet]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/048Activation functions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • the present application relates to the field of computer technology, and in particular to a form specification recommendation method, device and system.
  • Formal methods are techniques for formally specifying, developing, and verifying computer systems (software/hardware systems) based on strict mathematical foundations. Designing and developing a reliable computer system usually requires a lot of formal specification support. Among them, the formal specification is the computer system model strictly described by the formal specification language, the properties that the computer system needs to satisfy, or the loopholes to be detected in the computer system, etc. The formal specification is the basis of the formal method and occupies an important position in the formal method.
  • the present application provides a formal specification recommendation method, device and system, which are used to simplify the writing work of the formal specification, improve the efficiency of obtaining the formal specification and the development efficiency of the computer system.
  • a method for recommending formal specifications comprising: firstly, acquiring user-input codes and/or code annotations, and then obtaining multiple candidate formal specifications based on the user-input codes and/or code annotations, and displaying the multiple candidate formal specifications to the user.
  • the user-input code and/or code comments can be obtained in real time, and then based on the user-input code and/or code comments, multiple candidate formal specifications can be automatically obtained, and the multiple candidate formal specifications can provide users with good references. Save energy and time of users, and improve the acquisition efficiency of formal specifications.
  • the code and/or code-based comments can be specifically implemented to generate candidate formal specifications in the following manner: the code and/or code comments are input into the formal specification generation model for identification, and the formal specification output by the formal specification generation model is used as the candidate formal specification.
  • the formal specification generation model can be a model with high recognition accuracy obtained by training a sample set including a large number of known codes and/or annotations of a large number of known codes.
  • the sample set includes a large number of known codes and/or annotations of a large number of known codes. It can be manually written by users or obtained from the Internet, and is not specifically limited here.
  • the formal specification generation model can obtain multiple formal specifications and the confidence levels of the multiple formal specifications, and the formal specification generation model can directly output the formal specifications whose confidence is greater than the confidence threshold among the multiple formal specifications as candidate formal specifications, or sort them according to the degree of confidence, and output part of the formal specifications with higher confidence as candidate formal specifications, which is not specifically limited here.
  • Both the confidence threshold and the number of output candidate form reductions can be customized by the user according to the actual situation, and are not specifically limited here.
  • multiple candidate formal specifications can be obtained by implementing code and/or code-based comments in the following manner: first, calculate the matching degree between the code and/or code comments and multiple rules included in the rule base, and then, according to the calculation result, use the formal specification corresponding to the rule whose matching degree is greater than the matching degree threshold among the multiple rules as a candidate formal specification.
  • multiple rules included in the rule base correspond to multiple formal specifications, specifically, the corresponding relationship may be one-to-one.
  • the matching degree threshold can be customized by the user according to the actual situation, for example, 80% or 75%, etc., which is not specifically limited here.
  • the multiple rules may also be sorted according to the calculation result, and then the form specification corresponding to the part of the multiple rules with a higher matching degree is used as a candidate form specification.
  • the number of selected candidate form specifications can be customized according to the actual situation, for example, 5 or 10 can be customized, which is not specifically limited here.
  • multiple rules in the rule base and the formal specifications corresponding to the multiple rules can be obtained in advance according to various application scenarios for specialized rule designers.
  • multiple candidate form specifications can be obtained by implementing code-based and/or code-based comments in the following manner: multiple candidate form specifications are obtained based on the intermediate representation corresponding to the code and/or structured comments of the code, wherein the above-mentioned structured comments of the code are obtained by structurally processing the comments of the code.
  • the structured comment of the code is easier to process than the comment of the code (referring to the comment before the structured processing), and the obtained processing result is usually more accurate. Therefore, implementing the above implementation method, based on the intermediate representation corresponding to the code and/or the structured comment of the code, multiple candidate form specifications can be obtained, which can improve the accuracy of the obtained candidate form specifications, and can make the multiple candidate form specifications finally recommended to users more accurate.
  • the acquisition of the code input by the user and/or the comment of the code may be specifically achieved in the following manner: the acquisition of the code input by the user and/or the comment of the code is triggered by a keyword.
  • the acquisition of the code and/or comment of the code input by the user can be triggered by keywords in the following manner: monitor whether the user has input a keyword, and obtain the code and/or comment of the code input by the user when it is detected that the user has input the keyword.
  • Implementing the above-mentioned implementation mode can only monitor the code and/or code annotations entered by the user after the keyword is entered, and then recommend candidate form specifications to the user based on the user-input code and/or code annotations. In this way, user experience can be optimized and computing resources can be saved.
  • obtaining the code and/or code annotations input by the user may also be achieved in the following manner: first, receiving the time range input by the user, and then obtaining the code and/or code annotations entered by the user within the time range.
  • Implementing the above-mentioned implementation method can only obtain the user-input code and/or code annotations within the user's expected time range, and then recommend candidate formal specifications to the user based on the user-input code and/or code annotations. In this way, user experience can be optimized and computing resources can be saved.
  • displaying multiple candidate form specifications to the user may specifically be implemented in the following manner: displaying the sorted multiple candidate form specifications to the user, wherein among the multiple candidate form specifications, the candidate form specification that best matches the code and/or code comments is ranked first.
  • the method provided in the first aspect further includes the following steps: acquiring a target form specification selected by the user from multiple candidate form specifications, and then using the target form specification to verify the code to be verified.
  • an apparatus for recommending formal specifications which includes: an acquisition module, configured to acquire codes input by users and/or annotations of the codes; a protocol recommendation module, configured to obtain multiple candidate formal specifications based on the code and/or the annotations of the code, and display the multiple candidate formal specifications to the user.
  • the specification recommendation module can specifically implement code and/or code-based comments to obtain multiple candidate formal specifications in the following manner: input the code and/or code comments into the formal specification generation model for identification, and use the formal specification output by the formal specification generation model as a candidate formal specification.
  • the specification recommendation module can specifically implement code and/or code-based annotations to obtain multiple candidate formal specifications in the following manner: first, calculate the matching degree between the code and/or code annotations and multiple rules included in the rule base, and then, according to the calculation result, use the formal specification corresponding to the rule whose matching degree is greater than the matching degree threshold among the multiple rules as a candidate formal specification.
  • the protocol recommendation module can specifically implement code-based and/or code-based annotations to obtain multiple candidate formal specifications: based on the corresponding intermediate representation of the code and/or code structured annotations, the candidate formal specifications are generated, wherein the above-mentioned structured annotations of the code are obtained by structurally processing the annotations of the code.
  • the acquisition module may specifically acquire the code and/or code annotation input by the user in the following manner: trigger the acquisition of the code and/or code annotation entered by the user through keywords.
  • the acquisition module can specifically realize the acquisition of the code and/or comment of the code input by the user through keywords in the following manner: monitor whether the user has entered a keyword, and obtain the code and/or comment of the code input by the user when it is detected that the user has input the keyword.
  • the obtaining module may also obtain the code and/or code annotations input by the user in the following manner: first, receive the time range input by the user, and then obtain the code and/or code annotations entered by the user within the time range.
  • the specification recommendation module may specifically display multiple candidate form specifications to the user in the following manner: display the sorted multiple candidate form specifications to the user, wherein among the multiple candidate form specifications, the candidate form specification that best matches the code and/or code comments is ranked first.
  • the device provided by the second aspect further includes a verification module.
  • the obtaining module is also used to obtain a target form specification selected by the user from multiple candidate form specifications
  • the verification module is used to use the target form specification to verify the code to be verified.
  • a computing device in a third aspect, includes a processor and a memory; the processor is configured to execute instructions stored in the memory, so that the computing device implements the method provided in the first aspect or any possible implementation manner of the first aspect.
  • a form specification recommendation system in a fourth aspect, includes a terminal device and a server; the terminal device is used to obtain the code and/or code annotations input by the user; the terminal device is used to send the code and/or code annotations to the server; the server is used to obtain multiple candidate form specifications according to the code and/or code annotations, and send the multiple candidate form specifications to the terminal device; the terminal device is used to display multiple candidate form specifications to the user.
  • a computer-readable storage medium where instructions are stored in the computer-readable storage medium, and the instructions are used to implement the method provided in the above-mentioned first aspect or any possible implementation manner of the first aspect.
  • a sixth aspect provides a computer program product, including a computer program.
  • the computer program When the computer program is read and executed by a computing device, the computing device executes the method provided in the first aspect or any possible implementation manner of the first aspect.
  • Fig. 1 is a schematic diagram of an application scenario involved in the present application
  • Fig. 2 is a schematic structural diagram of a formal specification recommendation system provided by the present application.
  • Fig. 3 is an interactive schematic diagram of a formal specification recommendation method provided by the present application.
  • Fig. 4A is a graphical user interface exemplarily shown in this application.
  • Fig. 4B is a graphical user interface exemplarily shown in this application.
  • Fig. 5 is an interactive schematic diagram of another formal specification recommendation method provided by the present application.
  • Fig. 6 is an exemplary graphical user interface provided by the present application.
  • FIG. 7 is a schematic structural diagram of a formal specification recommendation device provided by the present application.
  • FIG. 8 is a schematic structural diagram of a computing device provided by the present application.
  • Formal specification also known as formal specification or formal description, is a computer system model strictly described by a formal specification language or the properties that a computer system needs to satisfy.
  • the former is a model specification, and the latter is a property specification.
  • formal specification can use different/same formal specification language to describe computer system from different angles, which is the so-called multi-dimensional perspective specification method.
  • Formal specification language refers to a language defined by strict recursive grammar rules, including model specification language, property specification language, etc.
  • the model specification language uses mathematical structure to describe the state change or event trajectory of the system, which directly defines the structure, functional behavior and even non-functional behavior of the described system model;
  • the property specification language is based on the program logic system, and describes a set of properties through logical formulas to define the desired system behavior.
  • the property specification does not directly define the specific behavior of the system.
  • Intermediate representation In the field of compilation, the compiler is usually divided into a front-end and a back-end. Among them, the front-end will perform lexical analysis, syntax analysis, and semantic analysis on the input program, and then generate an intermediate representation, which is the intermediate representation. The back-end will optimize the intermediate representation and then generate the object code. The intermediate representation and the source code are semantically equivalent. Because the source code usually includes various comments, it is very inconvenient to analyze. When performing code analysis, it is usually not directly analyzed based on the source code, but will be converted into an intermediate representation for analysis, so that the analysis results obtained will be more accurate.
  • the commonly used intermediate representations include three address code (three address code, abbreviated as TAC or 3AC), control flow graph (control flow graph, CFG) and static single assignment (static single assignment, SSA), among them, SSA can be divided into minimum SSA, pruned SSA, maximum SSA and so on.
  • TAC three address code
  • CFG control flow graph
  • SSA static single assignment
  • Structured data Refers to data that can be described by numbers or unified data models, with strict length and format. Compared with unstructured data, structured data has the advantages of easy storage, management and processing, and the processing results obtained are usually more accurate.
  • Neural networks can be composed of neural units (also called neurons).
  • a neural unit can refer to an operation unit that takes the variable x s and the intercept b as input, and the output of the operation unit can be:
  • W s is the weight of x s
  • b is the bias of the neuron unit.
  • f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal in the neural unit into an output signal. The output signal of this activation function can be used as the input of the next convolutional layer.
  • the activation function may be a sigmoid function or other functions, which are not limited here.
  • a neural network is a network formed by connecting many of the above-mentioned single neural units, that is, the output of one neural unit can be the input of another neural unit.
  • the input of each neural unit can be connected with the local receptive field of the previous layer to extract the features of the local receptive field.
  • the local receptive field can be an area composed of several neural units.
  • Common neural networks include random forest, support vector machine (SVM), graph neural networks (GNN), convolutional neural networks (CNN), etc.
  • Model training refers to the process of training a neural network to obtain a trained model that can be used to complete a specific task.
  • Training neural network refers to the use of existing data to make the neural network fit the law of the existing data through a certain method, so as to determine the parameters in the neural network.
  • Training a neural network requires the use of a data set. According to whether the data in the data set is labeled (that is, whether the data has a specific type or name), the training of the neural network can be divided into supervised training and unsupervised training.
  • the terminal device used by the developer may be a personal computer, a tablet computer, a mobile notebook, etc., which have the function of writing a formal specification.
  • FIG. 1 illustrates that the terminal device 100 is a personal computer as an example, but this application does not specifically limit it.
  • the present application provides a formal specification recommendation method, device and system, which can automatically obtain multiple candidate formal specifications based on the code and/or code comments that the user has input during the process of manually writing the code and/or formal specification to be verified by the user (that is, the above-mentioned developer), and display the obtained multiple candidate formal specifications to the user.
  • the multiple candidate formal specifications can provide good reference for the user.
  • the specification is used as the target form specification, and the selected target form specification is used to verify the code to be verified.
  • the user does not need to write the entire form specification, which can save the user's energy and time, and can improve the acquisition efficiency of the form specification and the development efficiency of the computer system.
  • Fig. 2 is a schematic structural diagram of a formal specification recommendation system provided by the present application, the system may include a terminal device 100 and a server 300, and the terminal device 100 and the server 300 are connected through a network 200, and the network 200 may be a wide area network, a local area network, a point-to-point connection, etc., or any combination thereof.
  • the server 300 can provide users with shared resource services, and the shared resource services can include format specification recommendation services, object storage services (object storage service, OBS), cloud backup services (cloud backup and recovery, CBR), data management services (data admin service, DAS), etc.
  • object storage service object storage service
  • cloud backup services cloud backup and recovery, CBR
  • data management services data admin service, DAS
  • This application does not limit the types of shared resource services that the server 300 can provide.
  • the server 300 may include a plurality of protocol recommendation nodes, and each protocol recommendation node specifically includes hardware, a virtualization service, and a protocol recommendation server application.
  • Hardware includes computing resources, storage resources, and network resources.
  • Computing resources can adopt heterogeneous computing architectures, for example, central processing unit (central processing unit, CPU) + graphics processing unit (graphics processing unit, GPU) architecture, CPU+AI chip, CPU+GPU+AI chip architecture, etc., are not specifically limited here.
  • Storage resources may include memory, among others.
  • computing resources may be divided into multiple computing unit resources, storage resources may be divided into multiple storage unit resources, and network resources may be divided into multiple network unit resources. Therefore, the image processing platform can be freely combined on the basis of unit resources according to the user's resource requirements, so as to provide resources according to the user's needs.
  • computing resources can be divided into computing unit resources of 5u
  • storage resources can be divided into storage unit resources of 10G
  • the combination of computing resources and storage resources can be, 5u+10G, 5u+20G, 5u+30u,..., 10u+10G, 10u+20G, 10u+30u,....
  • Virtualization service is a service that builds the resources of multiple physical hosts into a unified resource pool through virtualization technology, and flexibly isolates mutually independent resources according to user needs to run user application codes.
  • the virtualization service may include a virtual machine (virtual machine, VM) service, a bare metal server (bare metal server, BMS) service, and a container (container) service.
  • the VM service may be a service in which virtual machine (virtual machine, VM) resource pools are virtualized on multiple physical hosts through a virtualization technology to provide VMs for users on demand.
  • BMS service is a service that virtualizes BMS resource pools on multiple physical hosts to provide users with BMS on demand.
  • Container Service is a service that virtualizes container resource pools on multiple physical hosts to provide users with containers on demand.
  • VM is a simulated virtual computer, that is, a logical computer.
  • BMS is an elastically scalable high-performance computing service. Its computing performance is the same as that of traditional physical machines, and it has the characteristics of safe physical isolation.
  • Container is a kernel virtualization technology that can provide lightweight virtualization to achieve the purpose of isolating user space, processes and resources. It should be understood that the VM service, BMS service, and container service in the above virtualization services are only specific examples. In practical applications, the virtualization service may also be other lightweight or heavyweight virtualization services, which are not specifically limited here.
  • the protocol recommendation server application can be used to receive the user-input code and/or code comments sent by the terminal device 100 when the user manually writes the code and/or the formal specification to be verified on the terminal device 100, and then automatically obtain a plurality of candidate formal specifications based on the user-input code and/or code annotations, and return the generated multiple candidate formal specifications to the terminal device 100, and be displayed to the user by the terminal device 100.
  • the user views multiple candidate formal specifications, he can select the target formal specification from the multiple candidate formal specifications according to his own needs.
  • the server 300 can provide an interface to the user, and the protocol recommendation server application can receive the code and/or code comments sent by the terminal device 100 through the interface, and the protocol recommendation server can send the multiple candidate format protocols to the terminal device 100 through the interface after obtaining multiple candidate format protocols.
  • the interface may be a console (console) or an application program interface (application program interface, API) of the server 300, and the console may specifically be an application program or a web page for the user to interact with the server 300. It should be understood that the above examples are for illustration, and the present application does not make specific limitations.
  • the formal specification recommendation method provided by this application may include the following steps:
  • S301 The terminal device 100 monitors the code writing operation performed by the user in real time.
  • the code written by the user in the code writing operation can be the code and/or the formal specification to be verified by the formal specification.
  • the user can use any programming language (such as java, C, C++, etc.)
  • the formal specification written by the user may be a data model specification, a data function specification, or an interactive communication protocol specification, etc., which are not specifically limited here.
  • the terminal device 100 acquires the code and/or the comment of the code input by the user.
  • the code refers to the characters that the user has input during the process of writing the code to be verified by the formal specification and/or the formal specification.
  • the exemplary graphical user interface shown in Figure 4A and Figure 4B the code shown in Figure 4A is the complete and correct form specification that the user wants to obtain, and the code "amount" shown in Figure 4B is the code that the user has entered when writing the form specification shown in Figure 4A.
  • the terminal device 100 sends the code and/or the comment of the code input by the user to the server 300 .
  • the server 300 obtains a plurality of candidate form specifications based on the code and/or the comment of the code sent by the terminal device 100.
  • the server 300 can refer to one or more combinations of the following methods to obtain multiple candidate form specifications based on the code:
  • the server 300 may pre-store a rule base, and multiple rules in the rule base correspond to multiple formal specifications.
  • the server 300 may acquire the degree of matching between the code and the multiple rules included in the rule base, and then use the formal specification corresponding to the rule whose matching degree is greater than the first matching degree threshold among the multiple rules as a candidate formal specification.
  • the correspondence between multiple rules and multiple formal specifications may be a one-to-one correspondence.
  • the first matching degree threshold can be customized by the user according to the actual situation, for example, 80% or 75%, etc., which is not specifically limited here.
  • the rule base includes rules A to rule E, where rule A corresponds to form a, rule B corresponds to form b, rule C corresponds to form c, rule D corresponds to form d, rule E corresponds to form e, and the first matching degree threshold is 50%.
  • the formal specification d corresponding to rule D and the formal specification e corresponding to rule E are determined as candidate formal specifications.
  • the multiple rules may also be sorted according to the calculation result, and then the form specification corresponding to the part of the multiple rules with a higher matching degree is used as a candidate form specification.
  • the number of selected candidate form specifications can be customized according to the actual situation, for example, 5 or 10 can be customized, which is not specifically limited here.
  • the rule base includes rules A to rule E, where rule A corresponds to form a, rule B corresponds to form b, rule C corresponds to form c, rule D corresponds to form d, rule E corresponds to form e, and the matching degree threshold is 50%.
  • rules A to E the order of multiple rules can be obtained: rule E, rule D, rule B, rule A, and rule C, so two candidate formal specifications can be obtained: formal specification d corresponding to rule D and formal specification e corresponding to rule E.
  • multiple rules and the formal specifications corresponding to the multiple rules can be obtained in advance by specialized rule designers according to various application scenarios.
  • the formal specifications corresponding to the rules in the rule base whose code matching degree is greater than the first matching degree threshold are determined as candidate formal specifications, or the formal specifications corresponding to some rules with a relatively high matching degree are determined as candidate formal specifications, which can ensure the accuracy of the determined candidate formal specifications.
  • Method 2 When the server 300 receives the code sent by the terminal device 100, it inputs the code into a pre-trained formal specification generation model with high recognition accuracy for recognition, and then uses the formal specification output by the formal specification generation model as a candidate formal specification.
  • the formal specification generation model can be trained using a sample set including a large number of known codes.
  • the formal specification generation model can obtain multiple formal specifications and the confidences of the multiple formal specifications.
  • the formal specification generation model can directly output the formal specifications with a confidence greater than the confidence threshold among the multiple formal specifications as candidate formal specifications, or sort them according to the degree of confidence, and output some formal specifications with higher confidence as candidate formal specifications, which are not specifically limited here. Both the confidence threshold and the number of output candidate form reductions can be customized by the user according to the actual situation, and are not specifically limited here.
  • the formal specification generation model can be expressed as:
  • y is the formal specification
  • x is the code
  • f() is the mapping relationship between the code and the formal specification.
  • a machine learning model can be trained using a sample set including a large number of known codes to obtain a formal specification generation model.
  • a large number of known codes included in the sample set can be manually written by the user or obtained from the Internet, which is not specifically limited here;
  • machine learning models can include but are not limited to decision trees, support vector machines, deep learning, etc., deep learning models can use common models that generate codes from natural language processing, such as bidirectional encoder representations from transformers based on transformers (BERT for short), Seq2Seq, transformers, etc., which are not specifically limited in this application;
  • the manner in which the sample set is used to train the machine learning model to obtain the form reduction model can be supervised training or unsupervised training, which is not specifically limited in this application.
  • sample set Take the example of using a sample set to perform supervised training on a machine learning model to obtain a formal specification generation model.
  • the training method is supervised training
  • a large number of known codes included in the sample set can be used as input data samples.
  • the sample set can also include known formal specifications corresponding to each code in a large number of known codes.
  • a large number of known formal specifications can be used as output data samples.
  • a large number of known formal specifications can be manually written by users or obtained from the Internet. No specific restrictions are made here.
  • the i-th known code among a large number of known codes can be used as an input data sample S i
  • the known form specification corresponding to the i-th known code can be used as an output data sample s i . It can be understood that through the above combination, a large number of input data samples and a large number of output data samples can be obtained, and there is a one-to-one correspondence between the large number of input data samples and the large number of output data samples.
  • a large number of input data samples can be used as the input of the machine learning model in turn, and the output data samples corresponding to each input data sample can be used as a reference for the output value of the machine learning model, and the loss function is used to calculate the loss value between the output value of the machine learning model and the above data output samples, and then adjust the parameters of the machine learning model according to the loss value.
  • the machine learning model can be iteratively trained by using the above-mentioned large number of input data samples and a large number of output data samples, and the parameters of the machine learning model can be continuously adjusted until the machine learning model can accurately output the same output value as the output data sample corresponding to the input data sample according to the input data sample, so as to obtain a trained formal specification generation model.
  • the server 300 may pre-store a one-to-one correspondence between a large number of codes and a large number of formal specifications, wherein each formal specification is used to verify its corresponding code.
  • the server 300 may obtain the degree of matching between the code and a large number of pre-stored codes, and then use the formal specification corresponding to the code whose matching degree is greater than the second matching degree threshold among the large number of codes as a candidate form specification.
  • the second matching degree threshold can be customized by the user according to the actual situation, for example, 80% or 75% can be customized, which is not specifically limited here.
  • S305 The server 300 sends multiple candidate form protocols to the terminal device 100.
  • what the server 300 sends to the terminal device 100 may be a plurality of sorted candidate form specifications, wherein among the multiple candidate form specifications, the candidate form specification that best matches the code and/or code comments is ranked first, so that the user can conveniently and quickly view the optimal candidate form specification from the multiple candidate form specifications, and optimize user experience.
  • the server 300 may also send to the terminal device 100 only the candidate form specification that best matches the code and/or the comment of the code among the multiple candidate form specifications, or only send to the terminal device 100 a part of the candidate form specifications that are ranked higher among the multiple candidate form specifications, which is not specifically limited here.
  • the server 300 can refer to any one of the following ways to sort multiple candidate form specifications:
  • the multiple candidate formal specifications can be sorted based on the degree of matching between the rules corresponding to the multiple candidate formal specifications and the code and/or code comments.
  • multiple candidate form specifications may be sorted in descending order of matching degree, and the candidate form specification corresponding to the highest matching degree is determined to be the optimal candidate form specification and arranged first.
  • the multiple candidate formal specifications may be sorted based on the confidence levels corresponding to the multiple candidate formal specifications.
  • multiple candidate form specifications can be sorted in descending order of confidence, and the candidate form specification with the highest corresponding confidence is determined to be the best candidate form specification and arranged first.
  • Mode 3' in the case that multiple candidate form protocols are obtained by adopting mode 3 in the above step S304, the multiple candidate form protocols can be sorted based on the degree of matching between the codes and/or code annotations pre-stored by the server 300 corresponding to the multiple candidate format protocols and the codes and/or code annotations received by the server 300 and sent by the terminal device 100.
  • the server 300 when the server 300 sends multiple candidate form specifications to the terminal device 100 , it may also send the matching degrees or confidence levels corresponding to the multiple candidate form specifications to the terminal device 100 .
  • S306 The terminal device 100 displays multiple candidate form specifications to the user.
  • the multiple candidate form specifications displayed to the user by the terminal device 100 may be the multiple candidate form specifications after sorting. If the terminal device 100 also receives the matching degrees or confidence levels corresponding to the multiple candidate form specifications sent by the server 300, when the terminal device 100 displays the multiple candidate form specifications to the user, it may display the matching degrees or confidence levels corresponding to the multiple candidate form specifications to the user. In this way, it is convenient for the user to quickly and conveniently view the optimal candidate form specification from the multiple candidate form specifications, and optimize user experience.
  • the terminal device 100 acquires a target format protocol selected by the user from multiple candidate format protocols.
  • S308 The terminal device 100 uses the target form protocol to verify the code to be verified.
  • the formal protocol recommendation system shown in Figure 2 can also refer to the interactive schematic diagram shown in Figure 5 to implement the formal protocol recommendation:
  • S501 The terminal device 100 monitors the code writing operation performed by the user in real time.
  • the terminal device 100 acquires the code and/or the comment of the code input by the user.
  • the terminal device 100 sends the code and/or the comment of the code to the server 300 .
  • the server 300 acquires an intermediate representation corresponding to the code and/or a structured annotation of the code.
  • the server 300 obtains multiple candidate form specifications based on the intermediate representation corresponding to the code and/or the structured annotation of the code.
  • S506 The server 300 sends multiple candidate form protocols to the terminal device 100.
  • the terminal device 100 displays multiple candidate form specifications to the user.
  • the terminal device 100 acquires a target format protocol selected by the user from multiple candidate format protocols.
  • the terminal device 100 uses the target form protocol to verify the code to be verified.
  • step S504 can be as follows: the server 300 can obtain the intermediate representation corresponding to the code from the front end of the compiler, and the form of the intermediate representation can be a three-address code, a control flow chart, or a static single assignment, etc., which are not specifically limited here; the server 300 can perform structural processing on the code comment, so as to obtain the structured comment of the code.
  • the server 300 can also clean the comments, such as deleting special symbols included in the comments, such as "*", "#", etc., or adjusting the order of the words included in the comments, etc., which are not specifically limited here.
  • steps S501, S502, S503, S506, S507, S508, and S509 are the same as steps S301, S302, S303, S305, S306, S307, and S308.
  • steps S301, S302, S303, S305, S306, S307, and S308 please refer to the relevant descriptions of steps S301, S302, S303, S305, S306, S307, and S308 above. , will not be repeated here.
  • step S505 is similar to the specific implementation process of the above-mentioned step S304, and reference may be made to the relevant description of the above-mentioned step S304, which will not be repeated here.
  • the terminal device 100 may also directly obtain the intermediate representation corresponding to the code and/or the structured annotation of the code based on the code and/or the annotation of the code, and then send the intermediate representation corresponding to the code and/or the structured annotation of the code to the server 300.
  • the intermediate representation corresponding to the code is easier to analyze, and the obtained analysis results are usually more accurate.
  • the structured comment of the code is easier to process, and the processing result obtained is usually more accurate. This makes the multiple candidate form specifications recommended to users more accurate.
  • the terminal device 100 can also trigger the execution of step S301 or S501 through a keyword.
  • the terminal device 100 can monitor whether the user has input a keyword (such as requires or prey, etc.), and when it is detected that the user has input a keyword, execute step S301 or S501.
  • the position of the keyword input by the user is the position where the user expects to start the form specification recommendation, so that the device (terminal device 100 shown in FIG. 1 ) or system (the form specification recommendation system shown in FIG. 2 ) applying the form specification recommendation method provided by this application can only monitor the code writing operation performed by the user after inputting the keyword, and not monitor the code writing operation performed by the user before inputting the keyword, which can optimize user experience and save computing resources.
  • the terminal device 100 can monitor the content input by the user in real time, and then match the content input by the user with multiple keywords in the keyword database to determine whether there is a keyword matching the content input by the user in the keyword database.
  • the terminal device 100 may also receive a time range input by the user.
  • This time range is the time range in which the user will perform code writing operations and is also the time when the user expects to recommend form specifications.
  • the device or system that applies the form specification recommendation method provided by this application can only monitor the code writing operations performed by the user within this time range, and perform form specification recommendations based on the code writing operations within this time range. It does not monitor the code writing operations performed by the user outside the time range, which can optimize user experience and save computing resources.
  • the server 300 may further screen the multiple candidate protocols to filter out some obviously worthless protocols, for example, filter out the protocols with obvious errors (such as grammatical errors or semantic errors, etc.), so that the multiple candidate protocols finally recommended to the user can be more accurate.
  • the formal specification recommendation system and formal specification recommendation method provided by this application can monitor the code writing operation performed by the user in real time, obtain the code and/or code comments entered by the user, and then automatically obtain multiple candidate formal specifications according to the code and/or code comments, and finally recommend the obtained multiple candidate formal specifications to the user. , and use the selected target formal specification to verify the code to be verified, the user does not need to write the entire formal specification, which can save the user's energy and time, and can improve the efficiency of formal specification acquisition and computer system development.
  • FIG. 6 is an exemplary graphical user interface 600 provided by the present application. It can be seen from FIG. 6 that the interface 600 may include a code input area 610 .
  • the code input area 610 can provide the user with an interface for inputting codes and code comments.
  • the user can input keywords and perform code writing operations in this area. For example, "requires" shown in FIG.
  • the interface 600 can also provide the user with a "Add Code" control 620, as shown in FIG.
  • the device or system applying the formal protocol recommendation method provided by this application After the device or system applying the formal protocol recommendation method provided by this application detects that the user has input the keyword "requires", it can execute the above steps S301-S304 or execute the above-mentioned steps S501-S505 to obtain multiple candidate formal protocols, sort the multiple candidate formal protocols, and then display the sorting results to the user.
  • the protocol recommendation pop-up window 630 shown in FIG. c may be the sorted candidate formal specifications recommended to the user by a device or a system applying the formal specification recommendation method provided in this application.
  • the user determines that there is a candidate format specification that meets his needs in the pop-up window 630, he can click on the format specification, such as clicking on the format specification d, and then click on the "OK" control 6301 displayed in the pop-up window 630 to determine the clicked candidate format specification as the target format specification.
  • FIG. 6 is used for illustration, and is not specifically limited in the present application.
  • the method for recommending formal specifications provided by this application, for the user, after inputting code and/or code comments on the interface shown in interface 600, can obtain multiple sorted candidate formal specifications on the display interface shown in interface 600, and the sorting results can provide good reference for users. .
  • protocol recommendation method provided by the present application shown in FIG. 3 and FIG. 5 can be applied to the terminal device 100 shown in FIG. 1 in addition to the protocol recommendation system shown in FIG. 2 , that is, the steps performed by the server 300 in the embodiment shown in FIG. 3 and FIG. and using the selected target formal specification to verify the code to be verified, the user does not need to write the entire formal specification, which can save the user's energy and time, and can improve the efficiency of formal specification acquisition and computer system development.
  • the form specification recommendation device provided by this application.
  • This device can be applied to the terminal device 100 shown in FIG. 1, or to the form specification recommendation system shown in FIG. 2, and can be applied to the server 300 shown in FIG.
  • the unit modules inside the formal specification recommendation device can also be divided into multiple types. Each module can be a software module, or a hardware module, or partly a software module and partly a hardware module, which is not limited in this application.
  • the form specification recommendation device is applied to the server 300 shown in FIG. 2, and the form specification recommendation device includes a plurality of unit modules, each module in the plurality of unit modules can be deployed on the same server 300, or can be deployed on different servers 300, which is not specifically limited in this application.
  • FIG. 7 is a schematic structural diagram of an apparatus 700 for form protocol recommendation in this application.
  • the apparatus 700 includes: an acquisition module 710 and a protocol recommendation module 720 .
  • Obtaining module 710 configured to obtain codes and/or comments of codes input by the user.
  • the protocol recommending module 720 is configured to obtain multiple candidate formal specifications based on the code and/or code comments input by the user, and display the multiple candidate formal specifications to the user.
  • the protocol recommendation module 720 can specifically obtain multiple candidate formal specifications based on the code and/or code comments input by the user in the following manner: identify the code and/or code comments as input to the formal specification generation model, and use the formal specification output by the formal specification generation model as a candidate formal specification.
  • the protocol recommendation module 720 can specifically obtain multiple candidate formal specifications based on user-input code and/or code annotations in the following manner: first, obtain the matching degree between the code and/or code annotations and multiple rules included in the rule base, and then use the formal specification corresponding to the rule whose matching degree is greater than the matching degree threshold among the multiple rules as a candidate formal specification.
  • the protocol recommending module 720 can specifically obtain multiple candidate formal specifications based on user-input codes and/or code annotations in the following manner: generate multiple candidate formal specifications based on the intermediate representation corresponding to the codes and/or code structured annotations, wherein the above-mentioned structured annotations of codes are obtained by performing structural processing on the code annotations.
  • the acquiring module 710 may specifically acquire the code and/or comment of the code input by the user in the following manner: triggering acquisition of the code and/or comment of the code input by the user through keywords.
  • the acquisition module 710 can specifically implement the acquisition of the code and/or code annotations entered by the user through keywords in the following manner: monitor whether the user has entered a keyword, and obtain the code and/or code annotations entered by the user when it is detected that the user has entered the keyword.
  • the position of the above-mentioned keywords is the position where the user expects to start the form specification recommendation, so that the device or system that applies the form specification recommendation method provided by this application can only monitor the code writing operation performed by the user after inputting the keyword, and not monitor the code writing operation performed by the user before inputting the keyword, which can optimize user experience and save computing resources.
  • the acquisition module 710 can also obtain the code and/or code comments input by the user in the following manner: the time range for receiving user input, the time range is the time range for the user to write codes, and the time when the user expects to recommend formal specifications, so that the device or system that applies the formal specification recommendation method provided by this application can only monitor the code writing operations performed by the user within this time range, and perform formal specification recommendations based on the code writing operations within this time range, and not monitor the codes performed by users outside this time range Writing operations can optimize user experience and save computing resources.
  • the protocol recommendation module 720 when displaying multiple candidate protocols to the user, may display the sorted multiple candidate protocols to the user, wherein among the multiple candidate protocols, the candidate protocol that best matches the code and/or code comments is ranked first, so that the user can conveniently and quickly view the optimal candidate protocol from the multiple candidate protocols.
  • the device 700 further includes a verification module 730.
  • the verification module 730 is used to use the target form specification to verify the code to be verified.
  • the formal specification recommending apparatus 700 reference may be made to the descriptions in the related content in the above-mentioned formal specification recommending method embodiment, and for the sake of brevity, details are not repeated here.
  • the formal specification recommendation device provided by this application (the device 700 shown in Figure 7 ) can automatically generate multiple candidate formal specifications according to the code and/or code annotations by obtaining the code and/or code comments input by the user, and finally recommend the generated multiple candidate formal specifications to the user.
  • the multiple candidate formal specifications can provide users with good references.
  • the target form specification is verified by the code to be verified, and the user does not need to write the entire form specification, which can save the user's energy and time, and can improve the efficiency of obtaining the form specification and the development efficiency of the computer system.
  • FIG. 8 is a schematic structural diagram of a computing device 800 provided by the present application. As shown in FIG. 8,
  • the processor 810 can read the program codes (including instructions) stored in the memory 820, and execute the program codes stored in the memory 820, so that the computing device 800 executes the steps in the formal specification recommendation method provided by the above method embodiments, or makes the computing device 800 deploy the formal specification recommendation apparatus 700.
  • the processor 810 may have multiple specific implementation forms, such as a central processing unit (central processing unit, CPU), or a combination of a CPU and a hardware chip.
  • the aforementioned hardware chip may be an application-specific integrated circuit (application-specific integrated circuit, ASIC), a programmable logic device (programmable logic device, PLD) or a combination thereof.
  • ASIC application-specific integrated circuit
  • PLD programmable logic device
  • the above-mentioned PLD may be a complex programmable logic device (complex programmable logic device, CPLD), a field-programmable gate array (field-programmable gate array, FPGA), a general array logic (generic array logic, GAL) or any combination thereof.
  • Processor 810 executes various types of digitally stored instructions, such as software or firmware programs stored in memory 820, which enable computing device 800 to provide various services.
  • the memory 820 is used to store program codes, which are controlled and executed by the processor 810, so as to execute the processing steps in any one of the above-mentioned embodiments in FIG. 3 and FIG. 5 .
  • the program code may include one or more software modules, and the one or more software modules may be the software modules provided in the embodiment of FIG. 7 , such as an acquisition module 710 , a protocol recommendation module 720 and a verification module 730 .
  • Memory 820 can comprise volatile memory (volatile memory), such as random access memory (random access memory, RAM); Memory 820 can also comprise nonvolatile memory (non-volatile memory), such as read-only memory (read-only memory, ROM), flash memory (flash memory), hard disk (hard disk drive, HDD) or solid-state drive (solid-state drive) ive, SSD); the memory 820 may also include a combination of the above types.
  • volatile memory such as random access memory (random access memory, RAM)
  • Memory 820 can also comprise nonvolatile memory (non-volatile memory), such as read-only memory (read-only memory, ROM), flash memory (flash memory), hard disk (hard disk drive, HDD) or solid-state drive (solid-state drive) ive, SSD); the memory 820 may also include a combination of the above types.
  • the communication interface 830 can be a wired interface (such as an Ethernet interface, an optical fiber interface, other types of interfaces (such as an infiniBand interface)) or a wireless interface (such as a cellular network interface or using a wireless local area network interface) for communicating with other computing devices or devices.
  • the communication interface 830 can adopt a protocol family above the transmission control protocol/internet protocol (transmission control protocol/internet protocol, TCP/IP), for example, a remote function call (remote function call, RFC) protocol, a simple object access protocol (simple object access protocol, SOAP) protocol, a simple network management protocol (simple network management protocol, SNMP) protocol , common object request broker architecture (common object request broker architecture, CORBA) protocol and distributed protocol, etc.
  • TCP/IP transmission control protocol/internet protocol
  • RFC remote function call
  • simple object access protocol simple object access protocol
  • SOAP simple network management protocol
  • SNMP simple network management protocol
  • CORBA common object request broker architecture
  • the bus 840 can be a peripheral component interconnect express (PCIe) bus, or an extended industry standard architecture (EISA) bus, a unified bus (Ubus or UB), a computer fast link (compute express link, CXL), or a cache coherent interconnect for accelerator s, CCIX) etc.
  • PCIe peripheral component interconnect express
  • EISA extended industry standard architecture
  • Ubus or UB unified bus
  • CXL compute express link
  • CCIX cache coherent interconnect for accelerator s
  • the bus 840 can be divided into an address bus, a data bus, a control bus, and the like.
  • the bus 840 may also include a power bus, a control bus, and a status signal bus.
  • the various buses are labeled as bus 840 in the figure. For ease of representation, only one thick line is used in FIG. 8 , but it does not mean that there is only one bus or one type of bus.
  • the above-mentioned computing device 800 is used to execute the form specification recommendation method provided by this application as shown in FIG. 3 or FIG. 5 , which belongs to the same concept as the above-mentioned method embodiment. For the specific implementation process, refer to the above-mentioned method embodiment for details, and will not be repeated here. It should be understood that computing device 800 is only an example provided by the embodiment of the present application, and computing device 800 may have more or fewer components than those shown in FIG. 8 , may combine two or more components, or may have different configurations of components.
  • the present application also provides a computer-readable storage medium, and the computer-readable storage medium stores instructions, and when the instructions are executed, some or all steps of the formal specification recommendation method described in the above-mentioned embodiments can be implemented.
  • the present application also provides a computer program product.
  • the computer program product When the computer program product is read and executed by a computer, it can realize some or all steps of the formal specification recommendation method described in the above method embodiments.
  • all or part may be implemented by software, hardware or any combination thereof.
  • software When implemented using software, it may be implemented in whole or in part in the form of a computer program product.
  • the computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application will be generated in whole or in part.
  • the computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line) or wireless (such as infrared, wireless, microwave, etc.) means.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server or a data center integrated with one or more available media.
  • the available medium may be a magnetic medium (such as a floppy disk, a hard disk, or a magnetic tape), an optical medium, or a semiconductor medium.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Artificial Intelligence (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Evolutionary Computation (AREA)
  • General Health & Medical Sciences (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Library & Information Science (AREA)
  • Databases & Information Systems (AREA)
  • Stored Programmes (AREA)

Abstract

A form specification recommendation method, apparatus and system. The method comprises: firstly, acquiring a code input by a user and/or an annotation of the code (S302); then, on the basis of the code input by the user and/or the annotation of the code, obtaining a plurality of candidate form specifications (S304); displaying the plurality of candidate form specifications to the user (S306); the user being capable of selecting, from the plurality of candidate form specifications, a candidate form specification satisfying the requirements as a target form specification; and using the selected target form specification to verify the code to be verified. According to the method, the plurality of candidate form specifications are automatically generated and recommended to the user, so that the compiling work of the form specification can be simplified, and the acquisition efficiency of the form specification and the development efficiency of the computer system are improved.

Description

形式规约推荐方法、装置以及系统Formal specification recommended method, device and system
本申请要求于2022年01月21日提交中国专利局、申请号为202210074154.X、发明名称为“形式规约推荐方法、装置以及系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202210074154.X and the title of the invention "Proforma Specification Recommendation Method, Device and System" submitted to the China Patent Office on January 21, 2022, the entire contents of which are incorporated in this application by reference.
技术领域technical field
本申请涉及计算机技术领域,尤其涉及一种形式规约推荐方法、装置以及系统。The present application relates to the field of computer technology, and in particular to a form specification recommendation method, device and system.
背景技术Background technique
形式化方法是基于严格数学基础,对计算机系统(软/硬件系统)进行形式规约、开发和验证的技术。设计开发一个可靠的计算机系统通常需要大量的形式规约支持。其中,形式规约,是由形式规约语言严格描述的计算机系统模型、计算机系统需要满足的性质或者计算机系统中的待检测漏洞等,形式规约是形式化方法的基础,在形式化方法中占据了重要的地位。Formal methods are techniques for formally specifying, developing, and verifying computer systems (software/hardware systems) based on strict mathematical foundations. Designing and developing a reliable computer system usually requires a lot of formal specification support. Among them, the formal specification is the computer system model strictly described by the formal specification language, the properties that the computer system needs to satisfy, or the loopholes to be detected in the computer system, etc. The formal specification is the basis of the formal method and occupies an important position in the formal method.
然而,目前,在基于形式化方法设计开发计算机系统时,通常需要开发人员手动编写大量的形式规约,该种获取形式规约的方式存在着需要消耗大量的人力和时间,会导致形式规约的获取效率以及计算机系统开发效率较低的问题。However, at present, when designing and developing computer systems based on formal methods, developers usually need to manually write a large number of formal specifications. This method of obtaining formal specifications consumes a lot of manpower and time, which will lead to the problems of low efficiency of formal specification acquisition and computer system development.
发明内容Contents of the invention
本申请提供一种形式规约推荐方法、装置以及系统,用以简化形式规约的编写工作,提高形式规约的获取效率以及计算机系统的开发效率。The present application provides a formal specification recommendation method, device and system, which are used to simplify the writing work of the formal specification, improve the efficiency of obtaining the formal specification and the development efficiency of the computer system.
第一方面,提供一种形式规约推荐方法,该方法包括:首先,获取用户输入的代码和/或代码的注释,然后,基于用户输入的代码和/或代码的注释,得到多个候选形式规约,并向用户显示多个候选形式规约。In a first aspect, a method for recommending formal specifications is provided, the method comprising: firstly, acquiring user-input codes and/or code annotations, and then obtaining multiple candidate formal specifications based on the user-input codes and/or code annotations, and displaying the multiple candidate formal specifications to the user.
实施上述第一方面描述的方法,可在用户编写待形式规约验证的代码和/或形式规约时,实时获取用户输入的代码和/或代码的注释,然后基于用户输入的代码和/或代码的注释,自动得到多个候选形式规约,该多个候选形式规约可以给用户提供良好的参考,若用户确定多个候选形式规约中有满足自己需求的候选形式规约,则用户可直接选择该规约作为目标形式规约,用户无需进行整个形式规约的编写工作,能够节省用户的精力和时间,提高形式规约的获取效率。By implementing the method described in the first aspect above, when the user writes the code and/or formal specification to be verified by the formal specification, the user-input code and/or code comments can be obtained in real time, and then based on the user-input code and/or code comments, multiple candidate formal specifications can be automatically obtained, and the multiple candidate formal specifications can provide users with good references. Save energy and time of users, and improve the acquisition efficiency of formal specifications.
在一种可能的实现方式中,具体可以通过如下方式实现基于代码和/或代码的注释,生成得到候选形式规约:将代码和/或代码的注释,输入形式规约生成模型进行识别,将形式规约生成模型输出的形式规约作为候选形式规约。In a possible implementation, the code and/or code-based comments can be specifically implemented to generate candidate formal specifications in the following manner: the code and/or code comments are input into the formal specification generation model for identification, and the formal specification output by the formal specification generation model is used as the candidate formal specification.
在具体实现中,形式规约生成模型可以是使用包括大量已知代码和/或大量已知代码的注释的样本集进行训练得到的具有较高识别精度的模型,样本集包括的大量已知代码和/或大量已知代码的注释,可以是用户手动编写的,也可以是从互联网上获取的,此处不作具体限定In a specific implementation, the formal specification generation model can be a model with high recognition accuracy obtained by training a sample set including a large number of known codes and/or annotations of a large number of known codes. The sample set includes a large number of known codes and/or annotations of a large number of known codes. It can be manually written by users or obtained from the Internet, and is not specifically limited here.
在具体实现中,在将代码和/或代码的注释输入到形式规约生成模型之后,形式规约生成模型可以得到多个形式规约以及多个形式规约的置信度,形式规约生成模型可以将多个形式规约中置信度大于置信度阈值的形式规约直接作为候选形式规约输出,也可以按照置信度大 小进行排序,将置信度较大的部分形式规约作为候选形式规约输出,此处不作具体限定。置信度阈值、输出的候选形式规约的数量均可以由用户根据实际情况进行自定义,此处不作具体限定。In a specific implementation, after the code and/or code comments are input to the formal specification generation model, the formal specification generation model can obtain multiple formal specifications and the confidence levels of the multiple formal specifications, and the formal specification generation model can directly output the formal specifications whose confidence is greater than the confidence threshold among the multiple formal specifications as candidate formal specifications, or sort them according to the degree of confidence, and output part of the formal specifications with higher confidence as candidate formal specifications, which is not specifically limited here. Both the confidence threshold and the number of output candidate form reductions can be customized by the user according to the actual situation, and are not specifically limited here.
实施上述实现方式,将代码和/或代码的注释,输入形式规约生成模型进行识别,将形式规约生成模型输出的形式规约作为候选形式规约,由于形式规约生成模型为提前训练好的具有较高识别精度的模型,因此,可以保证生成的候选形式规约的准确性。Implement the above implementation, input the code and/or code comments into the formal specification generation model for identification, and use the formal specification output by the formal specification generation model as a candidate formal specification. Since the formal specification generation model is a model with high recognition accuracy trained in advance, the accuracy of the generated candidate formal specification can be guaranteed.
在一种可能的实现方式中,具体可以通过如下方式实现基于代码和/或代码的注释,得到多个候选形式规约:首先,计算代码和/或代码的注释与规则库包括的多条规则之间的匹配度,然后,根据计算结果将多条规则中匹配度大于匹配度阈值的规则对应的形式规约,作为候选形式规约。In a possible implementation manner, multiple candidate formal specifications can be obtained by implementing code and/or code-based comments in the following manner: first, calculate the matching degree between the code and/or code comments and multiple rules included in the rule base, and then, according to the calculation result, use the formal specification corresponding to the rule whose matching degree is greater than the matching degree threshold among the multiple rules as a candidate formal specification.
其中,规则库包括的多条规则对应多个形式规约,具体地,其对应关系可以为一一对应。匹配度阈值可以由用户根据实际情况进行自定义,例如,自定义为80%或者75%等,此处不作具体限定。Wherein, multiple rules included in the rule base correspond to multiple formal specifications, specifically, the corresponding relationship may be one-to-one. The matching degree threshold can be customized by the user according to the actual situation, for example, 80% or 75%, etc., which is not specifically limited here.
可选地,在计算得到代码与规则库包括的多条规则之间的匹配度之后,也可以根据计算结果对多条规则进行排序,然后将多条规则中匹配度较大的部分规则对应的形式规约,作为候选形式规约。具体实现中,可以根据实际情况自定义选择出的候选形式规约的数量,例如,自定义为5或者10,此处不作具体限定。Optionally, after calculating the matching degree between the code and the multiple rules included in the rule base, the multiple rules may also be sorted according to the calculation result, and then the form specification corresponding to the part of the multiple rules with a higher matching degree is used as a candidate form specification. In a specific implementation, the number of selected candidate form specifications can be customized according to the actual situation, for example, 5 or 10 can be customized, which is not specifically limited here.
在具体实现中,规则库中的多条规则以及多条规则对应的形式规约可以为专门的规则设计人员预先根据多种应用场景得到。In a specific implementation, multiple rules in the rule base and the formal specifications corresponding to the multiple rules can be obtained in advance according to various application scenarios for specialized rule designers.
实施上述实现方式,将规则库中与代码和/或代码的注释匹配度大于匹配度阈值的规则对应的形式规约,作为候选形式规约,由于规则库中的多条规则以及多条规则对应的形式规约可以为专门的规则设计人员预先根据多种应用场景到,因此,可以保证生成的候选形式规约的准确性。Implement the above implementation method, use the formal specification corresponding to the code and/or code comment matching degree greater than the matching degree threshold in the rule base as the candidate formal specification, because the multiple rules in the rule base and the formal specification corresponding to the multiple rules can be found in advance by a special rule designer according to various application scenarios, therefore, the accuracy of the generated candidate formal specification can be guaranteed.
在一种可能的实现方式中,具体可以通过如下方式实现基于代码和/或代码的注释,得到多个候选形式规约:基于代码对应的中间表示和/或代码的结构化注释,得到多个候选形式规约,其中,上述代码的结构化注释是对代码的注释进行结构化处理得到的。In a possible implementation manner, multiple candidate form specifications can be obtained by implementing code-based and/or code-based comments in the following manner: multiple candidate form specifications are obtained based on the intermediate representation corresponding to the code and/or structured comments of the code, wherein the above-mentioned structured comments of the code are obtained by structurally processing the comments of the code.
由于代码对应的中间表示相较于代码本身,更便于分析,且得到的分析结果通常也会更准确,代码的结构化注释相较于代码的注释(指结构化处理之前的注释),更易于处理,且得到的处理结果通常也会更准确,因此,实施上述实现方式,基于代码对应的中间表示和/或代码的结构化注释,得到多个候选形式规约,可以提高得到的候选形式规约的准确度,能够使得最终向用户推荐的多个候选形式规约更精准。Since the intermediate representation corresponding to the code is easier to analyze than the code itself, and the obtained analysis results are usually more accurate, the structured comment of the code is easier to process than the comment of the code (referring to the comment before the structured processing), and the obtained processing result is usually more accurate. Therefore, implementing the above implementation method, based on the intermediate representation corresponding to the code and/or the structured comment of the code, multiple candidate form specifications can be obtained, which can improve the accuracy of the obtained candidate form specifications, and can make the multiple candidate form specifications finally recommended to users more accurate.
在一种可能的实现方式中,具体可以通过如下方式实现获取用户输入的代码和/或代码的注释:通过关键词触发用户数输入的代码和/或代码的注释的获取。In a possible implementation manner, the acquisition of the code input by the user and/or the comment of the code may be specifically achieved in the following manner: the acquisition of the code input by the user and/or the comment of the code is triggered by a keyword.
在一种可能的实现方式中,具体可以通过如下方式实现通过关键词触发用户数输入的代码和/或代码的注释的获取:监测用户是否输入了关键词,在监测到用户输入了关键词的情况下,获取用户输入的代码和/或代码的注释。In a possible implementation manner, the acquisition of the code and/or comment of the code input by the user can be triggered by keywords in the following manner: monitor whether the user has input a keyword, and obtain the code and/or comment of the code input by the user when it is detected that the user has input the keyword.
实施上述实现方式,可以使得仅监测用户在输入关键词之后输入的代码和/或代码的注释,然后基于用户输入的代码和/或代码的注释向用户推荐候选形式规约,如此,可以优化用户体验,节省计算资源。Implementing the above-mentioned implementation mode can only monitor the code and/or code annotations entered by the user after the keyword is entered, and then recommend candidate form specifications to the user based on the user-input code and/or code annotations. In this way, user experience can be optimized and computing resources can be saved.
在一种可能的实现方式中,还可以通过如下方式实现获取用户输入的代码和/或代码的注释:首先,接收用户输入的时间范围,然后,获取用户在所述时间范围内输入的代码和/或代 码的注释。In a possible implementation manner, obtaining the code and/or code annotations input by the user may also be achieved in the following manner: first, receiving the time range input by the user, and then obtaining the code and/or code annotations entered by the user within the time range.
实施上述实现方式,可以使得仅在用户期望的时间范围内获取用户输入的代码和/或代码的注释,然后基于用户输入的代码和/或代码的注释向用户推荐候选形式规约,如此,可以优化用户体验,节省计算资源。Implementing the above-mentioned implementation method can only obtain the user-input code and/or code annotations within the user's expected time range, and then recommend candidate formal specifications to the user based on the user-input code and/or code annotations. In this way, user experience can be optimized and computing resources can be saved.
在一种可能的实现方式中,具体可以通过如下方式实现向用户显示多个候选形式规约:向用户显示排序后的多个候选形式规约,其中,多个候选形式规约中与代码和/或代码的注释匹配最优的候选形式规约排列在首位。In a possible implementation manner, displaying multiple candidate form specifications to the user may specifically be implemented in the following manner: displaying the sorted multiple candidate form specifications to the user, wherein among the multiple candidate form specifications, the candidate form specification that best matches the code and/or code comments is ranked first.
实施上述实现方式,将多个候选形式规约中与代码和/或代码的注释匹配最优的候选形式规约排列在首位,便于用户方便快捷地从多个候选形式规约中查看到上述最优候选形式规约,能够优化用户体验。Implement the above implementation method, and arrange the candidate form specification that best matches the code and/or code comments in the first place among the multiple candidate form specifications, so that the user can conveniently and quickly view the above-mentioned optimal candidate form specification from the multiple candidate form specifications, and can optimize user experience.
在一种可能的实现方式中,第一方面提供的方法还包括如下步骤:获取用户从多个候选形式规约中选择出的目标形式规约,然后,使用目标形式规约对待验证代码进行验证。In a possible implementation manner, the method provided in the first aspect further includes the following steps: acquiring a target form specification selected by the user from multiple candidate form specifications, and then using the target form specification to verify the code to be verified.
实施上述实现方式,直接使用选择出的目标形式规约对待验证代码进行验证,可以提高代码的验证效率,从而提高计算机系统的开发效率。Implementing the above implementation method and directly using the selected target form specification to verify the code to be verified can improve the verification efficiency of the code, thereby improving the development efficiency of the computer system.
第二方面,提供一种形式规约推荐装置,该装置包括:获取模块,用于获取用户输入的代码和/或代码的注释;规约推荐模块,用于基于代码和/或代码的注释,得到多个候选形式规约,并向用户显示多个候选形式规约。In a second aspect, an apparatus for recommending formal specifications is provided, which includes: an acquisition module, configured to acquire codes input by users and/or annotations of the codes; a protocol recommendation module, configured to obtain multiple candidate formal specifications based on the code and/or the annotations of the code, and display the multiple candidate formal specifications to the user.
在一种可能的实现方式中,规约推荐模块,具体可以通过如下方式实现基于代码和/或代码的注释,得到多个候选形式规约:将代码和/或代码的注释,输入形式规约生成模型进行识别,将形式规约生成模型输出的形式规约作为候选形式规约。In a possible implementation, the specification recommendation module can specifically implement code and/or code-based comments to obtain multiple candidate formal specifications in the following manner: input the code and/or code comments into the formal specification generation model for identification, and use the formal specification output by the formal specification generation model as a candidate formal specification.
在一种可能的实现方式中,规约推荐模块,具体可以通过如下方式实现基于代码和/或代码的注释,得到多个候选形式规约:首先,计算代码和/或代码的注释与规则库包括的多条规则之间的匹配度,然后,根据计算结果将多条规则中匹配度大于匹配度阈值的规则对应的形式规约,作为候选形式规约。In a possible implementation, the specification recommendation module can specifically implement code and/or code-based annotations to obtain multiple candidate formal specifications in the following manner: first, calculate the matching degree between the code and/or code annotations and multiple rules included in the rule base, and then, according to the calculation result, use the formal specification corresponding to the rule whose matching degree is greater than the matching degree threshold among the multiple rules as a candidate formal specification.
在一种可能的实现方式中,规约推荐模块,具体可以通过如下方式实现基于代码和/或代码的注释,得到多个候选形式规约:基于代码对应的中间表示和/或代码的结构化注释,生成得到候选形式规约,其中,上述代码的结构化注释是对代码的注释进行结构化处理得到的。In a possible implementation, the protocol recommendation module can specifically implement code-based and/or code-based annotations to obtain multiple candidate formal specifications: based on the corresponding intermediate representation of the code and/or code structured annotations, the candidate formal specifications are generated, wherein the above-mentioned structured annotations of the code are obtained by structurally processing the annotations of the code.
在一种可能的实现方式中,获取模块,具体可以通过如下方式实现获取用户输入的代码和/或代码的注释:通过关键词触发用户数输入的代码和/或代码的注释的获取。In a possible implementation manner, the acquisition module may specifically acquire the code and/or code annotation input by the user in the following manner: trigger the acquisition of the code and/or code annotation entered by the user through keywords.
在一种可能的实现方式中,获取模块,具体可以通过如下方式实现通过关键词触发用户数输入的代码和/或代码的注释的获取:监测用户是否输入了关键词,在监测到用户输入了关键词的情况下,获取用户输入的代码和/或代码的注释。In a possible implementation manner, the acquisition module can specifically realize the acquisition of the code and/or comment of the code input by the user through keywords in the following manner: monitor whether the user has entered a keyword, and obtain the code and/or comment of the code input by the user when it is detected that the user has input the keyword.
在一种可能的实现方式中,获取模块,还可以通过如下方式实现获取用户输入的代码和/或代码的注释:首先,接收用户输入的时间范围,然后,获取用户在所述时间范围内输入的代码和/或代码的注释。In a possible implementation manner, the obtaining module may also obtain the code and/or code annotations input by the user in the following manner: first, receive the time range input by the user, and then obtain the code and/or code annotations entered by the user within the time range.
在一种可能的实现方式中,规约推荐模块,具体可以通过如下方式实现向用户显示多个候选形式规约:向用户显示排序后的多个候选形式规约,其中,多个候选形式规约中与代码和/或代码的注释匹配最优的候选形式规约排列在首位。In a possible implementation manner, the specification recommendation module may specifically display multiple candidate form specifications to the user in the following manner: display the sorted multiple candidate form specifications to the user, wherein among the multiple candidate form specifications, the candidate form specification that best matches the code and/or code comments is ranked first.
在一种可能的实现方式中,第二方面提供的装置还包括验证模块,当获取模块还用于获取用户从多个候选形式规约中选择出的目标形式规约时,上述验证模块用于使用目标形式规约对待验证代码进行验证。In a possible implementation manner, the device provided by the second aspect further includes a verification module. When the obtaining module is also used to obtain a target form specification selected by the user from multiple candidate form specifications, the verification module is used to use the target form specification to verify the code to be verified.
第三方面,提供一种计算设备,该计算设备包括处理器和存储器;所述处理器用于执行所述存储器存储的指令,使得所述计算设备实现如上述第一方面或者第一方面的任意可能的实现方式提供的方法。In a third aspect, a computing device is provided, and the computing device includes a processor and a memory; the processor is configured to execute instructions stored in the memory, so that the computing device implements the method provided in the first aspect or any possible implementation manner of the first aspect.
第四方面,提供一种形式规约推荐系统,该系统包括终端设备和服务器;终端设备,用于获取用户输入的代码和/或代码的注释;终端设备,用于将代码和/或代码的注释发送给服务器;服务器,用于根据代码和/或代码的注释,得到多个候选形式规约,并将多个候选形式规约发送给终端设备;终端设备,用于向用户显示多个候选形式规约。In a fourth aspect, a form specification recommendation system is provided, the system includes a terminal device and a server; the terminal device is used to obtain the code and/or code annotations input by the user; the terminal device is used to send the code and/or code annotations to the server; the server is used to obtain multiple candidate form specifications according to the code and/or code annotations, and send the multiple candidate form specifications to the terminal device; the terminal device is used to display multiple candidate form specifications to the user.
第五方面,提供一种计算机可读存储介质,该计算机可读存储介质存储有指令,所述指令用于实现如上述第一方面或者第一方面的任意可能的实现方式提供的方法。In a fifth aspect, there is provided a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and the instructions are used to implement the method provided in the above-mentioned first aspect or any possible implementation manner of the first aspect.
第六方面,提供一种计算机程序产品,包括计算机程序,当所述计算机程序被计算设备读取并执行时,使得所述计算设备执行如上述第一方面或者第一方面的任意可能的实现方式提供的方法。A sixth aspect provides a computer program product, including a computer program. When the computer program is read and executed by a computing device, the computing device executes the method provided in the first aspect or any possible implementation manner of the first aspect.
附图说明Description of drawings
图1是本申请涉及的一种应用场景的示意图;Fig. 1 is a schematic diagram of an application scenario involved in the present application;
图2是本申请提供的一种形式规约推荐系统的结构示意图;Fig. 2 is a schematic structural diagram of a formal specification recommendation system provided by the present application;
图3是本申请提供的一种形式规约推荐方法的交互示意图;Fig. 3 is an interactive schematic diagram of a formal specification recommendation method provided by the present application;
图4A是本申请示例性示出的一种图形用户界面;Fig. 4A is a graphical user interface exemplarily shown in this application;
图4B是本申请示例性示出的一种图形用户界面;Fig. 4B is a graphical user interface exemplarily shown in this application;
图5是本申请提供的另一种形式规约推荐方法的交互示意图;Fig. 5 is an interactive schematic diagram of another formal specification recommendation method provided by the present application;
图6是本申请提供的一种示例性图形用户界面;Fig. 6 is an exemplary graphical user interface provided by the present application;
图7是本申请提供的一种形式规约推荐装置的结构示意图;FIG. 7 is a schematic structural diagram of a formal specification recommendation device provided by the present application;
图8是本申请提供的一种计算设备的结构示意图。FIG. 8 is a schematic structural diagram of a computing device provided by the present application.
具体实施方式Detailed ways
下面将结合附图,对本申请提供的技术方案进行描述。为了使本申请提供的技术方案更清晰,在具体描述本申请提供的技术方案之前,首先进行相关术语的解释。The technical solution provided by this application will be described below with reference to the accompanying drawings. In order to make the technical solution provided by this application clearer, before describing the technical solution provided by this application in detail, explanations of relevant terms are firstly made.
形式规约:也称形式规范或者形式化描述,是由形式规约语言严格描述的计算机系统模型或者计算机系统需要满足的性质,前者是模型规约,后者是性质规约。与计算机系统的其他建模方法一样,形式规约可以从不同的角度用不同/相同的形式规约语言来描述计算机系统,即所谓的多维视角规约方式,例如,一个计算机系统的需求方面的规约可包括数据模型规约、数据功能规约、交互通信协议规约等。Formal specification: also known as formal specification or formal description, is a computer system model strictly described by a formal specification language or the properties that a computer system needs to satisfy. The former is a model specification, and the latter is a property specification. Like other modeling methods of computer systems, formal specification can use different/same formal specification language to describe computer system from different angles, which is the so-called multi-dimensional perspective specification method.
形式规约语言:是指由严格的递归语法规则所定义的语言,具体包括模型规约语言、性质规约语言等。其中,模型规约语言利用数学结构描述系统的状态变化或者事件轨迹,它直接定义所描述系统模型的结构、功能行为甚至非功能行为;性质规约语言基于程序逻辑系统,通过逻辑公式来描述一组性质以定义所期望的系统行为,性质规约不直接定义系统的具体行为。Formal specification language: refers to a language defined by strict recursive grammar rules, including model specification language, property specification language, etc. Among them, the model specification language uses mathematical structure to describe the state change or event trajectory of the system, which directly defines the structure, functional behavior and even non-functional behavior of the described system model; the property specification language is based on the program logic system, and describes a set of properties through logical formulas to define the desired system behavior. The property specification does not directly define the specific behavior of the system.
中间表示(intermediate representation,IR):在编译领域,通常将编译器分为前端和后端,其中,前端会对输入的程序进行词法分析、语法分析、语义分析,然后生成中间表达形式,也就是中间表示,后端会对中间表示进行优化,然后生成目标代码。中间表示与源代码 在语义上是等价的,由于源代码通常包括各种注释,很不方便分析,在进行代码分析时,通常不会基于源代码直接分析,都会转换为中间表示后进行分析,这样得到的分析结果会比较准确。目前,比较常用的中间表示形式包括三地址码(three address code,缩写为TAC或3AC)、控制流程图(control flow graph,CFG)和静态单赋值(static single assignment,SSA),其中,SSA可以分为最小SSA、剪枝SSA、最大SSA等。Intermediate representation (IR): In the field of compilation, the compiler is usually divided into a front-end and a back-end. Among them, the front-end will perform lexical analysis, syntax analysis, and semantic analysis on the input program, and then generate an intermediate representation, which is the intermediate representation. The back-end will optimize the intermediate representation and then generate the object code. The intermediate representation and the source code are semantically equivalent. Because the source code usually includes various comments, it is very inconvenient to analyze. When performing code analysis, it is usually not directly analyzed based on the source code, but will be converted into an intermediate representation for analysis, so that the analysis results obtained will be more accurate. At present, the commonly used intermediate representations include three address code (three address code, abbreviated as TAC or 3AC), control flow graph (control flow graph, CFG) and static single assignment (static single assignment, SSA), among them, SSA can be divided into minimum SSA, pruned SSA, maximum SSA and so on.
结构化数据:指能够用数字或统一的数据模型加以描述的数据,具有严格的长度和格式。结构化数据相较于非结构化数据,具有易于存储、管理和处理等优点,且得到的处理结果通常也会更准确。Structured data: Refers to data that can be described by numbers or unified data models, with strict length and format. Compared with unstructured data, structured data has the advantages of easy storage, management and processing, and the processing results obtained are usually more accurate.
神经网络(neural networks):可以是由神经单元(也称为神经元)组成的,神经单元可以是指以变量x s和截距b为输入的运算单元,该运算单元的输出可以为: Neural networks (neural networks): It can be composed of neural units (also called neurons). A neural unit can refer to an operation unit that takes the variable x s and the intercept b as input, and the output of the operation unit can be:
Figure PCTCN2022139299-appb-000001
Figure PCTCN2022139299-appb-000001
其中,s=1、2、……n,n为大于1的自然数,W s为x s的权重,b为神经单元的偏置。f为神经单元的激活函数(activation functions),用于将非线性特性引入神经网络中,来将神经单元中的输入信号转换为输出信号。该激活函数的输出信号可以作为下一层卷积层的输入。激活函数可以是sigmoid函数以及其他函数,在此不做限定。神经网络是将许多个上述单一的神经单元联结在一起形成的网络,即一个神经单元的输出可以是另一个神经单元的输入。每个神经单元的输入可以与前一层的局部接受域相连,来提取局部接受域的特征,局部接受域可以是由若干个神经单元组成的区域。神经网络多种多样,常见的神经网络包括随机森林(random forest)、支持向量机(support vector machine,SVM)、图神经网络(graph neural networks,GNN)、卷积神经网络(convolutional neural networks,CNN)等。 Among them, s=1, 2, ... n, n is a natural number greater than 1, W s is the weight of x s , and b is the bias of the neuron unit. f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal in the neural unit into an output signal. The output signal of this activation function can be used as the input of the next convolutional layer. The activation function may be a sigmoid function or other functions, which are not limited here. A neural network is a network formed by connecting many of the above-mentioned single neural units, that is, the output of one neural unit can be the input of another neural unit. The input of each neural unit can be connected with the local receptive field of the previous layer to extract the features of the local receptive field. The local receptive field can be an area composed of several neural units. There are many kinds of neural networks. Common neural networks include random forest, support vector machine (SVM), graph neural networks (GNN), convolutional neural networks (CNN), etc.
模型训练:指对神经网络进行训练,得到训练好的能够用于完成特定任务的模型的过程。训练神经网络是指利用已有的数据通过一定方法使神经网络拟合已有数据的规律,从而确定神经网络中的参数。训练一个神经网络需要使用到数据集,根据数据集中的数据是否有标注(即:数据是否有特定的类型或名称),可以将神经网络的训练分为监督训练和无监督训练。Model training: refers to the process of training a neural network to obtain a trained model that can be used to complete a specific task. Training neural network refers to the use of existing data to make the neural network fit the law of the existing data through a certain method, so as to determine the parameters in the neural network. Training a neural network requires the use of a data set. According to whether the data in the data set is labeled (that is, whether the data has a specific type or name), the training of the neural network can be divided into supervised training and unsupervised training.
下面对本申请实施例涉及的应用场景进行简要说明。The following briefly describes the application scenarios involved in the embodiments of the present application.
计算机科学的发展主要涉及硬件和软件的发展,而软/硬件发展的核心问题之一是如何保证它们是可靠的、安全的。如今,硬件性能变得越来越高、运算速度变得越来越快、体系结构变得越来越复杂,软件的功能也变得越来越强大而复杂,如何开发可靠的计算机(软/硬件)系统,己经成为计算机科学发展的巨大挑战,特别是现在计算机系统己广泛应用于许多关系国计民生的安全系统中,例如高速列车控制系统、航空航天控制系统、核反应堆控制系统、医疗设备系统等等,这些系统中的任何错误都可能导致灾难性后果。The development of computer science mainly involves the development of hardware and software, and one of the core issues in the development of software/hardware is how to ensure that they are reliable and safe. Nowadays, the hardware performance is getting higher and higher, the computing speed is getting faster and faster, the system structure is becoming more and more complex, and the function of software is becoming more and more powerful and complex. How to develop a reliable computer (software/hardware) system has become a huge challenge for the development of computer science, especially now that computer systems have been widely used in many safety systems related to the national economy and people's livelihood, such as high-speed train control systems, aerospace control systems, nuclear reactor control systems, medical equipment systems, etc. Any error in these systems may lead to catastrophic consequences.
在实际应用中,通常会基于形式化方法设计开发一个可靠、安全的计算机系统。在基于形式化方法设计开发计算机系统时,通常需要开发人员在终端设备上手动编写大量的形式规约,如图1所示。具体实现中,开发人员所使用的终端设备可以是个人电脑、平板电脑、移动笔记本等等具有形式规约编写功能的电子设备,图1以终端设备100为个人电脑为例进行说明,但是本申请不对此进行具体限定。In practical applications, a reliable and secure computer system is usually designed and developed based on formal methods. When designing and developing computer systems based on formal methods, developers usually need to manually write a large number of formal specifications on terminal devices, as shown in Figure 1. In a specific implementation, the terminal device used by the developer may be a personal computer, a tablet computer, a mobile notebook, etc., which have the function of writing a formal specification. FIG. 1 illustrates that the terminal device 100 is a personal computer as an example, but this application does not specifically limit it.
上述由开发人员手动编写形式规约的方式,存在着需要消耗大量的人力和时间,会导致形式规约的获取效率以及计算机系统开发效率较低的问题。The above-mentioned method of manually writing the formal specification by the developer consumes a lot of manpower and time, which will lead to the problems of low efficiency of obtaining the formal specification and low efficiency of computer system development.
为了解决上述问题,本申请提供形式规约推荐方法、装置以及系统,能够在用户(即上述开发人员)手动编写待形式规约验证的代码和/或形式规约的过程中,自动基于用户已经输入的代码和/或代码的注释,得到多个候选形式规约,并将得到的多个候选形式规约显示给用 户,该多个候选形式规约可以给用户提供良好的参考,若用户确定多个候选形式规约中有满足自己需求的候选形式规约,则用户可直接选择该候选形式规约作为目标形式规约,并使用选择出目标形式规约对待验证代码进行验证,用户无需进行整个形式规约的编写工作,能够节省用户的精力和时间,而且能够提高形式规约的获取效率以及计算机系统的开发效率。In order to solve the above problems, the present application provides a formal specification recommendation method, device and system, which can automatically obtain multiple candidate formal specifications based on the code and/or code comments that the user has input during the process of manually writing the code and/or formal specification to be verified by the user (that is, the above-mentioned developer), and display the obtained multiple candidate formal specifications to the user. The multiple candidate formal specifications can provide good reference for the user. The specification is used as the target form specification, and the selected target form specification is used to verify the code to be verified. The user does not need to write the entire form specification, which can save the user's energy and time, and can improve the acquisition efficiency of the form specification and the development efficiency of the computer system.
为了便于更清楚地理解本申请提供的形式规约推荐方法、装置以及系统,下面结合对应的附图分别进行详细介绍。In order to facilitate a clearer understanding of the formal specification recommendation method, device, and system provided in this application, detailed descriptions will be made below in conjunction with the corresponding drawings.
首先,请参见图2,图2是本申请提供的一种形式规约推荐系统的结构示意图,该系统可包括终端设备100以及服务器300,并且,终端设备100以及服务器300通过网络200连接,网络200可以是广域网、局域网、点对点连接等方式,或它们的任意组合。First, please refer to Fig. 2, Fig. 2 is a schematic structural diagram of a formal specification recommendation system provided by the present application, the system may include a terminal device 100 and a server 300, and the terminal device 100 and the server 300 are connected through a network 200, and the network 200 may be a wide area network, a local area network, a point-to-point connection, etc., or any combination thereof.
服务器300可以为用户提供共享资源服务,共享资源服务可以包括形式规约推荐服务、对象存储服务(object storage service,OBS)、云备份服务(cloud backup and recovery,CBR)、数据管理服务(data admin service,DAS)等等,本申请不对服务器300可提供的共享资源服务类型进行限定。The server 300 can provide users with shared resource services, and the shared resource services can include format specification recommendation services, object storage services (object storage service, OBS), cloud backup services (cloud backup and recovery, CBR), data management services (data admin service, DAS), etc. This application does not limit the types of shared resource services that the server 300 can provide.
示例性地,服务器300可包括多个形式规约推荐节点,每个形式规约推荐节点具体包括硬件、虚拟化服务以及规约推荐服务端应用。Exemplarily, the server 300 may include a plurality of protocol recommendation nodes, and each protocol recommendation node specifically includes hardware, a virtualization service, and a protocol recommendation server application.
硬件包括计算资源、存储资源以及网络资源。计算资源可以采用异构计算架构,例如,可以采用中央处理器(central processing unit,CPU)+图形处理器(graphics processing unit,GPU)架构,CPU+AI芯片,CPU+GPU+AI芯片架构等等,此处不作具体限定。存储资源可以包括内存等等。这里,计算资源可以被分成多个计算单位资源,存储资源可以被分成多个存储单位资源,网络资源可以被分成多个网络单位资源。因此,图像处理平台可以按照用户的资源需求以单位资源为基础进行自由组合,从而用户的需要提供资源。例如,计算资源可以被分成5u的计算单位资源,存储资源可以被分成10G的存储单位资源,则计算资源和存储资源的组合可以是,5u+10G,5u+20G,5u+30u,…,10u+10G,10u+20G,10u+30u,…。Hardware includes computing resources, storage resources, and network resources. Computing resources can adopt heterogeneous computing architectures, for example, central processing unit (central processing unit, CPU) + graphics processing unit (graphics processing unit, GPU) architecture, CPU+AI chip, CPU+GPU+AI chip architecture, etc., are not specifically limited here. Storage resources may include memory, among others. Here, computing resources may be divided into multiple computing unit resources, storage resources may be divided into multiple storage unit resources, and network resources may be divided into multiple network unit resources. Therefore, the image processing platform can be freely combined on the basis of unit resources according to the user's resource requirements, so as to provide resources according to the user's needs. For example, computing resources can be divided into computing unit resources of 5u, and storage resources can be divided into storage unit resources of 10G, then the combination of computing resources and storage resources can be, 5u+10G, 5u+20G, 5u+30u,..., 10u+10G, 10u+20G, 10u+30u,....
虚拟化服务是通过虚拟化技术将多个物理主机的资源构建为统一的资源池,并按照用户的需要灵活地隔离出相互独立的资源以运行用户的应用代码的服务。虚拟化服务可以包括虚拟机(virtual machine,VM)服务、裸金属服务器(bare metal server,BMS)服务以及容器(container)服务。其中,VM服务可以是通过虚拟化技术在多个物理主机上虚拟出虚拟机(virtual machine,VM)资源池以为用户按需提供VM进行使用的服务。BMS服务是在多个物理主机上虚拟出BMS资源池以为用户按需提供BMS进行使用的服务。容器服务是在多个物理主机上虚拟出容器资源池以为用户按需提供容器进行使用的服务。VM是模拟出来的一台虚拟的计算机,也即逻辑上的一台计算机。BMS是一种可弹性伸缩的高性能计算服务,计算性能与传统物理机无差别,具有安全物理隔离的特点。容器是一种内核虚拟化技术,可以提供轻量级的虚拟化,以达到隔离用户空间、进程和资源的目的。应理解,上述虚拟化服务中的VM服务、BMS服务以及容器服务仅仅是作为具体的事例,在实际应用中,虚拟化服务还可以其他轻量级或者重量级的虚拟化服务,此处不作具体限定。Virtualization service is a service that builds the resources of multiple physical hosts into a unified resource pool through virtualization technology, and flexibly isolates mutually independent resources according to user needs to run user application codes. The virtualization service may include a virtual machine (virtual machine, VM) service, a bare metal server (bare metal server, BMS) service, and a container (container) service. Wherein, the VM service may be a service in which virtual machine (virtual machine, VM) resource pools are virtualized on multiple physical hosts through a virtualization technology to provide VMs for users on demand. BMS service is a service that virtualizes BMS resource pools on multiple physical hosts to provide users with BMS on demand. Container Service is a service that virtualizes container resource pools on multiple physical hosts to provide users with containers on demand. VM is a simulated virtual computer, that is, a logical computer. BMS is an elastically scalable high-performance computing service. Its computing performance is the same as that of traditional physical machines, and it has the characteristics of safe physical isolation. Container is a kernel virtualization technology that can provide lightweight virtualization to achieve the purpose of isolating user space, processes and resources. It should be understood that the VM service, BMS service, and container service in the above virtualization services are only specific examples. In practical applications, the virtualization service may also be other lightweight or heavyweight virtualization services, which are not specifically limited here.
规约推荐服务端应用,可以用于当用户在终端设备100上手动编写待形式规约验证的代码和/或形式规约时,接收终端设备100发送的用户输入的代码和/或代码的注释,然后基于用户输入的代码和/或代码的注释自动得到多个候选形式规约,并将得到生成的多个候选形式规约返回至终端设备100,由终端设备100显示给用户。用户在查看到多个候选形式规约时,可以根据自身的需求从多个候选形式规约中选择出目标形式规约。The protocol recommendation server application can be used to receive the user-input code and/or code comments sent by the terminal device 100 when the user manually writes the code and/or the formal specification to be verified on the terminal device 100, and then automatically obtain a plurality of candidate formal specifications based on the user-input code and/or code annotations, and return the generated multiple candidate formal specifications to the terminal device 100, and be displayed to the user by the terminal device 100. When the user views multiple candidate formal specifications, he can select the target formal specification from the multiple candidate formal specifications according to his own needs.
具体实现中,服务器300可以向用户提供接口,规约推荐服务端应用可以通过该接口接 收终端设备100发送的用户输入的代码和/或代码的注释,规约推荐服务端在得到多个候选形式规约后,可通过该接口将多个候选形式规约发送给终端设备100。具体地,接口可以是服务器300的控制台(console)或者应用程序接口(application program interface,API),控制台具体可以是用户与服务器300进行交互的一个应用程序或者网页页面,应理解,上述举例用于说明,本申请不作具体限定。In a specific implementation, the server 300 can provide an interface to the user, and the protocol recommendation server application can receive the code and/or code comments sent by the terminal device 100 through the interface, and the protocol recommendation server can send the multiple candidate format protocols to the terminal device 100 through the interface after obtaining multiple candidate format protocols. Specifically, the interface may be a console (console) or an application program interface (application program interface, API) of the server 300, and the console may specifically be an application program or a web page for the user to interact with the server 300. It should be understood that the above examples are for illustration, and the present application does not make specific limitations.
接下来,结合图3所示的本申请提供的一种形式规约推荐方法的交互示意图,对图2所示的形式规约推荐系统实现形式规约推荐的过程,进行更加详细地描述。如图3所示,本申请提供的形式规约推荐方法可包括如下步骤:Next, with reference to the interactive schematic diagram of a form specification recommendation method provided by the present application shown in FIG. 3 , the process of implementing form specification recommendation by the form specification recommendation system shown in FIG. 2 is described in more detail. As shown in Figure 3, the formal specification recommendation method provided by this application may include the following steps:
S301:终端设备100实时监测用户进行的代码编写操作。S301: The terminal device 100 monitors the code writing operation performed by the user in real time.
其中,用户进行代码编写操作编写的代码可以为待形式规约验证的代码和/或形式规约,具体实现中,用户可以使用任何编程语言(如java、C、C++等)编写待形式规约验证的代码,可以使用任何形式规约语言(如模型规约语言、性质规约语言)编写形式规约,用户编写的待形式规约验证的代码可以为游戏应用程序对应的代码,也可以是视频播放应用程序等其他应用程序对应的代码,还可以是用于实现某种特定功能(例如显示时间或者计算跑步公里数等)的代码,用户编写的形式规约可以为数据模型规约、数据功能规约或者交互通信协议规约等,此处均不作具体限定。Among them, the code written by the user in the code writing operation can be the code and/or the formal specification to be verified by the formal specification. In the specific implementation, the user can use any programming language (such as java, C, C++, etc.) For example, codes for displaying time or calculating running kilometers, etc.), the formal specification written by the user may be a data model specification, a data function specification, or an interactive communication protocol specification, etc., which are not specifically limited here.
可以理解,无论用户是在编写待形式规约验证的代码,还是在编写形式规约,用户在进行编写的过程中,均需要逐个字符进行输入,且用户在输入字符的过程中,还可以对输入的字符进行修改,从而得到最终的待形式规约验证的代码或者形式规约。It can be understood that no matter whether the user is writing the code to be verified by the formal specification or writing the formal specification, the user needs to input characters one by one during the writing process, and the user can also modify the input characters during the process of inputting characters, so as to obtain the final code or formal specification to be verified by the formal specification.
S302:终端设备100获取用户输入的代码和/或代码的注释。S302: The terminal device 100 acquires the code and/or the comment of the code input by the user.
其中,代码指用户在编写得到待形式规约验证的代码和/或形式规约的过程中,已经输入的字符。Wherein, the code refers to the characters that the user has input during the process of writing the code to be verified by the formal specification and/or the formal specification.
如图4A和图4B所示的示例性图形用户界面,图4A所显示的代码为用户想要得到的完整、正确的形式规约,图4B所显示的代码“amount”为用户在编写图4A所示的形式规约时,已经输入的代码。The exemplary graphical user interface shown in Figure 4A and Figure 4B, the code shown in Figure 4A is the complete and correct form specification that the user wants to obtain, and the code "amount" shown in Figure 4B is the code that the user has entered when writing the form specification shown in Figure 4A.
S303:终端设备100向服务器300发送用户输入的代码和/或代码的注释。S303: The terminal device 100 sends the code and/or the comment of the code input by the user to the server 300 .
S304:服务器300基于终端设备100发送的代码和/或代码的注释,得到多个候选形式规约。S304: The server 300 obtains a plurality of candidate form specifications based on the code and/or the comment of the code sent by the terminal device 100.
接下来,以基于代码得到多个候选形式规约为例,对基于代码和/或代码的注释,得到多个候选形式规约的过程进行详细描述。Next, the process of obtaining multiple candidate formal specifications based on codes and/or code annotations is described in detail by taking the example of obtaining multiple candidate formal specifications based on codes.
在本申请具体的实施例中,服务器300可以参考如下方式中的一种或者多种组合实现基于代码得到多个候选形式规约:In a specific embodiment of the present application, the server 300 can refer to one or more combinations of the following methods to obtain multiple candidate form specifications based on the code:
方式1,服务器300中可以预先存储规则库,该规则库中的多条规则对应多个形式规约。当服务器300接收到终端设备100发送的代码时,服务器300可以获取该代码与规则库包括的多条规则之间的匹配度,然后将多条规则中匹配度大于第一匹配度阈值的规则对应的形式规约,作为候选形式规约。 Mode 1, the server 300 may pre-store a rule base, and multiple rules in the rule base correspond to multiple formal specifications. When the server 300 receives the code sent by the terminal device 100, the server 300 may acquire the degree of matching between the code and the multiple rules included in the rule base, and then use the formal specification corresponding to the rule whose matching degree is greater than the first matching degree threshold among the multiple rules as a candidate formal specification.
具体实现中,多条规则与多个形式规约的对应关系可以为一一对应。第一匹配度阈值可以由用户根据实际情况进行自定义,例如,自定义为80%或者75%等,此处不作具体限定。In a specific implementation, the correspondence between multiple rules and multiple formal specifications may be a one-to-one correspondence. The first matching degree threshold can be customized by the user according to the actual situation, for example, 80% or 75%, etc., which is not specifically limited here.
举例来讲,假设用户输入的代码为代码1,规则库包括规则A~规则E,其中,规则A对应形式规约a,规则B对应形式规约b,规则C对应形式规约c,规则D对应形式规约d,规则E对应形式规约e,第一匹配度阈值为50%,计算得到的代码1与规则A~规则E的匹 配度对应为30%、55%、20%、65%、88%,则可将规则B对应的形式规约b、规则D对应的形式规约d和规则E对应的形式规约e确定为候选形式规约。For example, assuming that the code input by the user is code 1, the rule base includes rules A to rule E, where rule A corresponds to form a, rule B corresponds to form b, rule C corresponds to form c, rule D corresponds to form d, rule E corresponds to form e, and the first matching degree threshold is 50%. , the formal specification d corresponding to rule D and the formal specification e corresponding to rule E are determined as candidate formal specifications.
可选地,在计算得到代码与规则库包括的多条规则之间的匹配度之后,也可以根据计算结果对多条规则进行排序,然后将多条规则中匹配度较大的部分规则对应的形式规约,作为候选形式规约。具体实现中,可以根据实际情况自定义选择出的候选形式规约的数量,例如,自定义为5或者10,此处不作具体限定。Optionally, after calculating the matching degree between the code and the multiple rules included in the rule base, the multiple rules may also be sorted according to the calculation result, and then the form specification corresponding to the part of the multiple rules with a higher matching degree is used as a candidate form specification. In a specific implementation, the number of selected candidate form specifications can be customized according to the actual situation, for example, 5 or 10 can be customized, which is not specifically limited here.
继续以用户输入的代码为代码1,规则库包括规则A~规则E,其中,规则A对应形式规约a,规则B对应形式规约b,规则C对应形式规约c,规则D对应形式规约d,规则E对应形式规约e,匹配度阈值为50%,计算得到的代码1与规则A~规则E的匹配度对应为30%、55%、20%、65%、88%为例,假设自定义的候选形式规约的数量为2,则按照匹配度对规则A~规则E进行排序可以得到多条规则的顺序为:规则E、规则D、规则B、规则A、规则C,因而可以得到两条候选形式规约:规则D对应的形式规约d和规则E对应的形式规约e。Continuing to use the code input by the user as code 1, the rule base includes rules A to rule E, where rule A corresponds to form a, rule B corresponds to form b, rule C corresponds to form c, rule D corresponds to form d, rule E corresponds to form e, and the matching degree threshold is 50%. By sorting rules A to E, the order of multiple rules can be obtained: rule E, rule D, rule B, rule A, and rule C, so two candidate formal specifications can be obtained: formal specification d corresponding to rule D and formal specification e corresponding to rule E.
具体实现中,多条规则以及多条规则对应的形式规约可为专门的规则设计人员预先根据多种应用场景得到,如此,将规则库中与代码匹配度大于第一匹配度阈值的规则对应的形式规约确定为候选形式规约,或者将匹配度较大的部分规则对应的形式规约确定为候选形式规约,均可以保证确定的候选形式规约的准确性。In specific implementation, multiple rules and the formal specifications corresponding to the multiple rules can be obtained in advance by specialized rule designers according to various application scenarios. In this way, the formal specifications corresponding to the rules in the rule base whose code matching degree is greater than the first matching degree threshold are determined as candidate formal specifications, or the formal specifications corresponding to some rules with a relatively high matching degree are determined as candidate formal specifications, which can ensure the accuracy of the determined candidate formal specifications.
方式2,服务器300在接收到终端设备100发送的代码时,将代码输入提前训练好的识别精度较高的形式规约生成模型进行识别,然后将形式规约生成模型输出的形式规约作为候选形式规约。其中,形式规约生成模型可以使用包括大量已知代码的样本集训练得到。Method 2: When the server 300 receives the code sent by the terminal device 100, it inputs the code into a pre-trained formal specification generation model with high recognition accuracy for recognition, and then uses the formal specification output by the formal specification generation model as a candidate formal specification. Among them, the formal specification generation model can be trained using a sample set including a large number of known codes.
在具体实现中,服务器300在将代码输入到形式规约生成模型之后,形式规约生成模型可以得到多个形式规约以及多个形式规约的置信度,形式规约生成模型可以将多个形式规约中置信度大于置信度阈值的形式规约直接作为候选形式规约输出,也可以按照置信度大小进行排序,将置信度较大的部分形式规约作为候选形式规约输出,此处不作具体限定。置信度阈值、输出的候选形式规约的数量均可以由用户根据实际情况进行自定义,此处不作具体限定。In a specific implementation, after the server 300 inputs the code into the formal specification generation model, the formal specification generation model can obtain multiple formal specifications and the confidences of the multiple formal specifications. The formal specification generation model can directly output the formal specifications with a confidence greater than the confidence threshold among the multiple formal specifications as candidate formal specifications, or sort them according to the degree of confidence, and output some formal specifications with higher confidence as candidate formal specifications, which are not specifically limited here. Both the confidence threshold and the number of output candidate form reductions can be customized by the user according to the actual situation, and are not specifically limited here.
在本申请具体的实施例中,形式规约生成模型可以表示为:In the specific embodiment of this application, the formal specification generation model can be expressed as:
y=f(x)y=f(x)
其中,y为形式规约,x为代码,f()为代码与形式规约之间的映射关系。Among them, y is the formal specification, x is the code, and f() is the mapping relationship between the code and the formal specification.
下面详细介绍形式规约生成模型的训练过程。The training process of the formal reduction generative model is described in detail below.
具体实现中,可以使用包括大量已知代码的样本集对机器学习模型进行训练得到形式规约生成模型。其中,样本集包括的大量已知代码,可以是用户手动编写的,也可以是从互联网上获取的,此处不作具体限定;机器学习模型可包括但不限于决策树、支持向量机、深度学习等等,深度学习模型可采用从自然语言处理生成代码的常用模型,例如基于转换器的双向编码表征(bidirectional encoder representations from transformers,简称BERT)、Seq2Seq、transformer等,本申请不作具体限定;使用样本集对机器学习模型进行训练得到形式规约生成模型的方式可以为监督训练,也可以为无监督训练,本申请不作具体限定。In a specific implementation, a machine learning model can be trained using a sample set including a large number of known codes to obtain a formal specification generation model. Among them, a large number of known codes included in the sample set can be manually written by the user or obtained from the Internet, which is not specifically limited here; machine learning models can include but are not limited to decision trees, support vector machines, deep learning, etc., deep learning models can use common models that generate codes from natural language processing, such as bidirectional encoder representations from transformers based on transformers (BERT for short), Seq2Seq, transformers, etc., which are not specifically limited in this application; The manner in which the sample set is used to train the machine learning model to obtain the form reduction model can be supervised training or unsupervised training, which is not specifically limited in this application.
以使用样本集对机器学习模型进行监督训练得到形式规约生成模型为例,当训练方式为监督训练时,样本集中包括的大量已知代码可以作为输入数据样本,除此之外,样本集中还可以包括大量已知代码中每个代码对应的已知形式规约,大量已知形式规约可以作为输出数据样本,大量已知形式规约可以是用户手动编写的,也可以是从互联网上获取的,此处不作具体限定。Take the example of using a sample set to perform supervised training on a machine learning model to obtain a formal specification generation model. When the training method is supervised training, a large number of known codes included in the sample set can be used as input data samples. In addition, the sample set can also include known formal specifications corresponding to each code in a large number of known codes. A large number of known formal specifications can be used as output data samples. A large number of known formal specifications can be manually written by users or obtained from the Internet. No specific restrictions are made here.
具体地,可以将大量已知代码中第i个已知代码作为输入数据样本S i,将第i个已知代码对应的已知形式规约作为输出数据样本s i。可以理解,通过上述组合,可以得到大量输入数据样本以及大量输出数据样本,且大量输入数据样本与大量输出数据样本之间存在一一对应关系。 Specifically, the i-th known code among a large number of known codes can be used as an input data sample S i , and the known form specification corresponding to the i-th known code can be used as an output data sample s i . It can be understood that through the above combination, a large number of input data samples and a large number of output data samples can be obtained, and there is a one-to-one correspondence between the large number of input data samples and the large number of output data samples.
在得到大量输入数据样本和大量输出数据样本之后,可以将大量输入数据样本依次作为机器学习模型的输入,并将每个输入数据样本对应的输出数据样本作为机器学习模型的输出值的参考,利用损失函数计算机器学习模型的输出值与上述数据输出样本之间的损失值,然后根据损失值调整机器学习模型的参数。在具体实现中,可以利用上述大量输入数据样本和大量输出数据样本迭代地对机器学习模型进行训练,不断调整机器学习模型的参数,直至机器学习模型可以根据输入的输入数据样本准确地输出与该输入数据样本对应的输出数据样本相同的输出值,从而得到训练好的形式规约生成模型。After obtaining a large number of input data samples and a large number of output data samples, a large number of input data samples can be used as the input of the machine learning model in turn, and the output data samples corresponding to each input data sample can be used as a reference for the output value of the machine learning model, and the loss function is used to calculate the loss value between the output value of the machine learning model and the above data output samples, and then adjust the parameters of the machine learning model according to the loss value. In a specific implementation, the machine learning model can be iteratively trained by using the above-mentioned large number of input data samples and a large number of output data samples, and the parameters of the machine learning model can be continuously adjusted until the machine learning model can accurately output the same output value as the output data sample corresponding to the input data sample according to the input data sample, so as to obtain a trained formal specification generation model.
方式3,服务器300中可以预先存储有大量代码和大量形式规约的一一对应关系,其中,每个形式规约用于对其对应的代码进行验证。当服务器300接收到终端设备100发送的代码时,服务器300可以获取该代码与预先存储的大量代码之间的匹配度,然后将大量代码中匹配度大于第二匹配度阈值的代码对应的形式规约,作为候选形式规约。其中,第二匹配度阈值可以由用户根据实际情况进行自定义,例如,自定义为80%或者75%等,此处不作具体限定。Mode 3, the server 300 may pre-store a one-to-one correspondence between a large number of codes and a large number of formal specifications, wherein each formal specification is used to verify its corresponding code. When the server 300 receives the code sent by the terminal device 100, the server 300 may obtain the degree of matching between the code and a large number of pre-stored codes, and then use the formal specification corresponding to the code whose matching degree is greater than the second matching degree threshold among the large number of codes as a candidate form specification. Wherein, the second matching degree threshold can be customized by the user according to the actual situation, for example, 80% or 75% can be customized, which is not specifically limited here.
应理解,基于代码的注释得到候选形式规约的过程以及基于代码和代码的注释得到候选形式规约的过程,均与上述基于代码得到候选形式规约的过程相类似,具体可以参考上文相关描述,为了说明书的简洁,此处不再展开赘述。It should be understood that the process of obtaining candidate formal specifications based on code comments and the process of obtaining candidate formal specifications based on codes and code comments are similar to the above-mentioned process of obtaining candidate formal specifications based on codes. For details, please refer to the relevant description above. For the sake of brevity, details will not be repeated here.
应理解,上述所列举的几种得到候选形式规约的实现方式仅仅是作为示例,在具体实现中,其他能够实现基于代码和/或代码的注释得到候选形式规约的方式,也属于本申请的保护范围,例如,结合规则匹配以及模型识别两种方式共同得到候选形式规约,或者利用最弱前置条件(weakest precondition)生成技术得到候选形式规约,本申请对此不作具体限定。It should be understood that the above-listed implementation methods for obtaining candidate formal specifications are only examples. In specific implementations, other methods that can obtain candidate formal specifications based on code and/or code comments also belong to the scope of protection of this application.
S305:服务器300将多个候选形式规约发送给终端设备100。S305: The server 300 sends multiple candidate form protocols to the terminal device 100.
在一种可能的实施例中,服务器300向终端设备100发送的可以是排序后的多个候选形式规约,其中,多个候选形式规约中与代码和/或代码的注释匹配最优的候选形式规约排列在首位,便于用户方便快捷地从多个候选形式规约中查看到最优候选形式规约,优化用户体验。In a possible embodiment, what the server 300 sends to the terminal device 100 may be a plurality of sorted candidate form specifications, wherein among the multiple candidate form specifications, the candidate form specification that best matches the code and/or code comments is ranked first, so that the user can conveniently and quickly view the optimal candidate form specification from the multiple candidate form specifications, and optimize user experience.
可选地,服务器300在对多个候选形式规约进行排序后,也可以仅向终端设备100发送多个候选形式规约中与代码和/或代码的注释匹配最优的候选形式规约,或者仅向终端设备100发送多个候选形式规约中排序比较靠前的部分候选形式规约,此处不作具体限定。Optionally, after sorting the multiple candidate form specifications, the server 300 may also send to the terminal device 100 only the candidate form specification that best matches the code and/or the comment of the code among the multiple candidate form specifications, or only send to the terminal device 100 a part of the candidate form specifications that are ranked higher among the multiple candidate form specifications, which is not specifically limited here.
在本申请具体的实施例中,服务器300可以参考如下方式中的任意一种实现对多个候选形式规约进行排序:In a specific embodiment of the present application, the server 300 can refer to any one of the following ways to sort multiple candidate form specifications:
方式1',在多个候选形式规约是采用上述步骤S304中的方式1得到的情况下,可以基于多个候选形式规约对应的规则与代码和/或代码的注释之间的匹配度,对多个候选形式规约进行排序。Mode 1', in the case that multiple candidate formal specifications are obtained by adopting the above method 1 in step S304, the multiple candidate formal specifications can be sorted based on the degree of matching between the rules corresponding to the multiple candidate formal specifications and the code and/or code comments.
例如,可以按照匹配度从大到小对多个候选形式规约进行排序,并将对应匹配度最大的候选形式规约确定为最优候选形式规约排列在首位。For example, multiple candidate form specifications may be sorted in descending order of matching degree, and the candidate form specification corresponding to the highest matching degree is determined to be the optimal candidate form specification and arranged first.
方式2',在多个候选形式规约是采用上述步骤S304中的方式2得到的情况下,可以基于多个候选形式规约对应的置信度,对多个候选形式规约进行排序。Mode 2', in the case that multiple candidate formal specifications are obtained by adopting the above-mentioned mode 2 in step S304, the multiple candidate formal specifications may be sorted based on the confidence levels corresponding to the multiple candidate formal specifications.
例如,可以按照置信度从大到小对多个候选形式规约进行排序,并将对应置信度最大的 候选形式规约确定为最优候选形式规约排列在首位。For example, multiple candidate form specifications can be sorted in descending order of confidence, and the candidate form specification with the highest corresponding confidence is determined to be the best candidate form specification and arranged first.
方式3',在多个候选形式规约是采用上述步骤S304中的方式3得到的情况下,可以基于多个候选形式规约对应的服务器300预先存储的代码和/或代码的注释与服务器300接收到的终端设备100发送的代码和/或代码的注释之间的匹配度,对多个候选形式规约进行排序。Mode 3', in the case that multiple candidate form protocols are obtained by adopting mode 3 in the above step S304, the multiple candidate form protocols can be sorted based on the degree of matching between the codes and/or code annotations pre-stored by the server 300 corresponding to the multiple candidate format protocols and the codes and/or code annotations received by the server 300 and sent by the terminal device 100.
应理解,上述所列举的几种实现候选形式规约排序的方式仅仅是作为示例,其他能够实现候选形式规约的排序的方式也属于本申请的保护范围,本申请对此不作具体限定。It should be understood that the above-listed several ways to implement the sorting of the candidate form protocols are only examples, and other ways that can implement the sorting of the candidate form protocols also belong to the protection scope of the present application, which is not specifically limited in the present application.
可选地,服务器300在向终端设备100发送多个候选形式规约时,可以将多个候选形式规约对应的匹配度或者置信度一并发送给终端设备100。Optionally, when the server 300 sends multiple candidate form specifications to the terminal device 100 , it may also send the matching degrees or confidence levels corresponding to the multiple candidate form specifications to the terminal device 100 .
S306:终端设备100向用户显示多个候选形式规约。S306: The terminal device 100 displays multiple candidate form specifications to the user.
终端设备100向用户显示的多个候选形式规约可以是排序后的多个候选形式规约。若终端设备100还接收到了服务器300发送的多个候选形式规约对应的匹配度或者置信度,则终端设备100在向用户显示多个候选形式规约时,可以将多个候选形式规约对应的匹配度或者置信度一并显示给用户,如此,便于用户方便快捷地从多个候选形式规约中查看到最优候选形式规约,优化用户体验。The multiple candidate form specifications displayed to the user by the terminal device 100 may be the multiple candidate form specifications after sorting. If the terminal device 100 also receives the matching degrees or confidence levels corresponding to the multiple candidate form specifications sent by the server 300, when the terminal device 100 displays the multiple candidate form specifications to the user, it may display the matching degrees or confidence levels corresponding to the multiple candidate form specifications to the user. In this way, it is convenient for the user to quickly and conveniently view the optimal candidate form specification from the multiple candidate form specifications, and optimize user experience.
S307:终端设备100获取用户从多个候选形式规约中选择出的目标形式规约。S307: The terminal device 100 acquires a target format protocol selected by the user from multiple candidate format protocols.
S308:终端设备100使用目标形式规约对待验证代码进行验证。S308: The terminal device 100 uses the target form protocol to verify the code to be verified.
由上文对中间表示和结构化数据的介绍可知,代码对应的中间表示相较于代码本身,更便于分析,且得到的分析结果通常也会更准确,结构化数据相较于非结构化数据,更易于存储、管理和处理,因此,在本申请具体的实施例中,图2所示的形式规约推荐系统也可以参考图5所示的交互示意图实现形式规约推荐:From the above introduction to intermediate representation and structured data, it can be seen that the intermediate representation corresponding to the code is easier to analyze than the code itself, and the analysis results obtained are usually more accurate. Compared with unstructured data, structured data is easier to store, manage and process. Therefore, in the specific embodiment of this application, the formal protocol recommendation system shown in Figure 2 can also refer to the interactive schematic diagram shown in Figure 5 to implement the formal protocol recommendation:
S501:终端设备100实时监测用户进行的代码编写操作。S501: The terminal device 100 monitors the code writing operation performed by the user in real time.
S502:终端设备100获取用户输入的代码和/或代码的注释。S502: The terminal device 100 acquires the code and/or the comment of the code input by the user.
S503:终端设备100向服务器300发送代码和/或代码的注释。S503: The terminal device 100 sends the code and/or the comment of the code to the server 300 .
S504:服务器300获取代码对应的中间表示和/或代码的结构化注释。S504: The server 300 acquires an intermediate representation corresponding to the code and/or a structured annotation of the code.
S505:服务器300基于代码对应的中间表示和/或代码的结构化注释,得到多个候选形式规约。S505: The server 300 obtains multiple candidate form specifications based on the intermediate representation corresponding to the code and/or the structured annotation of the code.
S506:服务器300将多个候选形式规约发送给终端设备100。S506: The server 300 sends multiple candidate form protocols to the terminal device 100.
S507:终端设备100向用户显示多个候选形式规约。S507: The terminal device 100 displays multiple candidate form specifications to the user.
S508:终端设备100获取用户从多个候选形式规约中选择出的目标形式规约。S508: The terminal device 100 acquires a target format protocol selected by the user from multiple candidate format protocols.
S509:终端设备100使用目标形式规约对待验证代码进行验证。S509: The terminal device 100 uses the target form protocol to verify the code to be verified.
步骤S504的具体实现过程可以为:服务器300可以从编译器前端获取代码对应的中间表示,该中间表示的形式可以为三地址码、控制流程图或者静态单赋值等,此处不作具体限定;服务器300可以对代码的注释进行结构化处理,从而得到代码的结构化注释。可选地,服务器300在对代码的注释进行结构化处理时,还可以对注释进行清洗,如删除注释中包括的特殊符号,如“*”、“#”等,或者,对注释中包括的词的先后顺序进行调整等,此处不作具体限定。The specific implementation process of step S504 can be as follows: the server 300 can obtain the intermediate representation corresponding to the code from the front end of the compiler, and the form of the intermediate representation can be a three-address code, a control flow chart, or a static single assignment, etc., which are not specifically limited here; the server 300 can perform structural processing on the code comment, so as to obtain the structured comment of the code. Optionally, when the server 300 performs structural processing on the comments of the code, it can also clean the comments, such as deleting special symbols included in the comments, such as "*", "#", etc., or adjusting the order of the words included in the comments, etc., which are not specifically limited here.
可以看出,步骤S501、S502、S503、S506、S507、S508、S509与步骤S301、S302、S303、S305、S306、S307、S308对应相同,具体可以参考上文对步骤S301、S302、S303、S305、S306、S307、S308的相关描述,此处不再展开赘述。It can be seen that steps S501, S502, S503, S506, S507, S508, and S509 are the same as steps S301, S302, S303, S305, S306, S307, and S308. For details, please refer to the relevant descriptions of steps S301, S302, S303, S305, S306, S307, and S308 above. , will not be repeated here.
步骤S505的具体实现过程与上述步骤S304的具体实现过程相类似,可以参考上文对步骤S304的相关描述,此处不再展开赘述。The specific implementation process of step S505 is similar to the specific implementation process of the above-mentioned step S304, and reference may be made to the relevant description of the above-mentioned step S304, which will not be repeated here.
可选地,终端设备100在获取到用户输入的代码和/或代码的注释后,也可以基于代码和/或代码的注释直接获取代码对应的中间表示和/或代码的结构化注释,然后向服务器300发送代码对应的中间表示和/或代码的结构化注释。Optionally, after the terminal device 100 obtains the code and/or the annotation of the code input by the user, it may also directly obtain the intermediate representation corresponding to the code and/or the structured annotation of the code based on the code and/or the annotation of the code, and then send the intermediate representation corresponding to the code and/or the structured annotation of the code to the server 300.
可以理解,由于代码对应的中间表示相较于代码本身,更便于分析,且得到的分析结果通常也会更准确,代码的结构化注释相较于代码的注释(指结构化处理之前的注释),更易于处理,且得到的处理结果通常也会更准确,因此,上述基于代码对应的中间表示和/或代码的结构化注释,得到的多个候选形式规约,相较于基于代码和/或代码的注释,得到的多个候选形式规约,可以提高候选形式规约的准确度,能够使得最终向用户推荐的多个候选形式规约更精准。It can be understood that, compared with the code itself, the intermediate representation corresponding to the code is easier to analyze, and the obtained analysis results are usually more accurate. Compared with the comment of the code (referring to the comment before the structured processing), the structured comment of the code is easier to process, and the processing result obtained is usually more accurate. This makes the multiple candidate form specifications recommended to users more accurate.
在本申请具体的实施例中,终端设备100还可以通过关键词触发步骤S301或者S501的执行,具体地,终端设备100可以监测用户是否输入了关键词(如requires或者prey等),在监测到用户输入了关键词时,执行步骤S301或者S501。其中,用户输入的关键词所在的位置,为用户期望开始进行形式规约推荐的位置,如此可以使得应用本申请提供的形式规约推荐方法的设备(如图1所示终端设备100)或者系统(如图2所示形式规约推荐系统),仅监测用户在输入关键词之后进行的代码编写操作,不监测用户在输入关键词之前进行的代码编写操作,可以优化用户体验以及节省计算资源。In a specific embodiment of the present application, the terminal device 100 can also trigger the execution of step S301 or S501 through a keyword. Specifically, the terminal device 100 can monitor whether the user has input a keyword (such as requires or prey, etc.), and when it is detected that the user has input a keyword, execute step S301 or S501. Wherein, the position of the keyword input by the user is the position where the user expects to start the form specification recommendation, so that the device (terminal device 100 shown in FIG. 1 ) or system (the form specification recommendation system shown in FIG. 2 ) applying the form specification recommendation method provided by this application can only monitor the code writing operation performed by the user after inputting the keyword, and not monitor the code writing operation performed by the user before inputting the keyword, which can optimize user experience and save computing resources.
更具体地,终端设备100可以实时监测用户输入的内容,然后将用户输入的内容与关键词库中的多个关键词进行匹配,确定关键词库中是否存在与用户输入的内容匹配的关键词,在确定存在匹配的关键词的情况下,确定用户输入了关键词,反之,则确定用户没有输入关键词,继续监测用户输入的内容。More specifically, the terminal device 100 can monitor the content input by the user in real time, and then match the content input by the user with multiple keywords in the keyword database to determine whether there is a keyword matching the content input by the user in the keyword database.
可选地,终端设备100也可以接收用户输入的时间范围,该时间范围为用户会进行代码编写操作的时间范围,也是用户期望进行形式规约推荐的时间,如此可以使得应用本申请提供的形式规约推荐方法的设备或者系统,仅监测用户在该时间范围内进行的代码编写操作,基于该时间范围内的代码编写操作进行形式规约推荐,不监测用户在该时间范围外进行的代码编写操作,可以优化用户体验以及节省计算资源。Optionally, the terminal device 100 may also receive a time range input by the user. This time range is the time range in which the user will perform code writing operations and is also the time when the user expects to recommend form specifications. In this way, the device or system that applies the form specification recommendation method provided by this application can only monitor the code writing operations performed by the user within this time range, and perform form specification recommendations based on the code writing operations within this time range. It does not monitor the code writing operations performed by the user outside the time range, which can optimize user experience and save computing resources.
具体实现中,服务器300在向终端设备100发送多个候选形式规约之前,或者终端设备100在向用户显示多个候选形式规约之前,还可以对多个候选形式规约进行筛选,过滤掉一部分明显没有价值的规约,例如,过滤掉有明显错误(如语法错误或者语义错误等)的规约,如此,可以使得最终向用户推荐的多个候选形式规约更精准。In a specific implementation, before the server 300 sends the multiple candidate protocols to the terminal device 100, or before the terminal device 100 displays the multiple candidate protocols to the user, it may further screen the multiple candidate protocols to filter out some obviously worthless protocols, for example, filter out the protocols with obvious errors (such as grammatical errors or semantic errors, etc.), so that the multiple candidate protocols finally recommended to the user can be more accurate.
综上可知,本申请提供的形式规约推荐系统和形式规约推荐方法,可实时监测用户进行的代码编写操作,获取用户输入的代码和/或代码的注释,然后根据代码和/或代码的注释自动得到多个候选形式规约,最后将得到的多个候选形式规约推荐给用户,该多个候选形式规约可以给用户提供良好的参考,若用户确定多个候选形式规约中有满足自己需求的候选形式规约,则用户可直接选择该候选形式规约作为目标形式规约,并使用选择出的目标形式规约对待验证代码进行验证,用户无需进行整个形式规约的编写工作,能够节省用户的精力和时间,而且能够提高形式规约的获取效率以及计算机系统的开发的效率。In summary, the formal specification recommendation system and formal specification recommendation method provided by this application can monitor the code writing operation performed by the user in real time, obtain the code and/or code comments entered by the user, and then automatically obtain multiple candidate formal specifications according to the code and/or code comments, and finally recommend the obtained multiple candidate formal specifications to the user. , and use the selected target formal specification to verify the code to be verified, the user does not need to write the entire formal specification, which can save the user's energy and time, and can improve the efficiency of formal specification acquisition and computer system development.
为了便于理解本申请实施例所提供方案的有益效果,下面介绍上述步骤S301~S308以及步骤S501~S509的过程中,一些示例性的图形用户界面。请参见图6,图6是本申请提供的一种示例性图形用户界面600,由图6可知,界面600可包括代码输入区域610。In order to facilitate the understanding of the beneficial effects of the solution provided by the embodiment of the present application, some exemplary graphical user interfaces during the above steps S301-S308 and steps S501-S509 are introduced below. Please refer to FIG. 6 . FIG. 6 is an exemplary graphical user interface 600 provided by the present application. It can be seen from FIG. 6 that the interface 600 may include a code input area 610 .
其中,代码输入区域610可以为用户提供输入代码和代码的注释的接口,用户可在该区域输入关键词以及进行代码编写操作,比如图6中显示的“requires”,可为用户输入的关键词, “requires”所在行下方的代码和代码的注释,可为用户在代码输入区域610进行代码编写操作时输入的代码和代码的注释。Among them, the code input area 610 can provide the user with an interface for inputting codes and code comments. The user can input keywords and perform code writing operations in this area. For example, "requires" shown in FIG.
可选地,界面600还可以为用户提供“新增代码”控件620,如图6所示,用户触摸或者点击该控件后,可以上传已经编辑好的代码和/或代码的注释,并在代码输入区域610显示用户上传的代码和/或代码的注释。Optionally, the interface 600 can also provide the user with a "Add Code" control 620, as shown in FIG.
应用本申请提供的形式规约推荐方法的设备或者系统在监测到用户输入了关键词“requires”之后,可以执行上述步骤S301~S304或者执行上述步骤S501~S505,得到多个候选形式规约,并对多个候选形式规约进行排序后将排序结果显示给用户,如图6所示的规约推荐弹窗630,规约推荐弹窗630中显示的形式规约e、形式规约d、形式规约a和形式规约c,可为应用本申请提供的形式规约推荐方法的设备或者系统向用户推荐的排序后的候选形式规约。若用户确定弹窗630中有满足自己需求的候选形式规约,则可以点击该形式规约,如点击形式规约d,然后点击弹窗630中显示的“确定”控件6301,将点击的候选形式规约确定为目标形式规约。After the device or system applying the formal protocol recommendation method provided by this application detects that the user has input the keyword "requires", it can execute the above steps S301-S304 or execute the above-mentioned steps S501-S505 to obtain multiple candidate formal protocols, sort the multiple candidate formal protocols, and then display the sorting results to the user. The protocol recommendation pop-up window 630 shown in FIG. c, may be the sorted candidate formal specifications recommended to the user by a device or a system applying the formal specification recommendation method provided in this application. If the user determines that there is a candidate format specification that meets his needs in the pop-up window 630, he can click on the format specification, such as clicking on the format specification d, and then click on the "OK" control 6301 displayed in the pop-up window 630 to determine the clicked candidate format specification as the target format specification.
应理解,图6用于举例说明,本申请不作具体限定。It should be understood that FIG. 6 is used for illustration, and is not specifically limited in the present application.
根据图6所示的界面600可知,本申请提供的形式规约推荐方法,对于用户来说,在界面600所示的接口输入代码和/或代码的注释后,可在界面600所示的显示界面获得多个排序后的候选形式规约,该排序结果可以给用户提供良好的参考,若用户确定排序结果中有满足自己需求的候选形式规约,则用户可选择该规约作为目标形式规约,无需进行整个形式规约的编写工作,能够节省开发人员的精力和时间。According to the interface 600 shown in FIG. 6 , the method for recommending formal specifications provided by this application, for the user, after inputting code and/or code comments on the interface shown in interface 600, can obtain multiple sorted candidate formal specifications on the display interface shown in interface 600, and the sorting results can provide good reference for users. .
应理解,图3以及图5所示的本申请提供的形式规约推荐方法除了可以应用于图2所示的形式规约推荐系统之外,还可以应用于图1所示的终端设备100,即图3以及图5所示实施例中由服务器300执行的步骤均可以由终端设备100执行,如此,也可以实现推荐多个候选形式规约给用户,若用户确定多个候选形式规约中有满足自己需求的候选形式规约,则用户可直接选择该候选形式规约作为目标形式规约,并使用选择出的目标形式规约对待验证代码进行验证,用户无需进行整个形式规约的编写工作,能够节省用户的精力和时间,而且能够提高形式规约的获取效率以及计算机系统的开发的效率。It should be understood that the protocol recommendation method provided by the present application shown in FIG. 3 and FIG. 5 can be applied to the terminal device 100 shown in FIG. 1 in addition to the protocol recommendation system shown in FIG. 2 , that is, the steps performed by the server 300 in the embodiment shown in FIG. 3 and FIG. and using the selected target formal specification to verify the code to be verified, the user does not need to write the entire formal specification, which can save the user's energy and time, and can improve the efficiency of formal specification acquisition and computer system development.
接下来介绍本申请提供的形式规约推荐装置,该装置可以应用于图1所示的终端设备100,或者,应用于图2所示的形式规约推荐系统,在应用于图2所示的形式规约推荐系统时,可以应用于图2所示的服务器300。应理解,形式规约推荐装置内部的单元模块也可以有多种划分,各个模块可以是软件模块,也可以是硬件模块,也可以部分是软件模块部分是硬件模块,本申请不对其进行限制。当形式规约推荐装置应用于图2所示的服务器300,且形式规约推荐装置包括多个单元模块时,该多个单元模块中的各个模块可以部署于同一个服务器300上,也可以部署于不同的服务器300上,本申请不作具体限定。Next, the form specification recommendation device provided by this application is introduced. This device can be applied to the terminal device 100 shown in FIG. 1, or to the form specification recommendation system shown in FIG. 2, and can be applied to the server 300 shown in FIG. It should be understood that the unit modules inside the formal specification recommendation device can also be divided into multiple types. Each module can be a software module, or a hardware module, or partly a software module and partly a hardware module, which is not limited in this application. When the form specification recommendation device is applied to the server 300 shown in FIG. 2, and the form specification recommendation device includes a plurality of unit modules, each module in the plurality of unit modules can be deployed on the same server 300, or can be deployed on different servers 300, which is not specifically limited in this application.
参见图7,图7是本申请示例性示出的一种形式规约推荐装置700的结构示意图,该装置700包括:获取模块710和规约推荐模块720。Referring to FIG. 7 , FIG. 7 is a schematic structural diagram of an apparatus 700 for form protocol recommendation in this application. The apparatus 700 includes: an acquisition module 710 and a protocol recommendation module 720 .
获取模块710,用于获取用户输入的代码和/或代码的注释。Obtaining module 710, configured to obtain codes and/or comments of codes input by the user.
规约推荐模块720,用于基于用户输入的代码和/或代码的注释,得到多个候选形式规约,并向用户显示多个候选形式规约。The protocol recommending module 720 is configured to obtain multiple candidate formal specifications based on the code and/or code comments input by the user, and display the multiple candidate formal specifications to the user.
在一种可能的实现方式中,规约推荐模块720,具体可以通过如下方式实现基于用户输入的代码和/或代码的注释,得到多个候选形式规约:将代码和/或代码的注释,输入形式规约生成模型进行识别,将形式规约生成模型输出的形式规约作为候选形式规约。In a possible implementation, the protocol recommendation module 720 can specifically obtain multiple candidate formal specifications based on the code and/or code comments input by the user in the following manner: identify the code and/or code comments as input to the formal specification generation model, and use the formal specification output by the formal specification generation model as a candidate formal specification.
在一种可能的实现方式中,规约推荐模块720,具体可以通过如下方式实现基于用户输入的代码和/或代码的注释,得到多个候选形式规约:首先,获取代码和/或代码的注释与规则库包括的多条规则之间的匹配度,然后,将多条规则中匹配度大于匹配度阈值的规则对应的形式规约,作为候选形式规约。In a possible implementation, the protocol recommendation module 720 can specifically obtain multiple candidate formal specifications based on user-input code and/or code annotations in the following manner: first, obtain the matching degree between the code and/or code annotations and multiple rules included in the rule base, and then use the formal specification corresponding to the rule whose matching degree is greater than the matching degree threshold among the multiple rules as a candidate formal specification.
在一种可能的实现方式中,规约推荐模块720,具体可以通过如下方式实现基于用户输入的代码和/或代码的注释,得到多个候选形式规约:基于代码对应的中间表示和/或代码的结构化注释,生成多个候选形式规约,其中,上述代码的结构化注释是对代码的注释进行结构化处理得到的。In a possible implementation manner, the protocol recommending module 720 can specifically obtain multiple candidate formal specifications based on user-input codes and/or code annotations in the following manner: generate multiple candidate formal specifications based on the intermediate representation corresponding to the codes and/or code structured annotations, wherein the above-mentioned structured annotations of codes are obtained by performing structural processing on the code annotations.
在一种可能的实现方式中,获取模块710,具体可以通过如下方式实现获取用户输入的代码和/或代码的注释:通过关键词触发用户数输入的代码和/或代码的注释的获取。In a possible implementation manner, the acquiring module 710 may specifically acquire the code and/or comment of the code input by the user in the following manner: triggering acquisition of the code and/or comment of the code input by the user through keywords.
在一种可能的实现方式中,获取模块710,具体可以通过如下方式实现通过关键词触发用户数输入的代码和/或代码的注释的获取:监测用户是否输入了关键词,在监测到用户输入了关键词的情况下,获取用户输入的代码和/或代码的注释。上述关键词所在的位置,为用户期望开始进行形式规约推荐的位置,如此可以使得应用本申请提供的形式规约推荐方法的设备或者系统,仅监测用户在输入关键词之后进行的代码编写操作,不监测用户在输入关键词之前进行的代码编写操作,可以优化用户体验以及节省计算资源。In a possible implementation manner, the acquisition module 710 can specifically implement the acquisition of the code and/or code annotations entered by the user through keywords in the following manner: monitor whether the user has entered a keyword, and obtain the code and/or code annotations entered by the user when it is detected that the user has entered the keyword. The position of the above-mentioned keywords is the position where the user expects to start the form specification recommendation, so that the device or system that applies the form specification recommendation method provided by this application can only monitor the code writing operation performed by the user after inputting the keyword, and not monitor the code writing operation performed by the user before inputting the keyword, which can optimize user experience and save computing resources.
在一种可能的实现方式中,获取模块710,还可以通过如下方式实现获取用户输入的代码和/或代码的注释:接收用户输入的时间范围,该时间范围为用户会进行代码编写操作的时间范围,也是用户期望进行形式规约推荐的时间,如此可以使得应用本申请提供的形式规约推荐方法的设备或者系统,仅监测用户在该时间范围内进行的代码编写操作,基于该时间范围内的代码编写操作进行形式规约推荐,不监测用户在该时间范围外进行的代码编写操作,可以优化用户体验以及节省计算资源。In a possible implementation, the acquisition module 710 can also obtain the code and/or code comments input by the user in the following manner: the time range for receiving user input, the time range is the time range for the user to write codes, and the time when the user expects to recommend formal specifications, so that the device or system that applies the formal specification recommendation method provided by this application can only monitor the code writing operations performed by the user within this time range, and perform formal specification recommendations based on the code writing operations within this time range, and not monitor the codes performed by users outside this time range Writing operations can optimize user experience and save computing resources.
在一种可能的实现方式中,规约推荐模块720,在向用户显示多个候选形式规约时,可以向用户显示排序后的多个候选形式规约,其中,多个候选形式规约中与代码和/或代码的注释匹配最优的候选形式规约排列在首位,如此,可以便于用户方便快捷地从多个候选形式规约中查看到最优的候选形式规约。In a possible implementation, the protocol recommendation module 720, when displaying multiple candidate protocols to the user, may display the sorted multiple candidate protocols to the user, wherein among the multiple candidate protocols, the candidate protocol that best matches the code and/or code comments is ranked first, so that the user can conveniently and quickly view the optimal candidate protocol from the multiple candidate protocols.
在一种可能的实现方式中,如图7所示,装置700还包括验证模块730,当获取模块710还用于获取用户从多个候选形式规约中选择出的目标形式规约时,验证模块730用于使用目标形式规约对待验证代码进行验证。具体地,上述形式规约推荐装置700执行各种操作的具体实现,可参照上述形式规约推荐方法实施例中相关内容中的描述,为了说明书的简洁,这里不再赘述。In a possible implementation, as shown in FIG. 7 , the device 700 further includes a verification module 730. When the acquisition module 710 is also used to obtain the target form specification selected by the user from multiple candidate form specifications, the verification module 730 is used to use the target form specification to verify the code to be verified. Specifically, for the implementation of various operations performed by the formal specification recommending apparatus 700, reference may be made to the descriptions in the related content in the above-mentioned formal specification recommending method embodiment, and for the sake of brevity, details are not repeated here.
综上可知,本申请提供的形式规约推荐装置(如图7所示的装置700),可通过获取用户输入的代码和/或代码的注释,然后根据代码和/或代码的注释自动生成多个候选形式规约,最后将生成的多个候选形式规约推荐给用户,该多个候选形式规约可以给用户提供良好的参考,若用户确定多个候选形式规约中有满足自己需求的候选形式规约,则用户可直接选择该候选形式规约作为目标形式规约,并使用选择出的目标形式规约对待验证代码进行验证,用户无需进行整个形式规约的编写工作,能够节省用户的精力和时间,而且能够提高形式规约的获取效率以及计算机系统的开发的效率。To sum up, the formal specification recommendation device provided by this application (the device 700 shown in Figure 7 ) can automatically generate multiple candidate formal specifications according to the code and/or code annotations by obtaining the code and/or code comments input by the user, and finally recommend the generated multiple candidate formal specifications to the user. The multiple candidate formal specifications can provide users with good references. The target form specification is verified by the code to be verified, and the user does not need to write the entire form specification, which can save the user's energy and time, and can improve the efficiency of obtaining the form specification and the development efficiency of the computer system.
参见图8,图8是本申请提供的一种计算设备800的结构示意图,如图8所示,计算设备800包括:处理器810、存储器820和通信接口830,其中,处理器810、存储器820、通信接口830之间可以通过总线840相互连接。Referring to FIG. 8, FIG. 8 is a schematic structural diagram of a computing device 800 provided by the present application. As shown in FIG.
处理器810可以读取存储器820中存储的程序代码(包括指令),执行存储器820中存储的程序代码,使得计算设备800执行上述方法实施例提供的形式规约推荐方法中的步骤,或者使得计算设备800部署形式规约推荐装置700。The processor 810 can read the program codes (including instructions) stored in the memory 820, and execute the program codes stored in the memory 820, so that the computing device 800 executes the steps in the formal specification recommendation method provided by the above method embodiments, or makes the computing device 800 deploy the formal specification recommendation apparatus 700.
处理器810可以有多种具体实现形式,例如中央处理单元(central processing unit,CPU),或者CPU和硬件芯片的组合。上述硬件芯片可以是专用集成电路(application-specific integrated circuit,ASIC)、可编程逻辑器件(programmable logic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,CPLD)、现场可编程逻辑门阵列(field-programmable gate array,FPGA)、通用阵列逻辑(generic array logic,GAL)或其任意组合。处理器810执行各种类型的数字存储指令,例如存储在存储器820中的软件或者固件程序,它能使计算设备800提供多种服务。The processor 810 may have multiple specific implementation forms, such as a central processing unit (central processing unit, CPU), or a combination of a CPU and a hardware chip. The aforementioned hardware chip may be an application-specific integrated circuit (application-specific integrated circuit, ASIC), a programmable logic device (programmable logic device, PLD) or a combination thereof. The above-mentioned PLD may be a complex programmable logic device (complex programmable logic device, CPLD), a field-programmable gate array (field-programmable gate array, FPGA), a general array logic (generic array logic, GAL) or any combination thereof. Processor 810 executes various types of digitally stored instructions, such as software or firmware programs stored in memory 820, which enable computing device 800 to provide various services.
存储器820用于存储程序代码,并由处理器810来控制执行,以执行上述图3以及图5任一实施例中的处理步骤。程序代码中可以包括一个或多个软件模块,这一个或多个软件模块可以为图7实施例中提供的软件模块,如获取模块710、规约推荐模块720和验证模块730。The memory 820 is used to store program codes, which are controlled and executed by the processor 810, so as to execute the processing steps in any one of the above-mentioned embodiments in FIG. 3 and FIG. 5 . The program code may include one or more software modules, and the one or more software modules may be the software modules provided in the embodiment of FIG. 7 , such as an acquisition module 710 , a protocol recommendation module 720 and a verification module 730 .
存储器820可以包括易失性存储器(volatile memory),例如随机存取存储器(random access memory,RAM);存储器820也可以包括非易失性存储器(non-volatile memory),例如只读存储器(read-only memory,ROM)、快闪存储器(flash memory)、硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器820还可以包括上述种类的组合。 Memory 820 can comprise volatile memory (volatile memory), such as random access memory (random access memory, RAM); Memory 820 can also comprise nonvolatile memory (non-volatile memory), such as read-only memory (read-only memory, ROM), flash memory (flash memory), hard disk (hard disk drive, HDD) or solid-state drive (solid-state drive) ive, SSD); the memory 820 may also include a combination of the above types.
通信接口830可以为有线接口(例如以太网接口、光纤接口、其他类型接口(例如,infiniBand接口))或无线接口(例如蜂窝网络接口或使用无线局域网接口),用于与其他计算设备或装置进行通信。通信接口830可以采用传输控制协议/网际协议(transmission control protocol/internet protocol,TCP/IP)之上的协议族,例如,远程函数调用(remote function call,RFC)协议、简单对象访问协议(simple object access protocol,SOAP)协议、简单网络管理协议(simple network management protocol,SNMP)协议、公共对象请求代理体系结构(common object request broker architecture,CORBA)协议以及分布式协议等等。The communication interface 830 can be a wired interface (such as an Ethernet interface, an optical fiber interface, other types of interfaces (such as an infiniBand interface)) or a wireless interface (such as a cellular network interface or using a wireless local area network interface) for communicating with other computing devices or devices. The communication interface 830 can adopt a protocol family above the transmission control protocol/internet protocol (transmission control protocol/internet protocol, TCP/IP), for example, a remote function call (remote function call, RFC) protocol, a simple object access protocol (simple object access protocol, SOAP) protocol, a simple network management protocol (simple network management protocol, SNMP) protocol , common object request broker architecture (common object request broker architecture, CORBA) protocol and distributed protocol, etc.
总线840可以是快捷外围部件互连标准(peripheral component interconnect express,PCIe)总线,或扩展工业标准结构(extended industry standard architecture,EISA)总线、统一总线(unified bus,Ubus或UB)、计算机快速链接(compute express link,CXL)、缓存一致互联协议(cache coherent interconnect for accelerators,CCIX)等。总线840可以分为地址总线、数据总线、控制总线等。总线840除包括数据总线之外,还可以包括电源总线、控制总线和状态信号总线等。但是为了清楚说明起见,在图中将各种总线都标为总线840。为便于表示,图8中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。The bus 840 can be a peripheral component interconnect express (PCIe) bus, or an extended industry standard architecture (EISA) bus, a unified bus (Ubus or UB), a computer fast link (compute express link, CXL), or a cache coherent interconnect for accelerator s, CCIX) etc. The bus 840 can be divided into an address bus, a data bus, a control bus, and the like. In addition to the data bus, the bus 840 may also include a power bus, a control bus, and a status signal bus. However, for clarity of illustration, the various buses are labeled as bus 840 in the figure. For ease of representation, only one thick line is used in FIG. 8 , but it does not mean that there is only one bus or one type of bus.
上述计算设备800用于执行图3或者图5所示的本申请提供的形式规约推荐方法,与上述方法实施例属于同一构思,其具体实现过程详见上述方法实施例,这里不再赘述。应当理解,计算设备800仅为本申请实施例提供的一个例子,并且,计算设备800可具有比图8示出的部件更多或更少的部件,可以组合两个或更多个部件,或者可具有部件的不同配置实现。The above-mentioned computing device 800 is used to execute the form specification recommendation method provided by this application as shown in FIG. 3 or FIG. 5 , which belongs to the same concept as the above-mentioned method embodiment. For the specific implementation process, refer to the above-mentioned method embodiment for details, and will not be repeated here. It should be understood that computing device 800 is only an example provided by the embodiment of the present application, and computing device 800 may have more or fewer components than those shown in FIG. 8 , may combine two or more components, or may have different configurations of components.
本申请还提供一种计算机可读存储介质,该计算机可读存储介质中存储有指令,该指令被运行时可以实现上述实施例中记载的形式规约推荐方法的部分或者全部步骤。The present application also provides a computer-readable storage medium, and the computer-readable storage medium stores instructions, and when the instructions are executed, some or all steps of the formal specification recommendation method described in the above-mentioned embodiments can be implemented.
本申请还提供一种计算机程序产品,当计算机程序产品被计算机读取并执行时,可以实现上述方法实施例中记载的形式规约推荐方法的部分或者全部步骤。The present application also provides a computer program product. When the computer program product is read and executed by a computer, it can realize some or all steps of the formal specification recommendation method described in the above method embodiments.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其它实施例的相关描述。In the above-mentioned embodiments, the descriptions of each embodiment have their own emphases, and for parts not described in detail in a certain embodiment, reference may be made to relevant descriptions of other embodiments.
在上述实施例中,可以全部或部分地通过软件、硬件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线)或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如软盘、硬盘、磁带)、光介质、或者半导体介质等。In the above-mentioned embodiments, all or part may be implemented by software, hardware or any combination thereof. When implemented using software, it may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application will be generated in whole or in part. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line) or wireless (such as infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server or a data center integrated with one or more available media. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, or a magnetic tape), an optical medium, or a semiconductor medium.
以上所述,仅为本申请的具体实施方式。熟悉本技术领域的技术人员根据本申请提供的具体实施方式,可想到变化或替换,都应涵盖在本申请的保护范围之内。The foregoing is only a specific implementation manner of the present application. Those skilled in the art may conceive changes or substitutions based on the specific implementation methods provided in this application, and all of them shall fall within the protection scope of this application.

Claims (19)

  1. 一种形式规约推荐方法,其特征在于,所述方法包括:A form specification recommendation method, characterized in that the method includes:
    获取用户输入的代码和/或代码的注释;Get user-entered code and/or code comments;
    基于所述代码和/或代码的注释,得到多个候选形式规约,并向所述用户显示所述多个候选形式规约。Based on the code and/or annotations of the code, a plurality of candidate formal specifications is obtained, and the plurality of candidate formal specifications are displayed to the user.
  2. 根据权利要求1所述的方法,其特征在于,所述基于所述代码和/或代码的注释,得到多个候选形式规约,包括:The method according to claim 1, wherein said code and/or code annotations are used to obtain a plurality of candidate form specifications, including:
    将所述代码和/或代码的注释,输入形式规约生成模型进行识别,将所述形式规约生成模型输出的形式规约作为候选形式规约。Inputting the code and/or comments of the code into a formal specification generating model for identification, and using the formal specification output by the formal specification generating model as a candidate formal specification.
  3. 根据权利要求1所述的方法,其特征在于,所述基于所述代码和/或代码的注释,得到个候选形式规约,包括:The method according to claim 1, characterized in that, said based on said code and/or code annotations, obtaining a candidate form specification, comprising:
    基于所述代码和/或代码的注释与规则库包括的多条规则之间的匹配度,将所述多条规则中匹配度大于匹配度阈值的规则对应的形式规约作为候选形式规约。Based on the matching degree between the code and/or the comment of the code and the multiple rules included in the rule base, the formal specification corresponding to the rule whose matching degree is greater than the matching degree threshold among the multiple rules is used as a candidate formal specification.
  4. 根据权利要求1所述的方法,其特征在于,所述基于所述代码和/或代码的注释,得到多个候选形式规约,包括:The method according to claim 1, wherein said code and/or code annotations are used to obtain a plurality of candidate form specifications, including:
    基于所述代码对应的中间表示和/或代码的结构化注释,得到多个候选形式规约,其中,所述代码的结构化注释是对所述代码的注释进行结构化处理得到的。Multiple candidate form specifications are obtained based on the intermediate representation corresponding to the code and/or the structural annotation of the code, wherein the structural annotation of the code is obtained by performing structural processing on the annotation of the code.
  5. 根据权利要求1至4任一项所述的方法,其特征在于,所述获取用户输入的代码和/或代码的注释,包括:The method according to any one of claims 1 to 4, characterized in that said acquiring user-input codes and/or code comments includes:
    通过关键词触发对所述用户输入的代码和/或代码的注释的获取。Key words are used to trigger acquisition of the code and/or annotations of the code input by the user.
  6. 根据权利要求5所述的方法,其特征在于,所述通过关键词触发对所述用户输入的代码和/或代码的注释的获取,包括:The method according to claim 5, characterized in that, the acquisition of the code input by the user and/or code annotations triggered by keywords includes:
    在所述用户输入了关键词时,获取所述用户输入的代码和/或代码的注释。When the user inputs a keyword, acquire the code and/or the comment of the code input by the user.
  7. 根据权利要求1至6任一项所述的方法,其特征在于,所述向所述用户显示所述多个候选形式规约,包括:The method according to any one of claims 1 to 6, wherein the displaying the plurality of candidate form specifications to the user comprises:
    向所述用户显示排序后的所述多个候选形式规约,其中,所述多个候选形式规约中与所述代码和/或代码的注释匹配最优的候选形式规约排列在首位。Displaying the sorted plurality of candidate formal specifications to the user, wherein, among the plurality of candidate formal specifications, the candidate formal specifications that best match the code and/or the annotations of the code are ranked first.
  8. 根据权利要求1至7任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1 to 7, further comprising:
    获取所述用户从所述多个候选形式规约中选择出的目标形式规约;acquiring a target form specification selected by the user from the plurality of candidate form specifications;
    使用所述目标形式规约对待验证代码进行验证。The code to be verified is verified using the target form specification.
  9. 一种形式规约推荐装置,其特征在于,所述装置包括:A form specification recommendation device, characterized in that the device comprises:
    获取模块,用于获取用户输入的代码和/或代码的注释;Get module, used to get user input code and/or code comments;
    规约推荐模块,用于基于所述代码和/或代码的注释,得到多个候选形式规约,并向所述 用户显示所述多个候选形式规约。The protocol recommendation module is used to obtain multiple candidate form specifications based on the code and/or code annotations, and display the multiple candidate form specifications to the user.
  10. 根据权利要求9所述的装置,其特征在于,所述规约推荐模块,具体用于:The device according to claim 9, wherein the protocol recommendation module is specifically used for:
    将所述代码和/或代码的注释,输入形式规约生成模型进行识别,将所述形式规约生成模型输出的形式规约作为候选形式规约。Inputting the code and/or comments of the code into a formal specification generating model for identification, and using the formal specification output by the formal specification generating model as a candidate formal specification.
  11. 根据权利要求9所述的装置,其特征在于,所述规约推荐模块,具体用于:The device according to claim 9, wherein the protocol recommendation module is specifically used for:
    基于所述代码和/或代码的注释与规则库包括的多条规则之间的匹配度,将所述多条规则中匹配度大于匹配度阈值的规则对应的形式规约,作为候选形式规约。Based on the matching degree between the code and/or the comment of the code and the multiple rules included in the rule base, the formal specification corresponding to the rule whose matching degree is greater than the matching degree threshold among the multiple rules is used as a candidate formal specification.
  12. 根据权利要求9所述的装置,其特征在于,所述规约推荐模块,具体用于:The device according to claim 9, wherein the protocol recommendation module is specifically used for:
    基于所述代码对应的中间表示和/或代码的结构化注释,得到多个候选形式规约,其中,所述代码的结构化注释是对所述代码的注释进行结构化处理得到的。Multiple candidate form specifications are obtained based on the intermediate representation corresponding to the code and/or the structural annotation of the code, wherein the structural annotation of the code is obtained by performing structural processing on the annotation of the code.
  13. 根据权利要求9至12任一项所述的装置,其特征在于,所述获取模块,具体用于:The device according to any one of claims 9 to 12, wherein the acquisition module is specifically used for:
    通过关键词触发对所述用户输入的代码和/或代码的注释的获取。Key words are used to trigger acquisition of the code and/or annotations of the code input by the user.
  14. 根据权利要求13所述的装置,其特征在于,所述获取模块,具体用于:The device according to claim 13, wherein the acquiring module is specifically used for:
    在所述用户输入了关键词的情况下,获取所述用户输入的代码和/或代码的注释。In the case that the user has input a keyword, the code and/or the comment of the code input by the user are acquired.
  15. 根据权利要求9至14任一项所述的装置,其特征在于,所述规约推荐模块,具体用于:The device according to any one of claims 9 to 14, wherein the protocol recommendation module is specifically used for:
    向所述用户显示排序后的所述多个候选形式规约,其中,所述多个候选形式规约中与所述代码和/或代码的注释匹配最优的候选形式规约排列在首位。Displaying the sorted plurality of candidate formal specifications to the user, wherein, among the plurality of candidate formal specifications, the candidate formal specifications that best match the code and/or the annotations of the code are ranked first.
  16. 根据权利要求9至15任一项所述的装置,其特征在于,所述装置还包括验证模块;The device according to any one of claims 9 to 15, wherein the device further comprises a verification module;
    所述获取模块,还用于获取所述用户从所述多个候选形式规约中选择出的目标形式规约;The acquiring module is further configured to acquire a target form specification selected by the user from the plurality of candidate form specifications;
    所述验证模块,用于使用所述目标形式规约对待验证代码进行验证。The verification module is configured to use the target form specification to verify the code to be verified.
  17. 一种计算设备,其特征在于,所述计算设备包括处理器和存储器;所述处理器用于执行所述存储器存储的指令,使得所述计算设备实现权利要求1至8任一项所述的方法。A computing device, characterized in that the computing device includes a processor and a memory; the processor is configured to execute instructions stored in the memory, so that the computing device implements the method according to any one of claims 1 to 8.
  18. 一种形式规约推荐系统,其特征在于,所述系统包括终端设备和服务器;A form specification recommendation system, characterized in that the system includes a terminal device and a server;
    所述终端设备,用于获取用户输入的代码和/或代码的注释;The terminal device is used to obtain the code input by the user and/or the comment of the code;
    所述终端设备,用于将所述代码和/或代码的注释发送给所述服务器;The terminal device is configured to send the code and/or comments of the code to the server;
    所述服务器,用于根据所述代码和/或代码的注释,得到多个候选形式规约,并将所述多个候选形式规约发送给所述终端设备;The server is configured to obtain multiple candidate form specifications according to the code and/or code comments, and send the multiple candidate form specifications to the terminal device;
    所述终端设备,用于向所述用户显示所述多个候选形式规约。The terminal device is configured to display the plurality of candidate form specifications to the user.
  19. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有指令,所述指令用于实现权利要求1至8任一项所述的方法。A computer-readable storage medium, wherein the computer-readable storage medium stores instructions, and the instructions are used to implement the method according to any one of claims 1 to 8.
PCT/CN2022/139299 2022-01-21 2022-12-15 Form specification recommendation method, apparatus and system WO2023138270A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210074154.X 2022-01-21
CN202210074154.XA CN116540978A (en) 2022-01-21 2022-01-21 Formal specification recommendation method, device and system

Publications (1)

Publication Number Publication Date
WO2023138270A1 true WO2023138270A1 (en) 2023-07-27

Family

ID=87347771

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/139299 WO2023138270A1 (en) 2022-01-21 2022-12-15 Form specification recommendation method, apparatus and system

Country Status (2)

Country Link
CN (1) CN116540978A (en)
WO (1) WO2023138270A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2018156207A (en) * 2017-03-15 2018-10-04 富士通株式会社 Coding standards generation program, information processing apparatus and coding standards generation method
CN110276080A (en) * 2019-06-28 2019-09-24 第四范式(北京)技术有限公司 A kind of semantic processes method and system
CN111723192A (en) * 2020-06-19 2020-09-29 南开大学 Code recommendation method and device
CN113923268A (en) * 2021-09-08 2022-01-11 山东信通电子股份有限公司 Analysis method, equipment and storage medium for multi-version communication protocol

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2018156207A (en) * 2017-03-15 2018-10-04 富士通株式会社 Coding standards generation program, information processing apparatus and coding standards generation method
CN110276080A (en) * 2019-06-28 2019-09-24 第四范式(北京)技术有限公司 A kind of semantic processes method and system
CN111723192A (en) * 2020-06-19 2020-09-29 南开大学 Code recommendation method and device
CN113923268A (en) * 2021-09-08 2022-01-11 山东信通电子股份有限公司 Analysis method, equipment and storage medium for multi-version communication protocol

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
CHEN, DUYING ET AL.: "Research on Component Retrieval Based on Facet and Specification Description", JOURNAL OF HUAQIAO UNIVERSITY (NATURAL SCIENCE), 20 September 2012 (2012-09-20), XP009547868 *

Also Published As

Publication number Publication date
CN116540978A (en) 2023-08-04

Similar Documents

Publication Publication Date Title
US11720346B2 (en) Semantic code retrieval using graph matching
US10679008B2 (en) Knowledge base for analysis of text
US10354009B2 (en) Characteristic-pattern analysis of text
US10068174B2 (en) Hybrid approach for developing, optimizing, and executing conversational interaction applications
US20210342549A1 (en) Method for training semantic analysis model, electronic device and storage medium
US11645470B2 (en) Automated testing of dialog systems
US10929383B2 (en) Method and system for improving training data understanding in natural language processing
US20170004184A1 (en) Analysis of user text
US11966389B2 (en) Natural language to structured query generation via paraphrasing
CN112487157A (en) Template-based intent classification for chat robots
JP2021197133A (en) Meaning matching method, device, electronic apparatus, storage medium, and computer program
JP2021111334A (en) Method of human-computer interactive interaction based on retrieval data, device, and electronic apparatus
EP4006909B1 (en) Method, apparatus and device for quality control and storage medium
CN112417090A (en) Using uncommitted user input data to improve task performance
CN117296058A (en) Variant Inconsistent Attacks (VIA) as a simple and effective method of combating attacks
JP2023002690A (en) Semantics recognition method, apparatus, electronic device, and storage medium
US11875116B2 (en) Machine learning models with improved semantic awareness
JP7308910B2 (en) WORD SLOT RECOGNITION METHOD, APPARATUS AND ELECTRONIC DEVICE
US11080025B2 (en) Back-end application code stub generation from a front-end application wireframe
CN112329429B (en) Text similarity learning method, device, equipment and storage medium
US20240020096A1 (en) Systems and methods for generating code using language models trained on computer code
WO2023138270A1 (en) Form specification recommendation method, apparatus and system
US20180375926A1 (en) Distributed processing systems
US12032906B2 (en) Method, apparatus and device for quality control and storage medium
WO2023103690A1 (en) Unit testing generation method and apparatus, and related device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22921694

Country of ref document: EP

Kind code of ref document: A1