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

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

Info

Publication number
CN113238796A
CN113238796A CN202110534889.1A CN202110534889A CN113238796A CN 113238796 A CN113238796 A CN 113238796A CN 202110534889 A CN202110534889 A CN 202110534889A CN 113238796 A CN113238796 A CN 113238796A
Authority
CN
China
Prior art keywords
code
repeated
file
text
reconstructed
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.)
Pending
Application number
CN202110534889.1A
Other languages
Chinese (zh)
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/CN113238796A/en
Publication of CN113238796A publication Critical patent/CN113238796A/en
Pending legal-status Critical Current

Links

Images

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 a 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. According to the method provided by the embodiment of the invention, the repeated code book in the code file to be reconstructed is automatically extracted for code reconstruction, so that the repeated redundant part in the code file to be reconstructed is quickly extracted, the unextracted files are avoided being omitted, the code reconstruction speed is accelerated, the code reconstruction time is shortened, and the code reconstruction efficiency is improved.

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 code reconstruction device, code reconstruction equipment and a storage medium.
Background
In the testing process, the automatic code writing is often required to be realized, the reconstruction is often involved, and generally, for similar automatic code use cases, the code has more repetitive statements. According to the iterative writing, if the historical codes are many and accumulate for a long time, how to quickly find out the repeated codes and extract the codes independently is a great workload.
At present, the most common mode is read-through, deletion is extracted, and the latest code is reconstructed. In the process of implementing the 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 miss modification 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, which are used for realizing rapid and accurate code reconstruction.
In a first aspect, an embodiment of the present invention provides a code reconfiguration method, including:
responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
extracting a repeated code text in a 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 a 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 a repeated code text extracted by the text classifier.
Optionally, on the basis of the above scheme, determining a 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 a 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 a repetition code file corresponding to the repetition code text based on the code attribute includes:
and when the code attribute is the 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 the calling logic of the non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file, and completing the code reconstruction of the code file to be reconstructed.
In a second aspect, an embodiment of the present invention further provides a code reconstructing 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 files to be reconstructed and determining the 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 reconstructing the code 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 device, where the computer device includes:
one or more processors;
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 reconfiguration method as provided by any of the embodiments of the present invention.
In a fourth aspect, the embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the code reconstruction method provided in any embodiment of the present invention.
The method and the device for code reconstruction acquire the code file to be reconstructed corresponding to the code reconstruction instruction by responding to the detected code reconstruction instruction; extracting a repeated code text in a code file to be reconstructed, and determining the code attribute of the repeated code text; the method comprises the steps of generating a repeated code file corresponding to a repeated code text based on code attributes, carrying out code reconstruction on a code file to be reconstructed according to the repeated code file, and carrying out code reconstruction by automatically extracting a repeated codebook in the code file to be reconstructed, so that repeated redundant parts in the code file to be reconstructed are quickly extracted, the situation that files which are not extracted are omitted is avoided, the code reconstruction speed is increased, the code reconstruction time is shortened, and the code reconstruction efficiency is improved.
Drawings
Fig. 1 is a flowchart of a code reconstruction method according to an 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 reconstructing apparatus 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 present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
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, and is particularly applicable to the case of reconstructing codes with obvious characteristics of code structure (such as codes based on selenium + testng or other existing frameworks, which are applied to long-time code accumulation and excessive repetition of the same code beginning or ending characteristics). The method may be performed by a code reconstruction device, which may be implemented in software and/or hardware, for example, which may be configured in a computer apparatus. As shown in fig. 1, the method includes:
and 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 reconfiguration instruction may be a user-initiated instruction for instructing to perform code reconfiguration. For example, after adding code file information to be reconstructed to an operation terminal, a user may click a code reconstruction control to trigger a code reconstruction request, after detecting the code reconstruction request initiated by the user, the operation terminal obtains information (such as the code file information to be reconstructed and user information) associated with the code reconstruction request and the like to generate a code reconstruction instruction, and sends the code reconstruction instruction to a code reconstruction device, and after detecting the code reconstruction instruction sent by the operation terminal, the code reconstruction device analyzes the code reconstruction instruction to obtain the code file information to be reconstructed corresponding to the code reconstruction instruction, and further obtains the code file to be reconstructed. The information of the code file to be reconstructed may be a specific file, or may be a 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 can comprise a plurality of test cases, and the same code text exists in at least two test cases.
And S120, extracting the repeated code text in the code file to be reconstructed, and determining the code attribute of the repeated code text.
In the embodiment, the repeated code text in the code file to be reconstructed is extracted through a similar text extraction algorithm. Considering that the repeated code text cannot be used as a common file when the repeated code text is a specific function implementation part, after the repeated code text is extracted, the code attribute of the repeated code text needs to be determined, and whether the corresponding repeated code file is generated to be used as the common file is judged based on the code attribute. The code attribute of the repeated code text can be determined artificially, and can also be determined based on the text characteristics of the repeated code text.
Optionally, the specific similar text extraction algorithm is not limited. Illustratively, text features in a 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 text in the code file to be reconstructed can be directly calculated through the existing similarity calculation method, and the text with the same literal similarity is used as a repeated code text.
In one embodiment of the present invention, extracting a repeated code text in a code file to be reconstructed includes: and inputting the code file to be reconstructed into a pre-constructed text classifier to obtain a repeated code text extracted by the text classifier. Optionally, the repeated code text in the code file to be reconstructed may be extracted by using an existing text classifier (e.g., any classifier such as a naive bayes classifier, a decision tree, a maximum entropy classifier, etc.). 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 the 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 extraction of the repeated code text is quicker and more accurate.
In one embodiment, determining code attributes of 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. Generally, the position of the code in the use case can characterize the properties of the code, for example, the code at the beginning of the use case is generally a reference part and an initialization part, the code at the middle part of the use case is generally an implementation part, and the code at the end of the use case is generally a verification part. It will be appreciated that the reference portion, initialization portion and verification portion may be extracted and called as common text. Optionally, when the repeated code text is at the beginning (for example, the first M lines of the test case) or the end (for example, the last N lines 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 implementation attribute. Determining code attributes of repeated code text based on the location of the repeated code text is logically simple, but may be less accurate.
In one embodiment, determining code attributes of 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 same key words exist in the same part of codes, a key word library of a part corresponding to the code attribute can be preset, after a repeated code text is extracted, the code key words of the repeated code text are extracted, the code key words are matched with the key words in the key word 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 keywords for extracting the repeated code text can be extracted by the existing keyword extraction method, and are not described again here. The accuracy of determining the code attribute of the repeated code text based on the keywords of the repeated code text is high, but the setting of the keyword library is more critical.
And S130, 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.
In the present embodiment, after the code attribute is determined, whether to generate a repeated code file as a common file is determined based on the code attribute until all the repeated code text determinations/generations are completed.
Optionally, generating a repeated code file corresponding to the repeated code text based on the code attribute includes: and when the code attribute is the logic attribute, generating a repeated code file corresponding to the repeated code text. When the code attribute of the repeated code text is the 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 the implementation attribute (i.e. the repeated code text is the implementation code specific to the use case), the repeated code file is not generated as a common file.
The generating of the 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, such as attribute information such as a file name, of the repeated code file corresponding to the repeated code text is determined according to the code attribute of the repeated code text. For example, assuming that the code attribute of the repeated code text is a reference part in the logical attribute, a file name representing the reference part is generated as the file name of the repeated code file, so that the calling/reference relationship is adjusted based on the file name when the subsequent code is combed.
In one embodiment, the code reconstruction of the code file to be reconstructed according to the repeated code file includes: and adjusting the calling logic of the non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file, and completing the 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, after the repeated code text is generated into the repeated code file, the previous reference mode needs to be adjusted to 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, and the code reconstruction of the code file to be reconstructed is completed.
The method and the device for code reconstruction acquire the code file to be reconstructed corresponding to the code reconstruction instruction by responding to the detected code reconstruction instruction; extracting a repeated code text in a code file to be reconstructed, and determining the code attribute of the repeated code text; the method comprises the steps of generating a repeated code file corresponding to a repeated code text based on code attributes, carrying out code reconstruction on a code file to be reconstructed according to the repeated code file, and carrying out code reconstruction by automatically extracting a repeated codebook in the code file to be reconstructed, so that repeated redundant parts in the code file to be reconstructed are quickly extracted, the situation that files which are not extracted are omitted is avoided, the code reconstruction speed is increased, the code reconstruction time is shortened, and the code reconstruction efficiency is improved.
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 the condition that the automatic code framework is unified, the code structure has obvious characteristics, for example, the method is based on the selenium + testng or other existing frameworks, is applied to long-time code accumulation, excessive test cases, the same code beginning or ending is repeated, and the reconstruction is realized and the unified file is extracted.
Fig. 2a is a structural diagram of a code restructuring system according to a second embodiment of the present invention. As shown in fig. 2a, the core of the code restructuring system is 4 modules: the system comprises a reconstruction/optimization code structure, a text classifier, a code extraction module and an automatic code module, wherein 4 modules are independent from each other and cannot knead codes together, and interface-based calling or service calling is called among services.
In general, code input mainly includes automated engineering, including several automated modes, each engineering file for executing automation is independent and is used as the input of a text classifier, and the realized use case part is mainly used as the key input, which is also the part mainly required to be extracted. The text classifier can be implemented using a program that finds the same code section in multiple files, but needs to distinguish whether the repeated section is a code logic section or an implementation section. Code extraction according to the repeated code file obtained in the last step, the repeated code file is extracted respectively according to the similarity and the position of the code appearing in the file, such as a configuration file, a public method, an ending statement and the like. And forming different files according to different code attributes. And the reconstruction/optimization code structure integrally replans the code structure according to the extracted file, and the rest main automatic codes except the extracted part realize logic key combing. And redefining the structure and combing the extracted public file to finally form a neat and complete code structure.
Fig. 2b is a flowchart illustrating a code reconstructing method according to a second embodiment of the present invention. As shown in fig. 2b, the code reconstruction method includes:
(1) firstly, using a use case needing to be reconstructed as an input, and inputting the use case into a text same extractor constructed in advance;
(2) identifying whether extraction is needed or not according to the classification of the automatic use cases;
and comparing the files one by a preset identity classification method.
(3) Extracting the same file, performing text recognition according to the characteristics and the appearance position of the file, and forming a unified file;
such as a method of a print box number, the test case includes a reference part, an initialization part, a method implementation part, and a verification part. The reference part, the initialization part and the verification part can be extracted and customized into configuration files, and calling is only needed when the use case is written.
(4) The code is reconstructed.
After extraction, unified inspection is needed, and definition modification is carried out again. And on the basis of not changing the original test case, the redundant part of each test case is reduced.
According to the embodiment of the invention, the repeated redundant part of the automatic code is extracted quickly through the text similarity algorithm, so that the omission of the unextracted files is avoided, the reconstruction of the code is accelerated, and the reconstruction time is shortened; in addition, the modular construction is adopted, the coupling is low, the maintenance is easy, a certain link has problems, and the positioning can be carried out quickly.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a code reconstructing apparatus according to a third embodiment of the present invention. The code reconstruction apparatus may be implemented in software and/or hardware, for example, the code reconstruction apparatus may be configured in a computer device. As shown in fig. 3, the apparatus includes a file obtaining module 310, a repeated text extracting module 320, and a code reconstructing module 330, wherein:
the file obtaining module 310 is configured to, in response to the detected code reconfiguration instruction, obtain a code file to be reconfigured corresponding to the code reconfiguration instruction;
the repeated text extraction module 320 is used for extracting repeated code texts in the code files to be reconstructed and determining the code attributes of the repeated code texts;
and 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 perform code reconstruction of the code file to be reconstructed according to the repeated code file.
The method comprises the steps that a file acquisition module responds to a detected code reconstruction instruction to acquire a code file to be reconstructed corresponding to the code reconstruction instruction; the repeated text extraction module extracts a repeated code text in the code file to be reconstructed and determines the code attribute of the repeated code text; 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, performs code reconstruction by automatically extracting a repeated codebook in the code file to be reconstructed, realizes rapid extraction of a repeated redundant part in the code file to be reconstructed, avoids missing of files which are not extracted, accelerates the code reconstruction speed, shortens the code reconstruction time, and improves the code reconstruction efficiency.
Optionally, on the basis of 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 a repeated code text extracted by the text classifier.
Optionally, on the basis of 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, on the basis of 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, on the basis of the foregoing scheme, the code reconfiguration module 330 is specifically configured to:
and when the code attribute is the logic attribute, generating a repeated code file corresponding to the repeated code text.
Optionally, on the basis of the foregoing scheme, the code reconfiguration 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, on the basis of the foregoing scheme, the code reconfiguration module 330 is specifically configured to:
and adjusting the calling logic of the non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file, and completing the 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 corresponding functional modules and beneficial effects of the execution method.
Example four
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 present invention. The computer device 412 shown in FIG. 4 is only one example and should not impose any limitations on the functionality or scope of use of embodiments of the present 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, and a bus 418 that couples the various system components (including the system memory 428 and the processors 414).
Bus 418 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and processor 414 or a local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, 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 and write to non-removable, nonvolatile magnetic media (not shown in FIG. 4, and commonly referred to as a "hard drive"). Although not shown in FIG. 4, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 418 by one or more data media interfaces. Memory 428 can include at least one program product having a set (e.g., at least one) of program modules that are 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, for instance, in 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 of which examples or some combination thereof may comprise an implementation of a network environment. The program modules 442 generally perform the functions and/or methodologies of 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.), with one or more devices that enable a user to interact with the computer device 412, and/or with 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 via input/output (I/O) interfaces 422. Also, computer device 412 may communicate with one or more networks (e.g., 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 the other modules of computer device 412 over bus 418. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the computer device 412, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
The processor 414 executes various functional applications and data processing by executing programs stored in the system memory 428, for example, to implement a code reconstruction method provided by an embodiment of the present invention, the method including:
responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
extracting a 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.
Of course, those skilled in the art can understand that the processor can also implement the technical solution of the code reconstruction method provided by any embodiment of the present invention.
EXAMPLE five
The fifth embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the code reconstruction method provided in the fifth embodiment of the present invention, and the method includes:
responding to the detected code reconstruction instruction, and acquiring a code file to be reconstructed corresponding to the code reconstruction instruction;
extracting a 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.
Of course, the computer program stored on the computer-readable storage medium provided by the embodiments of the present invention is not limited to the above method operations, and may also perform the operations related to the code reconstruction method provided by any embodiments of the present invention.
Computer storage media for embodiments of the invention may employ 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. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination 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 the context of 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.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. 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 for aspects 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 + +, or the like, as well as 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 type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments illustrated 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, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (10)

1. A method for 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 a 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.
2. The method according to claim 1, wherein the 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 a repeated code text extracted by the text classifier.
3. The method of claim 1, wherein determining the code attribute 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 determining the code attribute 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. The method of claim 1, wherein generating the repetition code file corresponding to the repetition code text based on the code attribute comprises:
and when the code attribute is a logic attribute, generating a repeated code file corresponding to the repeated code text.
6. The method of claim 5, wherein generating the repetition code file corresponding to the repetition code text comprises:
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.
7. The method according to claim 6, wherein the performing code reconstruction of the code file to be reconstructed from the repeated code file comprises:
and adjusting the calling logic of the non-repeated code text in the code file to be reconstructed based on the file attribute of the repeated code file to complete the code reconstruction of the code file to be reconstructed.
8. A code reconstructing 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 the 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 reconstructing the code of the code file to be reconstructed according to the repeated code file.
9. A computer device, the device comprising:
one or more processors;
storage means for storing 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-7.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out a method for reconstructing code according to any one of claims 1 to 7.
CN202110534889.1A 2021-05-17 2021-05-17 Code reconstruction method, device, equipment and storage medium Pending CN113238796A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110534889.1A CN113238796A (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 CN113238796A (en) 2021-05-17 2021-05-17 Code reconstruction method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113238796A true CN113238796A (en) 2021-08-10

Family

ID=77134697

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN113238796A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
CN110162335A (en) * 2019-04-26 2019-08-23 深圳壹账通智能科技有限公司 Code refactoring method, apparatus, computer equipment and medium
CN110196952A (en) * 2019-05-30 2019-09-03 百度时代网络技术(北京)有限公司 Search processing method, device, equipment and the storage medium of program code
CN111722873A (en) * 2020-07-23 2020-09-29 腾讯科技(深圳)有限公司 Code reconstruction method, device, equipment and medium
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
CN112199117A (en) * 2020-09-23 2021-01-08 建信金融科技有限责任公司 Repeated code processing method and device, electronic equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
CN110162335A (en) * 2019-04-26 2019-08-23 深圳壹账通智能科技有限公司 Code refactoring method, apparatus, computer equipment and medium
CN110196952A (en) * 2019-05-30 2019-09-03 百度时代网络技术(北京)有限公司 Search processing method, device, equipment and the storage medium of program code
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
CN112199117A (en) * 2020-09-23 2021-01-08 建信金融科技有限责任公司 Repeated code processing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN109002510B (en) Dialogue processing method, device, equipment and medium
US11321122B2 (en) Method, apparatus, device and medium for processing topological relation of tasks
CN106960219B (en) Picture identification method and device, computer equipment and computer readable medium
CN111026470B (en) System and method for verification and conversion of input data
CN109359194B (en) Method and apparatus for predicting information categories
CN108776696B (en) Node configuration method and device, storage medium and electronic equipment
CN110888720A (en) Task processing method and device, computer equipment and storage medium
CN109947924B (en) Dialogue system training data construction method and device, electronic equipment and storage medium
CN111736840A (en) Compiling method and running method of applet, storage medium and electronic equipment
US20200327043A1 (en) System and a method for automated script generation for application testing
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
CN114398673A (en) Application compliance detection method and device, storage medium and electronic equipment
CN109684207B (en) Method and device for packaging operation sequence, electronic equipment and storage medium
US9208046B2 (en) Method and system for optimizing testing efforts in system of systems testing
CN107992457B (en) Information conversion method, device, terminal equipment and storage medium
CN115795059A (en) Threat modeling method and system for agile development
CN116360735A (en) Form generation method, device, equipment and medium
CN113238796A (en) Code reconstruction method, device, equipment and storage medium
CN113190462A (en) Dynamic data debugging method, device and equipment
CN112329429A (en) Text similarity learning method, device, equipment and storage medium
CN113032256A (en) Automatic test method, device, computer system and readable storage medium
CN111400623A (en) Method and apparatus for searching information
CN111291186A (en) Context mining method and device based on clustering algorithm and electronic equipment
US11586822B2 (en) Adaptation of regular expressions under heterogeneous collation rules

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