CN113805861B - Code generation method based on machine learning, code editing system and storage medium - Google Patents

Code generation method based on machine learning, code editing system and storage medium Download PDF

Info

Publication number
CN113805861B
CN113805861B CN202111091494.5A CN202111091494A CN113805861B CN 113805861 B CN113805861 B CN 113805861B CN 202111091494 A CN202111091494 A CN 202111091494A CN 113805861 B CN113805861 B CN 113805861B
Authority
CN
China
Prior art keywords
code
prediction
interface
codes
training
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN202111091494.5A
Other languages
Chinese (zh)
Other versions
CN113805861A (en
Inventor
胡安丽
谢琳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Bank Co Ltd
Original Assignee
Ping An Bank Co Ltd
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 Ping An Bank Co Ltd filed Critical Ping An Bank Co Ltd
Priority to CN202111091494.5A priority Critical patent/CN113805861B/en
Publication of CN113805861A publication Critical patent/CN113805861A/en
Application granted granted Critical
Publication of CN113805861B publication Critical patent/CN113805861B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N20/00Machine learning
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application is suitable for the technical field of artificial intelligence, and provides a code generation method, a code editing system and a storage medium based on machine learning. According to the code generation method, the interface type of the newly built interface is obtained through the code editing system, the index relation corresponding to the interface type is obtained, the prediction code which is usually matched with the current input code for use is predicted through the index relation, the prediction code can be inserted into the appointed position, and the code prediction and automatic input with high correlation are realized, so that the workload of a developer for writing the same code in different test cases is reduced, the writing efficiency of the test cases is improved, and the code test efficiency is further improved.

Description

Code generation method based on machine learning, code editing system and storage medium
Technical Field
The present application relates to the field of artificial intelligence technologies, and in particular, to a code generation method, a code editing system, and a storage medium based on machine learning.
Background
After the developer finishes writing the source Code, the source Code needs to be subjected to Code Test, and the Code Test needs to be subjected to three tests of Review, debug and Test Case operation according to the sequence, wherein the Review Test and the Debug Test can be usually finished through a Code editing system or a Test component of the development environment, and the Test Case operation requires the developer to build a Test Case according to the actual application scene of the source Code.
When the source code works in various application scenes, a developer needs to build various corresponding test cases according to different application scenes, the number of codes for building the various test cases is large, and a certain number of identical codes exist among the various test cases, so that the time for writing the test cases is excessive and the identical codes are repeatedly written, and therefore, how to solve the problem that the writing efficiency of the test cases is poor is currently needed to be solved.
Disclosure of Invention
In view of the above, the embodiments of the present application provide a code generation method, a code editing system and a storage medium based on machine learning, so as to solve the problems that a plurality of test cases are built with a large number of codes, and a certain number of identical codes exist between the plurality of test cases, which results in excessive time for writing the test cases, repeated writing of identical codes, and poor writing efficiency of the test cases.
A first aspect of an embodiment of the present application provides a code generation method based on machine learning, applied to a code editing system, the method including:
acquiring an interface type of the newly-built interface according to the identification of the newly-built interface, wherein the interface type comprises a scene type, a function type and a step type;
Acquiring attributes of a current input code of the newly-built interface, wherein the attributes comprise packages, objects, functions, variables and numerical values;
obtaining an index relation corresponding to the interface type, wherein the index relation comprises a plurality of sections of prediction codes, any one section of first prediction code in the plurality of sections of prediction codes has at least one section of second prediction code corresponding to the first prediction code, and the first prediction code and the second prediction code are different in attribute;
displaying at least one section of second prediction code corresponding to the first prediction code when the character of the current input code is the same as the character of the first prediction code and the attribute of the current input code is the same as the attribute of the first prediction code;
and inserting the second prediction code into a designated position of the code editing system when the second prediction code is selected.
According to the code generation method, the interface type of a newly built interface is obtained through the code editing system, the index relation corresponding to the interface type is obtained, the predicted code which is commonly matched with the current input code is predicted through the index relation, the predicted code can be inserted into a designated position, and the code prediction and automatic input with high correlation are achieved, so that the workload of a developer for writing the same code in different test cases is reduced, the writing efficiency of the test cases is improved, and further the code test efficiency is improved.
A second aspect of the embodiment of the present application provides a code editing system based on machine learning, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the code generating method provided in the first aspect of the embodiment of the present application when the computer program is executed.
In one embodiment, the processor includes a code hint component;
the code prompting component is used for detecting a current input code;
the code prompting component is further used for displaying at least one section of second predicted code corresponding to the first predicted code when the character of the current input code is the same as the character of the first predicted code and the attribute of the current input code is the same as the attribute of the first predicted code;
the code prompting component is further configured to display the first predicted code when the character of the current input code is the same as a consecutive preset number of characters in the first predicted code.
In one embodiment, the processor includes a code automatic input component;
the code automatic input component is connected with the code prompting component;
the code automatic input component is used for inserting a second predicted code into a designated position of the code editing system when the second predicted code is selected;
The code automatic input component is further configured to replace a current input code with a first predicted code when the first predicted code is selected.
The second aspect of the embodiment of the application provides a code editing system, which can judge the complete code which is tried to be input by a user by detecting the current input code, display the first prediction code, judge the prediction code which is frequently matched with the current input code and display the second prediction code, and realize the code prediction and the automatic input of the prediction code by replacing the current input code with the first prediction code or inputting the second prediction code at a designated position, thereby greatly improving the intelligence of the code editing system and improving the coding efficiency of developers.
A third aspect of the embodiments of the present application provides a computer-readable storage medium storing a computer program which, when executed by at least one processor, implements the steps of the code generation method provided in the first aspect of the embodiments of the present application.
It will be appreciated that the advantages of the third aspect may be found in the relevant description of the first aspect, and are not described in detail herein.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments or the description of the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of a code editing system according to an embodiment of the present application;
FIG. 2 is a first flowchart of a code generation method according to an embodiment of the present application;
FIG. 3 is a diagram of an interface type inclusion relationship provided by an embodiment of the present application;
FIG. 4 is a table of correspondence between a preset interface type library according to an embodiment of the present application;
FIG. 5 is a second flowchart of a code generation method according to an embodiment of the present application;
fig. 6 is a third flowchart of a code generation method according to an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth such as the particular system architecture, techniques, etc., in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
It should be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in the present specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes such combinations.
As used in the present description and the appended claims, the term "if" may be interpreted as "when..once" or "in response to a determination" or "in response to detection" depending on the context. Similarly, the phrase "if a determination" or "if a [ described condition or event ] is detected" may be interpreted in the context of meaning "upon determination" or "in response to determination" or "upon detection of a [ described condition or event ]" or "in response to detection of a [ described condition or event ]".
Furthermore, the terms "first," "second," "third," and the like in the description of the present specification and in the appended claims, are used for distinguishing between descriptions and not necessarily for indicating or implying a relative importance.
Reference in the specification to "one embodiment" or "some embodiments" or the like means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," and the like in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments" unless expressly specified otherwise. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless expressly specified otherwise.
In application, when source codes can work in various application scenes, the types of test cases are synchronously increased, so that the time consumed by developers in programming the test cases is excessive, and the code test efficiency is affected.
In view of the above technical problems, an embodiment of the present application provides a code generation method based on machine learning, by acquiring an interface type of a newly built interface, further acquiring an index relationship corresponding to the interface type, so as to predict a predicted code that is commonly used in cooperation with a current input code, and insert the predicted code in a designated position, so as to implement code prediction and automatic input with high correlation, improve development speed of a test case, and further improve code test efficiency.
The code generation method provided by the embodiment of the application can be applied to any terminal equipment capable of carrying out data processing on codes. The terminal device may be a mobile phone, a tablet computer, a wearable device, an Augmented Reality (AR)/Virtual Reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, or the like, and the specific type of the terminal device is not limited in the embodiments of the present application.
In application, the code testing method provided by the embodiment of the application is suitable for any electronic equipment capable of carrying out data processing on a code editing system. The electronic device may be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality/virtual reality device, a notebook computer, etc., and the embodiment of the application does not limit the specific type of the electronic device.
The code editing system needs to have an installation function of a custom component or be an Open Source (Open Source) environment, the custom component may be a code editing auxiliary (hint) component, the code editing system may be integrated in an integrated development environment (Integrated Development Environment, IDE), the integrated development environment may include Visual Studio (IDE developed by microsoft corporation), netBeans (IDE for JAVA language), eclipse (IDE for JAVA language), and the like, and the embodiment of the present application does not limit the specific type of the integrated development environment.
FIG. 1 schematically illustrates an architecture of a code editing system 100, the code editing system 100 comprising a memory 101, a processor 102, and a computer program 103 stored in the memory 101 and executable on the processor 102;
the processor 101 further includes a code prompting component 104, where the code prompting component 104 is configured to detect a current input code and display a predicted code according to characters and/or properties of the current input code. The input codes may be implemented by an input device 105 such as a keyboard or a mouse, and the prediction codes may be displayed on an output device 106 such as a display screen, and the memory 101, the processor 102, the input device 105, and the output device 106 may be correspondingly connected to each other and communicate based on a communication line 107.
In the application, the code editing system stores the index relation corresponding to each interface type, and the code prompting component can acquire the corresponding index relation according to the interface type of the newly built interface. The index relation comprises a plurality of sections of prediction codes, and specifically can comprise prediction codes with various attributes such as prediction encapsulation codes, prediction object codes, prediction function codes, prediction variable codes or prediction numerical value codes, and the specific characters contained in each section of the prediction codes are different. It should be noted that, the multiple segments of prediction codes have a corresponding relationship, specifically, any one segment of first prediction code has at least one corresponding segment of second prediction code, and the attributes of the first prediction code and the second prediction code are different, where the first prediction code may be any one segment of prediction code in the multiple segments of prediction codes.
In the application, the code prompting component is used for acquiring at least one section of second predicted code corresponding to the first predicted code according to the index relation when the current input code is detected to be the same as the first detected code and the attribute of the current input code is detected to be the same as the attribute of the first predicted code, and displaying the corresponding at least one section of second predicted code on an editing page of the code editing system so as to prompt a user to frequently match the second predicted code used with the first predicted code under the current interface type.
In the application, the code prompting component is further used for displaying at least one section of corresponding first predicted code on an editing page of the code editing system when the characters of the current input code are detected to be identical to the continuous preset number of characters in the first predicted code, so that under the current interface type, the complete code which the user tries to input is judged according to the partial characters of the user input code.
In one embodiment, the processor 101 further includes a code automatic input component 108;
the code automatic input component 108 is connected with the code prompting component 104;
the code automatic input component 108 is configured to insert the second predictive code into a specified location of the code editing system 100 when the second predictive code is selected;
The code automatic input component 108 is further operable to replace the current input code with the first predicted code upon selection of the first predicted code.
In application, the code automatic input component is used for selecting the second prediction code through clicking operation or key operation by a developer, inserting the second prediction code into a designated position of the code editing system, wherein the designated position can be specifically the later position of the current input code, and the designated position can be selected according to the actual requirement of the developer.
In application, the code automatic input component is further used for selecting the first predictive code through clicking operation or key operation by a developer, replacing the current input code with the first predictive code, reducing the workload of the developer for repeatedly writing the same code, and improving the development efficiency of the test case.
In application, the processor, when executing the computer program, may implement the code generation methods shown in fig. 2, 5 and 6 described below.
In application, the processor may be a central processing unit (Central Processing Unit, CPU), which may also be other general purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In applications, the memory may in some embodiments be an internal storage unit of the terminal device, such as a hard disk or a memory of the terminal device. The memory may in other embodiments also be an external storage device of the terminal device, such as a plug-in hard disk provided on the terminal device, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card (Flash Card) or the like. Further, the memory may also include both an internal storage unit of the terminal device and an external storage device. The memory is used to store an operating system, application programs, boot loader (BootLoader), data, and other programs, etc., such as program code for a computer program, etc. The memory may also be used to temporarily store data that has been output or is to be output.
The code editing system provided by the embodiment of the application can judge the complete code which is tried to be input by a user by detecting the current input code, display the first prediction code, judge the prediction code which is frequently matched with the current input code and display the second prediction code, and realize code prediction and automatic input of the prediction code by replacing the current input code with the first prediction code or inputting the second prediction code at a designated position, thereby greatly improving the intelligence of the code editing system and further improving the coding efficiency of developers.
It will be appreciated that the illustrated structure of the embodiments of the present application does not constitute a particular limitation of the code editing system 100. In other embodiments of the application, code editing system 100 may include more or less components than those illustrated, or certain components may be combined, or different components, such as may also include network access devices, etc. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
As shown in fig. 2, the machine learning-based code generation method provided by the embodiment of the application is applied to a code editing system, and includes the following steps S201 to S205:
step S201, according to the identification of the newly-built interface, obtaining the interface type of the newly-built interface, wherein the interface type comprises a scene type, a function type and a step type.
In application, the interface types may be divided according to Tree structures (Tree structures), and according to the containing relation of the Tree structures, the interface types may be divided from a root Structure to a substructure into scene types, function types, step types, and the like, the scene types may include saving scenes, loan scenes, investment scenes, and the like, the function types may include transfer functions, deposit functions, and the like, and the step types may include identity authentication steps, transfer result acquisition steps, and the like.
In an application, the inclusion relationship of the interfaces of the three interface types may be specifically: one scene type interface includes a plurality of function type interfaces, and one function type interface includes a plurality of step type interfaces; the functions of the interfaces of the three interface types can be as follows: one scenario type interface may set at least one usage scenario of a test case, one function type interface may set at least one function of a test case in one usage scenario, and one step type interface may set at least one test step of a test case in one function. For example (as shown in fig. 3), the savings scene interface includes a transfer function interface and a deposit function interface, wherein the transfer function interface includes an identity authentication step interface, a transfer object confirmation step interface, a transfer amount acquisition step interface, a transfer instruction transmission step interface, and a transfer result acquisition step interface. The division of the interface type can be set according to actual needs, and the embodiment of the application does not limit the specific division rule or the specific structure of the interface type.
Fig. 3 illustrates an exemplary diagram of the inclusion of interface types.
In the application, according to the writing rule of the code, a developer needs to define the interface when writing the test case, and the code editing system can read the identification for defining the newly built interface to acquire the interface type of the newly built structure. By dividing and identifying the interface types, the role of each interface in the test case can be rapidly judged.
In one embodiment, the identifier of the new interface may include the name of the new interface or the comment of the new interface, and step S201 includes:
acquiring the name of the new interface, and performing name retrieval based on a preset interface type library to acquire the interface type of the new interface;
or, acquiring the annotation of the newly-built interface, and performing annotation retrieval based on a preset interface type library to acquire the interface type of the newly-built interface.
In application, the code editing system stores a preset interface type library, where the preset interface type library includes preset interface types, preset names and preset notes, and each preset interface type has at least one corresponding preset name and at least one corresponding preset note (for specific correspondence, refer to fig. 4). It should be noted that, due to the limitation of the code writing rule, the preset name is written in english, and the preset annotation can be written in any language, specifically in chinese or english.
Fig. 4 illustrates a table of correspondence of a preset interface type library.
In application, the code editing system can search based on a preset interface type library to obtain the interface type of the newly built interface. The searching steps can be as follows: firstly, reading the name of a new interface, carrying out name retrieval according to a preset interface type library, judging that the name retrieval is successful if the preset name which is the same as the name of the new interface exists, acquiring the preset interface type corresponding to the name of the new interface, and taking the preset interface type as the interface type of the new interface; if the preset name which is the same as the name of the new interface does not exist, judging that the name retrieval fails, starting to read the annotation of the new interface, carrying out annotation retrieval according to a preset interface type library, and if the preset annotation which is the same as the annotation of the new interface exists, judging that the annotation retrieval is successful, acquiring the preset interface type corresponding to the annotation of the new interface and taking the preset interface type as the interface type of the new interface; if the preset annotation which is the same as the annotation of the newly built interface does not exist, judging that the annotation retrieval fails, outputting an interface type selection signal, providing a plurality of preset interface types for a user, and prompting the user to manually select.
In the application, name retrieval can be performed first, and annotation retrieval can be performed; the method and the device can also perform annotation retrieval first and then perform name retrieval, and the execution sequence of the name retrieval and the annotation retrieval is not limited in any way.
Step S202, obtaining the attribute of the current input code of the newly-built interface, wherein the attribute comprises encapsulation, an object, a function, a variable and a numerical value.
In application, the code editing system can acquire the current input code of the newly-built interface in editing in real time and judge the attribute of the current input code, wherein the attribute of the input code can comprise various attributes such as Encapsulation (Encapsulation), object (Class), function (Function), variable (Value) and the like; specifically, the complete code logic of the test case written at present can be read by the code editing system of the preset judging node so as to judge the attribute of the input code. The preset judging node may be when the user completes writing a word, or when the user completes writing a Line of codes (1-Line-Code) to the next Line, or when the user completes writing a Code block. The embodiment of the application does not limit the setting of the preset judging node.
Step S203, obtaining an index relation corresponding to the interface type, wherein the index relation comprises a plurality of sections of prediction codes, any section of first prediction code in the plurality of sections of prediction codes has at least one section of second prediction code corresponding to the first prediction code, and the first prediction code and the second prediction code have different attributes.
In application, the code editing system stores index relations corresponding to each interface type, and can acquire the corresponding index relations according to the interface type of the newly built interface. The index relation comprises a plurality of sections of prediction codes, and specifically can comprise prediction codes with various attributes such as prediction encapsulation codes, prediction object codes, prediction function codes, prediction variable codes or prediction numerical value codes, and the specific characters contained in each section of the prediction codes are different. It should be noted that, the multiple segments of prediction codes have a corresponding relationship, specifically, any one of the multiple segments of first prediction codes has at least one corresponding segment of second prediction code, and the attributes of the first prediction code and the second prediction code are different, where the first prediction code may be any one of the multiple segments of prediction codes, and the following is exemplified:
for example, assuming that the interface type of the newly-built interface is an identity authentication step, the identity authentication step includes face authentication and voice authentication, and substituting the identity authentication step as a first prediction code into an index relation to obtain 7-segment prediction codes, wherein the 7-segment prediction codes specifically include 2-segment prediction package codes and 5-segment prediction object codes, the 1-segment prediction package codes correspond to the 1 st segment and the 2 nd segment prediction object codes, and the 2 nd segment prediction package codes correspond to the 3 rd, 4 th and 5 th segment prediction object codes;
The 1 st section of prediction encapsulation codes can be particularly used for realizing a face authentication function, and the 1 st section of prediction object codes corresponding to the 1 st section of prediction encapsulation codes can be particularly used for defining face acquisition data; the 2 nd segment of the prediction object code corresponding to the method can be specifically used for defining the face authentication result;
the 2 nd section of prediction packaging codes can be particularly used for realizing a voice authentication function, and the 3 rd section of prediction object codes corresponding to the 2 nd section of prediction packaging codes can be particularly used for defining voice acquisition data; the specific content of the 4 th section of the prediction object code corresponding to the method can be used for defining voice acquisition analysis; the 5 th segment of the prediction object code corresponding to the prediction object code can be specifically used for defining a voice authentication result.
It should be noted that, the above-mentioned interface types are only exemplary, and the index relationships corresponding to the identity authentication steps are not limited in any way.
Step S204, when the character of the current input code is the same as the character of the first prediction code, and the attribute of the current input code is the same as the attribute of the first prediction code, displaying at least one section of the second prediction code corresponding to the first prediction code.
In the application, when the code editing system detects that the current input code is the same as the first detection code and the attribute of the current input code is the same as the attribute of the first prediction code, at least one section of second prediction code corresponding to the first prediction code can be obtained according to the index relation, and at least one section of corresponding second prediction code is displayed on an editing page of the code editing system so as to prompt a user to frequently match the second prediction code used with the first prediction code under the current interface type.
Step S205, when the second prediction code is selected, the second prediction code is inserted into the designated position of the code editing system.
In the application, the developer can select the second prediction code through clicking operation or key operation, and insert the second prediction code into a designated position of the code editing system, wherein the designated position can be specifically the later position of the current input code, and the designated position can be selected according to the actual requirement of the developer.
In application, the interface type of the newly built interface is obtained through the code editing system, the index relation corresponding to the interface type is obtained, the predicted code which is usually matched with the current input code is predicted through the index relation, the predicted code can be inserted into a designated position, and the code prediction and automatic input with high correlation are realized, so that the workload of a developer for writing the same code in different test cases is reduced, the development speed of the test cases is improved, and the code test efficiency is further improved.
As shown in fig. 5, in one embodiment, based on the embodiment corresponding to fig. 2, the method includes the following steps S501 to S507:
step S501, according to the identification of the newly-built interface, obtaining the interface type of the newly-built interface, wherein the interface type comprises a scene type, a function type and a step type;
Step S502, obtaining the attribute of the current input code of the newly-built interface, wherein the attribute comprises package, object, function, variable and numerical value;
step S503, obtaining an index relation corresponding to the interface type, wherein the index relation comprises a plurality of sections of prediction codes, any section of first prediction code in the plurality of sections of prediction codes has at least one section of second prediction code corresponding to the first prediction code, and the first prediction code and the second prediction code have different attributes;
step S504, when the character of the current input code is the same as the character of the first prediction code, and the attribute of the current input code is the same as the attribute of the first prediction code, displaying at least one section of second prediction code corresponding to the first prediction code;
step S505, inserting the second predictive code into the appointed position of the code editing system when the second predictive code is selected;
step S506, when the characters of the current input code are the same as the continuous preset number of characters in the first predicted code, displaying the first predicted code;
step S507, when the first prediction code is selected, the current input code is replaced by the first prediction code.
In application, the steps S501 to S507 are consistent with the code generation methods provided in the steps S201 to S205, and are not described herein. The difference is that step S503 is followed by step S506 and step S507, and step S506 and step S507 are described below.
In the application, when the code editing system detects the characters of the current input code and the characters with the same continuous preset number as the characters in the first predicted code, at least one section of the corresponding first predicted code can be displayed on an editing page of the code editing system, so that under the current interface type, the complete code which the user tries to input can be judged according to the partial characters of the user input code.
In the application, a developer can select the first predictive code through clicking operation or key operation, replace the current input code with the first predictive code, reduce the workload of the developer for repeatedly writing the same code, and improve the development efficiency of the test case.
As shown in fig. 6, in one embodiment, based on the embodiment corresponding to fig. 5, before step S503, an index relationship corresponding to each interface type needs to be established, and the establishing method includes steps S601 to S604 as follows:
step S601, collecting training codes meeting any extraction condition, wherein the training codes comprise a plurality of training interfaces, the extraction condition comprises that the compiling times of the training codes are larger than the preset compiling times, and the executing times of the compiled training codes are larger than the preset executing times.
In the application, the training codes can be obtained according to the code storage carriers such as the log files or engineering files of the local code editing system, or can be obtained from the code storage carriers such as the code library or the log files of the server in a Web Crawler (Web Crawler) mode. The training code needs to meet any extraction condition, and the extraction condition can comprise that the editing times of the training code are larger than the preset compiling times, and the execution times of the compiled training code are larger than the preset execution times. The preset compiling times can be 1 time, 2 times, 3 times or 4 times, and the preset executing times can be 1 time, 2 times, 3 times or 4 times, and the specific times of the preset compiling times and the preset executing times are not limited in the embodiment of the application.
In the application, by setting the extraction conditions, low-quality codes of the extraction conditions which are stored in a local code editing system and a server and are not compiled or executed can be filtered, so that the quality of the acquired training codes is improved, and the training codes are ensured to have no grammar errors.
Step S602, according to the identification of each training interface, the interface type of each training interface is obtained.
In the application, the method for obtaining the interface type of each training interface is consistent with the method for obtaining the interface type of the newly built interface in the step S201, and will not be described herein.
Step S603, analyzing the training interfaces of each interface type through the prediction module to obtain an index relationship of each interface type, where the index relationship of any interface type is used to record training codes of the corresponding interface type and corresponding relationships between the training codes.
In application, before the training interfaces of each interface type are analyzed by the prediction module, the collected plurality of training interfaces may be classified according to the interface type. The input of the prediction module is all codes included in training interfaces of any interface type, the output is an index relation corresponding to the interface type, and the prediction module can process training interfaces of multiple interface types in parallel and output the index relation of the multiple interface types in a one-to-one correspondence mode. The internal processing mechanism and the generated index relationship of the prediction module are described in detail below:
after the prediction module obtains the training interface of one interface type, the prediction module can read all codes included in the training interface of one interface type, and determine the attribute of each training code according to the code logic, and specifically can include training codes of various attributes such as training package codes, training object codes, training function codes, training variable codes, training numerical codes and the like. The prediction module may also establish a correspondence between the training codes of the plurality of attributes according to the inclusion relationship between the training codes of the plurality of attributes.
Specifically, the prediction module can identify a plurality of segments of training object codes included in a segment of training package codes, so as to obtain a plurality of segments of training object codes corresponding to the segment of training package codes, and similarly, can obtain a plurality of segments of training function codes corresponding to the segment of packages, a plurality of segments of training variable codes corresponding to the segment of packages, and a plurality of segments of training numerical codes corresponding to the segment of packages;
the multi-section training function codes included in one section of training object codes can be identified, so that the multi-section training function codes corresponding to the one section of training object codes are obtained, and the multi-section training variable codes corresponding to the one section of training object codes and the multi-section training numerical codes corresponding to the one section of training object codes can be obtained in the same way;
the method can also identify a plurality of training variable codes included in a training function code so as to obtain a plurality of training variable codes corresponding to the training function code, and the method can also obtain a plurality of training numerical codes corresponding to the training function code;
the training variable codes can be identified to obtain a plurality of training numerical codes corresponding to the training variable codes;
By the method for acquiring the corresponding relation between the training codes, all codes included in the training interfaces of each interface type are analyzed, and the index relation of each interface type can be obtained in a one-to-one correspondence mode.
In one embodiment, step S603 includes:
and analyzing the training interfaces of each interface type through the prediction module to obtain index relations of each interface type, wherein the index relations of any interface type are used for recording the corresponding relations of the training encapsulation codes, the training object codes, the training function codes and the training variable codes of the corresponding interface type.
In the application, the method for acquiring the correspondence between training codes is consistent with the step S603, and will not be described herein. The difference is that the index relation of any interface type is used for recording the corresponding relation of training package codes, training object codes, training function codes and training variable codes of the corresponding interface type.
Step S604, installing the index relation to a code editing system.
In application, when the code editing system has the installation function of the custom component, the index relation of each interface type can be packaged to generate a custom component and the custom component is installed to the code editing system; when the code editing system is in an open source environment, the index relation can be written into the bottom code of the code editing system, so that when the test case is written, the code editing system can run the index relation, and in the process of writing the test case by a user, the second prediction code with high correlation is prompted according to the current input code, and the writing efficiency of the test case is improved.
In application, the code generating method based on machine learning provided by the embodiment of the application obtains the interface type of the newly built interface through the code editing system, obtains the index relation corresponding to the interface type, predicts the predicted code which is commonly matched with the current input code through the index relation, and can insert the predicted code into the appointed position to realize the code prediction and automatic input with high correlation, thereby reducing the workload of a developer for writing the same code in different test cases, improving the writing efficiency of the test cases and further improving the code test efficiency.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic, and should not limit the implementation process of the embodiment of the present application.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional modules is illustrated, and in practical application, the above-described functional allocation may be performed by different functional modules according to needs, i.e. the internal structure of the apparatus is divided into different functional modules to perform all or part of the functions described above. The functional modules in the embodiment may be integrated in one processing module, or each module may exist alone physically, or two or more modules may be integrated in one module, where the integrated modules may be implemented in a form of hardware or a form of software functional modules. In addition, the specific names of the functional modules are only for distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working process of the modules in the above system may refer to the corresponding process in the foregoing method embodiment, which is not described herein again.
The integrated modules, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the present application may implement all or part of the flow of the method of the above embodiments, and may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium, and when the computer program is executed by a processor, the computer program may implement the steps of each of the method embodiments described above. Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable medium may include at least: any entity or device capable of carrying computer program code to a photo terminal equipment, a recording medium, a computer Memory, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Such as a U-disk, removable hard disk, magnetic or optical disk, etc.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference is made to the related descriptions of other embodiments.
Those of ordinary skill in the art will appreciate that the various illustrative modules and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed terminal device and method may be implemented in other manners. For example, the above-described embodiments of the terminal device are merely illustrative, and for example, the division of the modules is merely a logical function division, and there may be other manners of division in actual implementation, for example, multiple modules or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection via interfaces, devices or modules, which may be in electrical, mechanical or other forms.
The above embodiments are only for illustrating the technical solution of the present application, and not for limiting the same; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.

Claims (8)

1. A code generation method based on machine learning, the code generation method being applied to a code editing system, the method comprising:
acquiring the interface type of the newly built interface according to the identifier of the newly built interface;
acquiring the attribute of the current input code of the newly-built interface;
obtaining an index relation corresponding to the interface type, wherein the index relation comprises a plurality of sections of prediction codes, any section of first prediction code in the plurality of sections of prediction codes has at least one section of corresponding second prediction code, the first prediction code and the second prediction code are different in attribute, and the first prediction code and the second prediction code are different in character;
Displaying at least one section of second prediction code corresponding to the first prediction code when the character of the current input code is the same as the character of the first prediction code and the attribute of the current input code is the same as the attribute of the first prediction code;
inserting the second predictive code into a designated position of the code editing system when the second predictive code is selected;
before the index relation corresponding to the interface type is obtained, the method further comprises:
collecting training codes meeting any extraction condition, wherein the training codes comprise a plurality of training interfaces, the extraction condition comprises that the compiling times of the training codes are larger than preset compiling times, and the executing times of the compiled training codes are larger than preset executing times;
acquiring the interface type of each training interface according to the identification of each training interface;
analyzing the training interfaces of each interface type through a prediction module to obtain index relations of each interface type, wherein the index relation of any interface type is used for recording training codes of the corresponding interface type and corresponding relations among the training codes;
Installing the index relationship to the code editing system;
the training interfaces of each interface type are analyzed through the prediction module to obtain the index relation of each interface type, and the method comprises the following steps:
and analyzing the training interfaces of each interface type through the prediction module to obtain index relations of each interface type, wherein the index relation of any interface type is used for recording the corresponding relation of training packaging codes, training object codes, training function codes and training variable codes of the corresponding interface type.
2. The code generation method of claim 1, wherein the identification of the new interface includes a name of the new interface or an annotation of the new interface;
the obtaining the interface type of the newly-built interface according to the identifier of the newly-built interface comprises the following steps:
acquiring the name of the new interface, and performing name retrieval based on a preset interface type library to acquire the interface type of the new interface;
or, acquiring the annotation of the newly-built interface, and performing annotation retrieval based on a preset interface type library to acquire the interface type of the newly-built interface.
3. The code generation method according to claim 1 or 2, wherein after the obtaining the index relation corresponding to the interface type, the method further comprises:
And displaying the first predictive code when the character of the current input code is the same as the continuous preset number of characters in the first predictive code.
4. The code generation method of claim 3, wherein the method further comprises, after displaying the first predicted code when the character of the current input code is the same as a consecutive preset number of characters in the first predicted code:
and when the first prediction code is selected, replacing the current input code with the first prediction code.
5. A machine learning based code editing system comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the code generation method of any of claims 1 to 4 when the computer program is executed.
6. The code editing system of claim 5, wherein said processor comprises a code hint component;
the code prompting component is used for detecting a current input code;
the code prompting component is further used for displaying at least one section of second predicted code corresponding to the first predicted code when the character of the current input code is the same as the character of the first predicted code and the attribute of the current input code is the same as the attribute of the first predicted code;
The code prompting component is further configured to display the first predicted code when the character of the current input code is the same as a consecutive preset number of characters in the first predicted code.
7. The code editing system of claim 5 or 6, wherein the processor comprises a code automatic input component;
the code automatic input component is connected with the code prompting component;
the code automatic input component is used for inserting a second predicted code into a designated position of the code editing system when the second predicted code is selected;
the code automatic input component is further configured to replace a current input code with a first predicted code when the first predicted code is selected.
8. A computer-readable storage medium storing a computer program, characterized in that the computer program, when executed by a processor, implements the steps of the code generation method of any one of claims 1 to 4.
CN202111091494.5A 2021-09-17 2021-09-17 Code generation method based on machine learning, code editing system and storage medium Active CN113805861B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111091494.5A CN113805861B (en) 2021-09-17 2021-09-17 Code generation method based on machine learning, code editing system and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111091494.5A CN113805861B (en) 2021-09-17 2021-09-17 Code generation method based on machine learning, code editing system and storage medium

Publications (2)

Publication Number Publication Date
CN113805861A CN113805861A (en) 2021-12-17
CN113805861B true CN113805861B (en) 2023-08-11

Family

ID=78895696

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111091494.5A Active CN113805861B (en) 2021-09-17 2021-09-17 Code generation method based on machine learning, code editing system and storage medium

Country Status (1)

Country Link
CN (1) CN113805861B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116560631B (en) * 2023-07-12 2023-10-17 百融云创科技股份有限公司 Method and device for generating machine learning model code

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6654954B1 (en) * 1998-02-17 2003-11-25 International Business Machines Corporation Computer system, program product and method utilizing executable file with alternate program code attached as a file attribute
CN110083340A (en) * 2019-03-19 2019-08-02 深圳壹账通智能科技有限公司 Code generating method, device, computer equipment and storage medium
CN111782181A (en) * 2020-06-28 2020-10-16 北京百度网讯科技有限公司 Code generation method and device, electronic equipment and storage medium
CN112527273A (en) * 2020-12-18 2021-03-19 平安科技(深圳)有限公司 Code completion method, device and related equipment

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10628129B2 (en) * 2017-08-08 2020-04-21 Accenture Global Solutions Limited Intellectual automated security, performance and code generation framework
US10459695B2 (en) * 2017-10-05 2019-10-29 Sap Se Correction of code errors using machine learning
US10963226B2 (en) * 2017-10-25 2021-03-30 Aspiring Minds Assessment Private Limited Generating compilable code from uncompilable code

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6654954B1 (en) * 1998-02-17 2003-11-25 International Business Machines Corporation Computer system, program product and method utilizing executable file with alternate program code attached as a file attribute
CN110083340A (en) * 2019-03-19 2019-08-02 深圳壹账通智能科技有限公司 Code generating method, device, computer equipment and storage medium
CN111782181A (en) * 2020-06-28 2020-10-16 北京百度网讯科技有限公司 Code generation method and device, electronic equipment and storage medium
CN112527273A (en) * 2020-12-18 2021-03-19 平安科技(深圳)有限公司 Code completion method, device and related equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
张晶 ; 黄小锋 ; .基于业务模型和界面模型的代码生成工具.电脑与信息技术.2016,(第02期),第5-9、19页. *

Also Published As

Publication number Publication date
CN113805861A (en) 2021-12-17

Similar Documents

Publication Publication Date Title
US8539475B2 (en) API backward compatibility checking
US7493596B2 (en) Method, system and program product for determining java software code plagiarism and infringement
CN106294134B (en) The collapse localization method and device of code
CN109783346B (en) Keyword-driven automatic testing method and device and terminal equipment
CN111176996A (en) Test case generation method and device, computer equipment and storage medium
CN111124479B (en) Method and system for analyzing configuration file and electronic equipment
CN103631573A (en) Method and system for obtaining execution time of transferable functions
CN115686631B (en) Random instruction generation method and device based on knowledge base and storage medium
CN113805861B (en) Code generation method based on machine learning, code editing system and storage medium
CN108664471A (en) Text region error correction method, device, equipment and computer readable storage medium
JPH08212106A (en) Device and method for supporting system test
CN107562423B (en) UI page development method and device
CN115033434A (en) Kernel performance theoretical value calculation method and device and storage medium
CN113900956A (en) Test case generation method and device, computer equipment and storage medium
JP2007213487A (en) Aspect generation method and apparatus
CN111124423A (en) Multi-platform-based compiling detection method, device, server and medium
CN112148581A (en) Code specification checking method, device, system and storage medium
CN115981711B (en) Code processing method and electronic equipment
CN113946347B (en) Function call detection method and device, electronic equipment and readable medium
CN116541305B (en) Abnormality detection method and device, electronic equipment and storage medium
CN109002287B (en) Management method and device for software in cloud data system
CN117493169A (en) Method, device, equipment and medium for detecting API (application program interface) behavior incompatibility among Java dependency library versions
CN112559370A (en) Front-end-based React project unit testing method and related equipment
CN117687922A (en) Test case testing method, device, equipment and storage medium
CN115905006A (en) Method for checking program code, storage medium, and electronic device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant