CN113238796B - Code reconstruction method, device, equipment and storage medium - Google Patents

Code reconstruction method, device, equipment and storage medium Download PDF

Info

Publication number
CN113238796B
CN113238796B CN202110534889.1A CN202110534889A CN113238796B CN 113238796 B CN113238796 B CN 113238796B CN 202110534889 A CN202110534889 A CN 202110534889A CN 113238796 B CN113238796 B CN 113238796B
Authority
CN
China
Prior art keywords
code
repeated
file
text
reconstruction
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
CN202110534889.1A
Other languages
Chinese (zh)
Other versions
CN113238796A (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.)
Beijing Jingdong Zhenshi Information Technology Co Ltd
Original Assignee
Beijing Jingdong Zhenshi Information Technology 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 Beijing Jingdong Zhenshi Information Technology Co Ltd filed Critical Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority to CN202110534889.1A priority Critical patent/CN113238796B/en
Publication of CN113238796A publication Critical patent/CN113238796A/en
Application granted granted Critical
Publication of CN113238796B publication Critical patent/CN113238796B/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/70Software maintenance or management
    • G06F8/72Code refactoring

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention discloses a code reconstruction method, a device, equipment and a storage medium, wherein the method comprises the following steps: responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction; extracting repeated code text in the code file to be reconstructed, and determining code attributes of the repeated code text; and generating a repeated code file corresponding to the repeated code text based on the code attribute, and carrying out code reconstruction of the code file to be reconstructed according to the repeated code file. The method provided by the embodiment of the invention carries out code reconstruction by automatically extracting the repeated codebook in the code file to be reconstructed, thereby realizing the rapid extraction of the repeated redundant part in the code file to be reconstructed, avoiding missing the file which is not extracted, accelerating the code reconstruction speed, shortening the code reconstruction time and improving the code reconstruction efficiency.

Description

Code reconstruction method, device, equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a code reconstruction method, a device, equipment and a storage medium.
Background
In the test process, automatic code writing is often required to be realized, reconstruction is also often involved, and code repeatability sentences are more usually used for similar automatic code use cases. According to iterative writing, if the historical codes are too many and accumulate for a long time, how to quickly find out repeated codes and extract the codes independently is a great workload.
The most common way at present is read through, extracted and deleted, and finally the latest code is reconstructed. In the process of implementing the present invention, the inventor finds that at least the following technical problems exist in the prior art: the existing code reconstruction mode is time-consuming, labor-consuming, easy to change, and low in reconstruction efficiency.
Disclosure of Invention
The embodiment of the invention provides a code reconstruction method, a device, equipment and a storage medium, so as to realize quick and accurate completion of code reconstruction.
In a first aspect, an embodiment of the present invention provides a code reconstruction method, including:
responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
Extracting repeated code text in the code file to be reconstructed, and determining the code attribute of the repeated code text;
and generating a repeated code file corresponding to the repeated code text based on the code attribute, and reconstructing the code of the code file to be reconstructed according to the repeated code file.
Optionally, on the basis of the above scheme, extracting the repeated code text in the code file to be reconstructed includes:
and inputting the code file to be reconstructed into a pre-constructed text classifier to obtain the repeated code text extracted by the text classifier.
Optionally, on the basis of the above scheme, determining the code attribute of the repeated code text includes:
And acquiring the position of the repeated code text in the test case, and determining the code attribute based on the position.
Optionally, on the basis of the above scheme, determining the code attribute of the repeated code text includes:
code keywords in the repeated code text are extracted, and code attributes are determined based on the code keywords.
Optionally, on the basis of the above scheme, generating the repeated code file corresponding to the repeated code text based on the code attribute includes:
And when the code attribute is a logic attribute, generating a repeated code file corresponding to the repeated code text.
Optionally, on the basis of the above scheme, generating a repetition code file corresponding to the repetition code text includes:
and generating a repeated code file containing the repeated code text, and determining the file attribute of the repeated code file corresponding to the repeated code text according to the code attribute of the repeated code text.
Optionally, on the basis of the above scheme, performing code reconstruction of the code file to be reconstructed according to the repeated code file includes:
and adjusting calling logic of a non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file to complete code reconstruction of the code file to be reconstructed.
In a second aspect, an embodiment of the present invention further provides a code reconstruction apparatus, including:
The file acquisition module is used for responding to the detected code reconstruction instruction and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
The repeated text extraction module is used for extracting repeated code texts in the code file to be reconstructed and determining code attributes of the repeated code texts;
and the code reconstruction module is used for generating a repeated code file corresponding to the repeated code text based on the code attribute, and carrying out code reconstruction of the code file to be reconstructed according to the repeated code file.
In a third aspect, an embodiment of the present invention further provides a computer apparatus, including:
One or more processors;
a storage means for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the code reconstruction method as provided by any embodiment of the present invention.
In a fourth aspect, embodiments of the present invention also provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a code reconstruction method as provided by any of the embodiments of the present invention.
According to the embodiment of the invention, the code file to be reconstructed corresponding to the code reconstruction instruction is obtained by responding to the detected code reconstruction instruction; extracting repeated code text in the code file to be reconstructed, and determining the code attribute of the repeated code text; generating a repeated code file corresponding to the repeated code text based on the code attribute, carrying out code reconstruction of the code file to be reconstructed according to the repeated code file, and carrying out code reconstruction by automatically extracting the repeated code book in the code file to be reconstructed, thereby realizing rapid extraction of repeated redundant parts in the code file to be reconstructed, avoiding missing the non-extracted file, accelerating the code reconstruction speed, shortening the code reconstruction time and improving the code reconstruction efficiency.
Drawings
FIG. 1 is a flow chart of a code reconstruction method according to a first embodiment of the present invention;
FIG. 2 is a flowchart of a code reconstruction method according to a second embodiment of the present invention;
Fig. 3 is a schematic structural diagram of a code reconstruction device according to a third embodiment of the present invention;
Fig. 4 is a schematic structural diagram of a computer device according to a fourth embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
Example 1
Fig. 1 is a flowchart of a code reconstruction method according to an embodiment of the present invention. The present embodiment is applicable to the case of reconstructing codes, especially codes with obvious features (such as those based on selenium+ testng or other existing frameworks, applied to long-time code accumulation, and excessive repetition of the same code beginning or ending features). The method may be performed by code reconstruction means, which may be implemented in software and/or hardware, e.g. may be configured in a computer device. As shown in fig. 1, the method includes:
S110, responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction.
In this embodiment, the code reconstruction instruction may be user initiated and is used to indicate an instruction for performing code reconstruction. The user may click the code reconfiguration control to trigger the code reconfiguration request after the information of the code file to be reconfigured is added by the operation terminal, the operation terminal obtains information (such as the information of the code file to be reconfigured and the information of the user) associated with the code reconfiguration request after detecting the code reconfiguration request initiated by the user, and the like to generate a code reconfiguration instruction, and sends the code reconfiguration instruction to the code reconfiguration device, and after detecting the code reconfiguration instruction sent by the operation terminal, the code reconfiguration device analyzes the code reconfiguration instruction to obtain the information of the code file to be reconfigured corresponding to the code reconfiguration instruction, so as to obtain the code file to be reconfigured. The information of the code file to be reconstructed may be a specific file, or may be a uniform resource locator (Uniform Resource Locator, URL) of the code file to be reconstructed. If the information of the code file to be reconstructed is a specific file, the code file to be reconstructed can be directly obtained by analyzing the code reconstruction instruction; and if the information of the code file to be reconstructed is the URL of the code file to be reconstructed, acquiring the code file to be reconstructed from the URL.
The code file to be reconstructed may include a plurality of test cases, and at least two test cases have the same code text.
S120, extracting repeated code text in the code file to be reconstructed, and determining the code attribute of the repeated code text.
In this embodiment, the repeated code text in the code file to be reconstructed is extracted by a similar text extraction algorithm. In view of the fact that the repeated code text cannot be used as a common file when it is a specific function implementing part, it is necessary to determine the code attribute of the repeated code text after extracting the repeated code text, and determine whether to generate the corresponding repeated code file as the common file based on the code attribute. The code attribute of the repeated code text can be determined manually or based on the text feature of the repeated code text.
Alternatively, the specific similar text extraction algorithm is not limited. By way of example, text features in the code file to be reconstructed can be extracted through a feature extraction model (such as a trained neural network model), and texts with the same text features are used as repeated code texts; the literal similarity of the texts in the code file to be reconstructed can be directly calculated by the existing similarity calculation method, and the texts with the same literal similarity can be used as repeated code texts.
In one embodiment of the present invention, extracting the repeated code text in the code file to be reconstructed includes: and inputting the code file to be reconstructed into a pre-constructed text classifier to obtain the repeated code text extracted by the text classifier. Alternatively, an existing text classifier (such as any classifier of naive bayes classifier, decision tree, maximum entropy classifier, etc.) may be used to extract the repeated code text in the code file to be reconstructed. It can be understood that the code file to be reconstructed is input into the text classifier, the code file to be reconstructed is used as an input parameter of the text classifier, the classification logic of the text classifier is executed, and the output result of the text classifier is obtained as the repeated code text. The repeated code text in the code file to be reconstructed is extracted by using the text classifier, so that the repeated code text is extracted more quickly and accurately.
In one embodiment, determining the code attribute of the repeated code text includes: and acquiring the position of the repeated code text in the test case, and determining the code attribute based on the position. In general, the location of the code in the use case can characterize its properties, such as the code at the beginning of the use case is typically the reference portion and the initialization portion, the code in the middle of the use case is typically the implementation portion, and the code at the end of the use case is typically the verification portion. It will be appreciated that the reference portion, initialization portion and verification portion may be extracted and invoked as common text. Optionally, when the repeated code text is at the beginning (e.g., the first M rows of the test case) or the end (e.g., the last N rows of the test case) of the test case, determining that the code attribute is a logic attribute; when the repeated code text is in the middle part of the test case (such as the M line-N line of the test case), the code attribute is determined to be the realization attribute. Determining the code properties of the repeated code text based on the location of the repeated code text is simple in logic but may be less accurate.
In one embodiment, determining the code attribute of the repeated code text includes: code keywords in the repeated code text are extracted, and code attributes are determined based on the code keywords. Generally, the codes in the same part have the same keywords, a keyword library of the corresponding part of the code attribute can be preset, after the repeated code text is extracted, the code keywords of the repeated code text are extracted, the code keywords are matched with the keywords in the keyword library, if the matching is successful, the code attribute of the repeated code text is determined to be a logic attribute, and if the matching is failed, the code text of the repeated code text is determined to be an implementation attribute. The keyword extracting the repeated code text may adopt an existing keyword extracting manner, which is not described herein. The accuracy of determining the code attribute of the repeated code text is higher based on the keywords of the repeated code text, but the setting of the keyword library is more critical.
S130, generating a repeated code file corresponding to the repeated code text based on the code attribute, and performing code reconstruction of the code file to be reconstructed according to the repeated code file.
In the present embodiment, after determining the code attribute, it is judged whether or not to generate the repetition code file as a common file based on the code attribute until all the repetition code text judgment/generation is completed.
Optionally, generating the repeated code file corresponding to the repeated code text based on the code attribute includes: and when the code attribute is a logic attribute, generating a repeated code file corresponding to the repeated code text. When the code attribute of the repeated code text is a logic attribute, the repeated code text can be called as a public file, so that when the code attribute is the logic attribute, a repeated code file corresponding to the repeated code text is generated; when the code attribute is an implementation attribute (i.e., the repetition code text is a use case specific implementation code), the repetition code file is not generated as a common file.
Generating a repeated code file corresponding to the repeated code text comprises the following steps: and generating a repeated code file containing the repeated code text, and determining the file attribute of the repeated code file corresponding to the repeated code text according to the code attribute of the repeated code text. Specifically, the repeated code text is used as a single repeated code file, and the file attribute of the repeated code file corresponding to the repeated code text, such as attribute information of a file name, is determined according to the code attribute of the repeated code text. Illustratively, assuming that the code attribute of the repeated code text is a reference portion in the logical attribute, a file name representing the reference portion is generated as the file name of the repeated code file, so that the call/reference relationship is adjusted based on the file name in the subsequent code comb.
In one embodiment, the code reconstruction of the code file to be reconstructed according to the repeated code file includes: and adjusting calling logic of a non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file to complete code reconstruction of the code file to be reconstructed. Before the code file to be reconstructed is reconstructed, a direct reference mode is adopted in the non-repeated code text, and after the repeated code text is generated into the repeated code file, the previous reference mode is required to be adjusted to be a mode of calling the file, namely, the reference/calling logic relation of parameters in the repeated code text in the non-repeated code text is adjusted, so that the code reconstruction of the code file to be reconstructed is completed.
According to the embodiment of the invention, the code file to be reconstructed corresponding to the code reconstruction instruction is obtained by responding to the detected code reconstruction instruction; extracting repeated code text in the code file to be reconstructed, and determining the code attribute of the repeated code text; generating a repeated code file corresponding to the repeated code text based on the code attribute, carrying out code reconstruction of the code file to be reconstructed according to the repeated code file, and carrying out code reconstruction by automatically extracting the repeated code book in the code file to be reconstructed, thereby realizing rapid extraction of repeated redundant parts in the code file to be reconstructed, avoiding missing the non-extracted file, accelerating the code reconstruction speed, shortening the code reconstruction time and improving the code reconstruction efficiency.
Example two
The present embodiment provides a preferred embodiment based on the above-described scheme. The code reconstruction method provided by the embodiment of the invention is mainly suitable for unified automatic code frames, has obvious characteristics of a code structure, such as the situation that the code structure is based on selenium+ testng or other existing frames, is applied to long-time code accumulation, excessive test cases and repeated the same code beginning or ending, and is intended to realize reconstruction and extract unified files.
Fig. 2a is a block diagram of a code reconstruction system according to a second embodiment of the present invention. As shown in fig. 2a, the core of the code reconstruction system is 4 modules: the method comprises the steps of reconstructing/optimizing a code structure, a text classifier, a code extraction module and an automation code module, wherein the 4 modules are independent of each other and can not mix codes together, and call interface-based call or call of service between services.
Overall, the code input mainly comprises automation engineering, several automation modes are included, each engineering file for executing automation is independent, as the input of the text classifier, the implemented use case part is mainly used as key input, and the code input is also the part which mainly needs to be extracted. The text classifier can be implemented in a program to find the same code portion in multiple files, but needs to distinguish whether the repeated portion is a code logic portion or an implementation portion. Code extraction the repeated code file obtained according to the previous step is extracted according to the similarity and the position of the code in the file, such as configuration file, public method, end statement, etc. Different files are formed according to different code attributes. The whole reconstruction/optimization code structure re-plans the code structure according to the extracted file, and the rest main automation codes realize logic key combing except the extracted part. And redefining and carding the extracted public file to finally form a tidy and complete code structure.
Fig. 2b is a flowchart of a code reconstruction method according to a second embodiment of the present invention. As shown in fig. 2b, the code reconstruction method includes:
(1) Firstly, a use case needing to be reconstructed is used as input and is input into a text identical extractor constructed in advance;
(2) Identifying whether extraction is needed according to the classification of the automatic use cases;
And comparing the files one by a preset identity partition classification method.
(3) Extracting the same file, identifying the text according to the characteristics and the appearance position of the file, and forming a unified file;
Such as a method of printing a box number, the test case includes a reference portion, an initialization portion, a method implementation portion, and a verification portion. The reference part, the initialization part and the verification part can be extracted to customize a configuration file, and the configuration file is called when the case is written.
(4) Reconstructing the code.
After extraction, unified inspection is needed, and definition modification is performed again. And redundant parts of each test case are reduced on the basis of not changing the original test case.
According to the embodiment of the invention, the repeated redundant parts of the automatic codes are rapidly extracted through the text similarity algorithm, so that missing of non-extracted files is avoided, the reconstruction of codes is quickened, and the reconstruction time is shortened; in addition, the building is realized in a modularized form, the coupling is low, the maintenance is easy, one link has a problem, and the quick positioning can be realized.
Example III
Fig. 3 is a schematic structural diagram of a code reconstruction device according to a third embodiment of the present invention. The code reconstruction means may be implemented in software and/or hardware, for example the code reconstruction means may be arranged in a computer device. As shown in fig. 3, the apparatus includes a file acquisition module 310, a repeated text extraction module 320, and a code reconstruction module 330, wherein:
a file obtaining module 310, configured to obtain a code file to be reconstructed corresponding to the code reconstruction instruction in response to the detected code reconstruction instruction;
the repeated text extraction module 320 is configured to extract repeated code text in the code file to be reconstructed, and determine a code attribute of the repeated code text;
The code reconstruction module 330 is configured to generate a repeated code file corresponding to the repeated code text based on the code attribute, and reconstruct the code of the code file to be reconstructed according to the repeated code file.
According to the embodiment of the invention, a file obtaining module responds to the detected code reconstruction instruction to obtain the code file to be reconstructed corresponding to the code reconstruction instruction; the repeated text extraction module extracts repeated code texts in the code file to be reconstructed and determines code attributes of the repeated code texts; the code reconstruction module generates a repeated code file corresponding to the repeated code text based on the code attribute, performs code reconstruction of the code file to be reconstructed according to the repeated code file, and performs code reconstruction by automatically extracting the repeated code book in the code file to be reconstructed, thereby realizing rapid extraction of repeated redundant parts in the code file to be reconstructed, avoiding missing non-extracted files, accelerating code reconstruction speed, shortening code reconstruction time and improving code reconstruction efficiency.
Optionally, based on the above scheme, the repeated text extraction module 320 is specifically configured to:
and inputting the code file to be reconstructed into a pre-constructed text classifier to obtain the repeated code text extracted by the text classifier.
Optionally, based on the above scheme, the repeated text extraction module 320 is specifically configured to:
And acquiring the position of the repeated code text in the test case, and determining the code attribute based on the position.
Optionally, based on the above scheme, the repeated text extraction module 320 is specifically configured to:
code keywords in the repeated code text are extracted, and code attributes are determined based on the code keywords.
Optionally, based on the above scheme, the code reconstruction module 330 is specifically configured to:
And when the code attribute is a logic attribute, generating a repeated code file corresponding to the repeated code text.
Optionally, based on the above scheme, the code reconstruction module 330 is specifically configured to:
and generating a repeated code file containing the repeated code text, and determining the file attribute of the repeated code file corresponding to the repeated code text according to the code attribute of the repeated code text.
Optionally, based on the above scheme, the code reconstruction module 330 is specifically configured to:
and adjusting calling logic of a non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file to complete code reconstruction of the code file to be reconstructed.
The code reconstruction device provided by the embodiment of the invention can execute the code reconstruction method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
Example IV
Fig. 4 is a schematic structural diagram of a computer device according to a fourth embodiment of the present invention. Fig. 4 is a schematic structural diagram of a computer device according to a fourth embodiment of the present invention. Fig. 4 illustrates a block diagram of an exemplary computer device 412 suitable for use in implementing embodiments of the invention. The computer device 412 shown in fig. 4 is only an example and should not be construed as limiting the functionality and scope of use of embodiments of the invention.
As shown in FIG. 4, computer device 412 is in the form of a general purpose computing device. Components of computer device 412 may include, but are not limited to: one or more processors 414, a system memory 428, a bus 418 that connects the various system components (including the system memory 428 and the processors 414).
Bus 418 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor 414, or a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Computer device 412 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by computer device 412 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 428 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 430 and/or cache memory 432. The computer device 412 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage 434 may be used to read from or write to non-removable, non-volatile magnetic media (not shown in FIG. 4, commonly referred to as a "hard disk drive"). Although not shown in fig. 4, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 418 via one or more data medium interfaces. Memory 428 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of embodiments of the invention.
A program/utility 440 having a set (at least one) of program modules 442 may be stored in, for example, memory 428, such program modules 442 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 442 generally perform the functions and/or methodologies in the described embodiments of the invention.
The computer device 412 may also communicate with one or more external devices 414 (e.g., keyboard, pointing device, display 424, etc.), one or more devices that enable a user to interact with the computer device 412, and/or any devices (e.g., network card, modem, etc.) that enable the computer device 412 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 422. Moreover, computer device 412 may also communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, through network adapter 420. As shown, network adapter 420 communicates with other modules of computer device 412 over bus 418. It should be appreciated that although not shown, other hardware and/or software modules may be used in connection with computer device 412, including, but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processor 414 executes programs stored in the system memory 428 to perform various functional applications and data processing, such as implementing a code reconstruction method provided by an embodiment of the present invention, including:
responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
extracting repeated code text in the code file to be reconstructed, and determining code attributes of the repeated code text;
And generating a repeated code file corresponding to the repeated code text based on the code attribute, and carrying out code reconstruction of the code file to be reconstructed according to the repeated code file.
Of course, it will be appreciated by those skilled in the art that the processor may also implement the technical solution of the code reconstruction method provided in any embodiment of the present invention.
Example five
The fifth embodiment of the present invention further provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the code reconstruction method provided by the embodiment of the present invention, the method comprising:
responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
extracting repeated code text in the code file to be reconstructed, and determining code attributes of the repeated code text;
And generating a repeated code file corresponding to the repeated code text based on the code attribute, and carrying out code reconstruction of the code file to be reconstructed according to the repeated code file.
Of course, the computer readable storage medium provided by the embodiments of the present invention, on which the computer program stored, is not limited to the above method operations, but may also perform the related operations of the code reconstruction method provided by any embodiment of the present invention.
The computer storage media of embodiments of the invention may take the form of any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (7)

1. A method of code reconstruction, comprising:
responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
extracting repeated code text in the code file to be reconstructed, and determining code attributes of the repeated code text;
generating a repeated code file corresponding to the repeated code text based on the code attribute, and carrying out code reconstruction of the code file to be reconstructed according to the repeated code file;
the generating the repeated code file corresponding to the repeated code text based on the code attribute comprises the following steps:
when the code attribute is a logic attribute, generating a repeated code file corresponding to the repeated code text;
The generating the repeated code file corresponding to the repeated code text comprises the following steps:
generating a repeated code file containing the repeated code text, and determining the file attribute of the repeated code file corresponding to the repeated code text according to the code attribute of the repeated code text;
The code reconstruction of the code file to be reconstructed according to the repeated code file comprises the following steps:
adjusting calling logic of a non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file to complete code reconstruction of the code file to be reconstructed;
when the repeated code text is at the beginning or the end of the test case, determining that the code attribute of the repeated code text is a logic attribute.
2. The method of claim 1, wherein the extracting the repeated code text in the code file to be reconstructed comprises:
and inputting the code file to be reconstructed into a pre-constructed text classifier to obtain repeated code text extracted by the text classifier.
3. The method of claim 1, wherein said determining the code properties of the repeated code text comprises:
And acquiring the position of the repeated code text in the test case, and determining the code attribute based on the position.
4. The method of claim 1, wherein said determining the code properties of the repeated code text comprises:
and extracting code keywords in the repeated code text, and determining the code attribute based on the code keywords.
5. A code reconstruction apparatus, comprising:
The file acquisition module is used for responding to the detected code reconstruction instruction and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
The repeated text extraction module is used for extracting repeated code texts in the code file to be reconstructed and determining code attributes of the repeated code texts;
the code reconstruction module is used for generating a repeated code file corresponding to the repeated code text based on the code attribute, and carrying out code reconstruction of the code file to be reconstructed according to the repeated code file;
The code reconstruction module is specifically configured to:
when the code attribute is a logic attribute, generating a repeated code file containing repeated code text, and determining the file attribute of the repeated code file corresponding to the repeated code text according to the code attribute of the repeated code text;
Adjusting calling logic of a non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file to complete code reconstruction of the code file to be reconstructed;
when the repeated code text is at the beginning or the end of the test case, determining that the code attribute of the repeated code text is a logic attribute.
6. A computer device, the device comprising:
One or more processors;
a storage means for storing one or more programs;
The one or more programs, when executed by the one or more processors, cause the one or more processors to implement the code reconstruction method of any one of claims 1-4.
7. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the code reconstruction method as claimed in any one of claims 1-4.
CN202110534889.1A 2021-05-17 2021-05-17 Code reconstruction method, device, equipment and storage medium Active CN113238796B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110534889.1A CN113238796B (en) 2021-05-17 2021-05-17 Code reconstruction method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110534889.1A CN113238796B (en) 2021-05-17 2021-05-17 Code reconstruction method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113238796A CN113238796A (en) 2021-08-10
CN113238796B true CN113238796B (en) 2024-09-20

Family

ID=77134697

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110534889.1A Active CN113238796B (en) 2021-05-17 2021-05-17 Code reconstruction method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113238796B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104063208A (en) * 2013-03-21 2014-09-24 北京百度网讯科技有限公司 Code file optimizing method, system and server
CN104866334A (en) * 2014-12-12 2015-08-26 北汽福田汽车股份有限公司 Method for partitioning and running software codes of controller
CN106068496A (en) * 2014-03-20 2016-11-02 日立公共系统有限公司 Source code is formed and provides device and source code to be formed and the method for offer
CN107506204A (en) * 2017-09-30 2017-12-22 福建星瑞格软件有限公司 A kind of function reconstructing method of the code similarity-rough set based on the cosine law

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4118456B2 (en) * 1999-06-29 2008-07-16 株式会社東芝 Program language processing system, code optimization method, and machine-readable storage medium
CN103559025B (en) * 2013-10-21 2017-01-25 沈阳建筑大学 Software refactoring method through clustering
JP2015179369A (en) * 2014-03-19 2015-10-08 株式会社 日立産業制御ソリューションズ Refactoring device and program
CN110162335A (en) * 2019-04-26 2019-08-23 深圳壹账通智能科技有限公司 Code refactoring method, apparatus, computer equipment and medium
CN110196952B (en) * 2019-05-30 2021-11-12 百度时代网络技术(北京)有限公司 Program code search processing method, device, equipment and storage medium
CN110221824B (en) * 2019-06-03 2024-03-22 北京秒针人工智能科技有限公司 Method and device for generating component
CN111767076A (en) * 2020-06-23 2020-10-13 中国工商银行股份有限公司 Code reconstruction method and device
CN111813444A (en) * 2020-07-10 2020-10-23 北京思特奇信息技术股份有限公司 Method, system and electronic equipment for analyzing similarity of source codes
CN111722873A (en) * 2020-07-23 2020-09-29 腾讯科技(深圳)有限公司 Code reconstruction method, device, equipment and medium
CN112199117B (en) * 2020-09-23 2023-06-02 建信金融科技有限责任公司 Method and device for processing repeated codes, electronic equipment and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104063208A (en) * 2013-03-21 2014-09-24 北京百度网讯科技有限公司 Code file optimizing method, system and server
CN106068496A (en) * 2014-03-20 2016-11-02 日立公共系统有限公司 Source code is formed and provides device and source code to be formed and the method for offer
CN104866334A (en) * 2014-12-12 2015-08-26 北汽福田汽车股份有限公司 Method for partitioning and running software codes of controller
CN107506204A (en) * 2017-09-30 2017-12-22 福建星瑞格软件有限公司 A kind of function reconstructing method of the code similarity-rough set based on the cosine law

Also Published As

Publication number Publication date
CN113238796A (en) 2021-08-10

Similar Documents

Publication Publication Date Title
CN109002510B (en) Dialogue processing method, device, equipment and medium
CN111026470B (en) System and method for verification and conversion of input data
US11074067B2 (en) Auto-generation of application programming interface (API) documentation via implementation-neutral analysis of API traffic
CN111552633A (en) Interface abnormal call testing method and device, computer equipment and storage medium
CN112509690A (en) Method, apparatus, device and storage medium for controlling quality
CN109872230B (en) Test method and device of financial data analysis system, medium and electronic equipment
CN112507090A (en) Method, apparatus, device and storage medium for outputting information
CN113836014A (en) Interface testing method and device, electronic equipment and storage medium
CN112395843A (en) PHP code-based service processing method, device, equipment and medium
CN113778897A (en) Automatic test method, device, equipment and storage medium of interface
CN116360735A (en) Form generation method, device, equipment and medium
JP7309811B2 (en) Data annotation method, apparatus, electronics and storage medium
CN113792138A (en) Report generation method and device, electronic equipment and storage medium
CN113656391A (en) Data detection method and device, storage medium and electronic equipment
CN109684207B (en) Method and device for packaging operation sequence, electronic equipment and storage medium
CN109766260B (en) Method, device, electronic equipment and storage medium for configuring test action
CN113238796B (en) Code reconstruction method, device, equipment and storage medium
CN114171107B (en) Method, device, equipment and storage medium for detecting VPD information of solid state disk
US20230062297A1 (en) Systems and methods for code repository embedding for tagging and summarization tasks using attention on multiple code domains
CN107992457B (en) Information conversion method, device, terminal equipment and storage medium
US9208046B2 (en) Method and system for optimizing testing efforts in system of systems testing
CN111552779A (en) Man-machine conversation method, device, medium and electronic equipment
CN111400623A (en) Method and apparatus for searching information
CN118170688B (en) Configuration file detection method and device, storage medium and electronic equipment
CN116560819B (en) RPA-based batch automatic operation method, system, equipment and storage medium

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