Code recommendation and assembly method and device, equipment and medium

By acquiring contextual representations of code snippets and performing multi-dimensional quality assessments, and utilizing pre-trained models and dynamic optimization mechanisms, intelligent and real-time code assembly is achieved. This solves the problems of coarse recommendation granularity and insufficient contextual understanding in existing tools, thereby improving code development efficiency and quality.

CN121680803APending Publication Date: 2026-03-17CERNET CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511847540.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-09
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

Existing code development tools are coarse in their recommendations, making it difficult to combine multiple code snippets. They lack contextual understanding and proactive assembly capabilities, resulting in low writing efficiency and a high risk of errors.

Method used

By acquiring the contextual representation of code snippets, multi-dimensional quality assessment is performed. Using pre-trained large code models and dynamic optimization mechanisms, code snippets are acquired from the knowledge base and automatically or semi-automatically assembled. Combined with symbolic execution, code style models, and static analysis tools for detection, intelligent and real-time code assembly is achieved.

Benefits of technology

It significantly improves the efficiency and quality of code development, and can accurately recommend and automatically assemble code snippets based on context, solving the problem of lack of dynamic adjustment and active assembly in traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121680803A_ABST
    Figure CN121680803A_ABST
Patent Text Reader

Abstract

The invention provides a code recommendation and assembly method and device, equipment and a medium, and the method comprises the steps: obtaining a currently written code snippet in an editor, and carrying out the context sensing of the currently written code snippet, and obtaining the context representation of the currently written code snippet; performing quality iterative evaluation based on the context representation to obtain quality information used for representing code quality; obtaining at least one candidate code snippet from a knowledge base based on the context representation and the quality information; determining at least one target code snippet from the at least one candidate code snippet based on the user intention; and inserting the at least one target code snippet into the target position of the currently written code snippet to obtain a to-be-recommended code.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of computer software engineering and artificial intelligence, in particular to a code recommendation and assembly method, device, equipment and medium. BACKGROUND

[0002] With the rapid development of the software industry, the scale of software development is increasingly large and the complexity is continuously increasing. Developers need to deal with a large amount of knowledge base, framework and third-party library, which brings great challenges to the writing, searching and integration of code. The traditional code development method mainly relies on the experience, memory and manual search of the developer, which is low in efficiency and prone to errors.

[0003] At present, there are some code completion or recommendation tools on the market, such as code prompt based on static analysis, simple association based on history record, etc. These tools improve the coding speed to some extent, but have obvious limitations.

[0004] Coarse recommendation granularity: Most tools can only provide single function, variable or statement level suggestions, and it is difficult to deal with complex logic or specific patterns that require the combination of multiple code segments.

[0005] Insufficient understanding of context: The understanding of the existing tools for the context of the code often stays at the syntax level, and it is difficult to accurately grasp the intention of the developer currently writing the code, the business logic or the design pattern.

[0006] Lack of active assembly capability: Most tools only stay at the "recommendation" level, and the developer needs to manually select and splice the code, and the recommended code segments cannot be automatically assembled into a complete code unit according to the context. SUMMARY

[0007] In view of the above problems, the present disclosure provides a code recommendation and assembly method, device, equipment and medium, which at least partially solves the above technical problems.

[0008] According to a first aspect of an embodiment of the present disclosure, a code recommendation and assembly method is provided, comprising: obtaining a currently written code segment in an editor, performing context perception on the currently written code segment to obtain a context representation of the currently written code segment; performing quality iterative evaluation based on the context representation to obtain quality information for representing code quality; obtaining at least one candidate code segment from a knowledge base based on the context representation and the quality information; determining at least one target code segment from the at least one candidate code segment based on a user intention; inserting the at least one target code segment into a target position of the currently written code segment to obtain a code to be recommended.

[0009] According to embodiments of this disclosure, context awareness is performed on the currently written code snippet to obtain a context representation of the currently written code snippet, including: using natural language processing to identify code comments, variable names, and function names in the currently written code snippet, and extracting semantic information; obtaining relevant information about the project to which the currently written code snippet belongs, including at least one of the following: project structure, dependency libraries, configuration files, and existing knowledge bases; and generating a multi-dimensional context representation based on code comments, variable names, function names, semantic information, and relevant information.

[0010] According to embodiments of this disclosure, quality iterative evaluation based on context representation is performed to obtain quality information characterizing code quality, including: constructing a detection environment based on context representation; performing multi-dimensional quality detection based on the detection environment, the multi-dimensional quality detection including correctness detection, readability detection, performance detection and security detection; and aggregating the detection results of correctness detection, readability detection, performance detection and security detection according to weights and performing online incremental learning to obtain quality information.

[0011] According to embodiments of this disclosure, a detection environment is constructed based on context representation, including: configuring a symbolic execution engine, a code style model, a complexity analysis tool, and a static analysis tool based on context representation to construct the detection environment. Multi-dimensional quality detection is performed based on the detection environment, including: verifying logical path coverage and boundary conditions through the symbolic execution engine for correctness detection; checking naming conventions and code formatting through the code style model for readability detection; analyzing time complexity and resource usage patterns through the complexity analysis tool for performance detection; and statically scanning for vulnerabilities through the static analysis tool for security detection.

[0012] According to embodiments of this disclosure, the preset weights of the correctness detection results, readability detection results, performance detection results, and security detection results are adjusted based on context representation; the syntactic structural features and business semantic features in the context representation are used as annotation labels for online incremental learning.

[0013] According to embodiments of this disclosure, inserting at least one target code fragment into the target position of a currently written code fragment to obtain code to be recommended includes: analyzing the potential relationships between at least one target code fragment and the integration point between at least one target code fragment and the currently written code fragment; the potential relationships include function call relationships, data transfer relationships, and logical order; and inserting at least one target code fragment into the target position of the currently written code fragment based on the potential relationships and the integration point to obtain code to be recommended.

[0014] According to embodiments of this disclosure, the method further includes: updating the knowledge base using the code to be recommended.

[0015] A second aspect of this disclosure provides a code recommendation and assembly apparatus, comprising: a perception module for acquiring a currently written code fragment in an editor, performing context awareness on the currently written code fragment to obtain a context representation of the currently written code fragment; an evaluation module for performing iterative quality evaluation based on the context representation to obtain quality information characterizing code quality; an acquisition module for acquiring at least one candidate code fragment from a knowledge base based on the context representation and the quality information; a determination module for determining at least one target code fragment from at least one candidate code fragment based on user intent; and an insertion module for inserting at least one target code fragment into a target position of the currently written code fragment to obtain code to be recommended.

[0016] A third aspect of this disclosure provides an electronic device, including: one or more processors; and a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method described above.

[0017] A fourth aspect of this disclosure also provides a computer-readable storage medium having a computer program or instructions stored thereon, which, when executed by a processor, implement the steps of the above-described method.

[0018] A fifth aspect of this disclosure also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described method.

[0019] The code recommendation and assembly method according to embodiments of this disclosure achieves intelligent and real-time code assembly through a pre-trained large code model and a dynamic optimization mechanism, significantly improving the problem that traditional code assembly methods, which are usually based on static rules or templates and lack dynamic adjustment capabilities. This method is a more intelligent, proactive, and developer-intent-aware code assistance method that can accurately recommend the required code fragments based on context and automatically or semi-automatically assemble these fragments into executable code, thereby significantly improving development efficiency and code quality. Attached Figure Description

[0020] The foregoing contents, as well as other objects, features, and advantages of this disclosure, will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:

[0021] Figure 1 The illustrations depict application scenarios of code recommendation and assembly methods, apparatus, devices, media, and program products according to embodiments of this disclosure.

[0022] Figure 2A flowchart illustrating a code recommendation and assembly method according to an embodiment of the present disclosure is shown schematically;

[0023] Figure 3 A schematic diagram illustrating the code recommendation and assembly method according to an embodiment of the present disclosure is provided.

[0024] Figure 4 A schematic diagram illustrating the working principle of a knowledge base according to an embodiment of the present disclosure is shown.

[0025] Figure 5 A schematic diagram illustrating a context-aware principle according to an embodiment of the present disclosure is shown.

[0026] Figure 6 A schematic diagram illustrating the structure of a code recommendation and assembly apparatus according to an embodiment of the present disclosure is shown.

[0027] Figure 7 A block diagram schematically illustrates an electronic device suitable for implementing a code recommendation and assembly method according to an embodiment of the present disclosure. Detailed Implementation

[0028] The embodiments of the present disclosure will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the disclosure. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of the present disclosure for ease of explanation. However, it will be apparent that one or more embodiments may be practiced without these specific details. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concepts of the present disclosure.

[0029] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this disclosure. The terms “comprising,” “including,” etc., as used herein indicate the presence of the stated features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.

[0030] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.

[0031] When using expressions such as "at least one of A, B and C", they should generally be interpreted in accordance with the meaning that is commonly understood by those skilled in the art (e.g., "a system having at least one of A, B and C" should include, but is not limited to, a system having A alone, a system having B alone, a system having C alone, a system having A and B, a system having A and C, a system having B and C, and / or a system having A, B and C, etc.).

[0032] In the technical solution disclosed herein, the user information (including but not limited to user personal information, user image information, user device information, such as location information) and data (including but not limited to data used for analysis, stored data, and displayed data) involved are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of related data all comply with relevant laws, regulations, and standards, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entry points for users to choose to authorize or refuse.

[0033] In scenarios involving automated decision-making using personal information, the methods, devices, and systems provided in this disclosure all offer users corresponding entry points for choosing to agree to or reject the automated decision-making results. If the user chooses to reject, the process proceeds to the expert decision-making stage. Here, "automated decision-making" refers to the activity of automatically analyzing and evaluating an individual's behavioral habits, interests, or economic, health, and credit status through computer programs, and then making a decision. Here, "expert decision-making" refers to the activity of making decisions by personnel who specialize in a particular field, possess specialized experience, knowledge, and skills, and have reached a certain level of professional expertise.

[0034] Figure 1 The illustrations depict application scenarios of code recommendation and assembly methods, apparatus, devices, media, and program products according to embodiments of the present disclosure.

[0035] like Figure 1 As shown, application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, a server 105, and a database 106. The network 104 serves as a medium for providing communication links between the first terminal device 101, the second terminal device 102, the third terminal device 103, the server 105, and the database 106. The network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0036] Users can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 and the database 106 via the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as office applications, shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platforms, financial consumer applications, etc. (this is just an example). The database 106 can store a preset knowledge base.

[0037] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0038] Server 105 can be a server that provides various services, such as a backend management server that supports and responds to code recommendation requests sent by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103 (this is just an example). The backend management server can retrieve the set of code snippets that best match the requirements from a structured code snippet library; at the same time, it uses an assembly strategy model to analyze the logical relationships and dependencies between code snippets, and automatically generates and inserts a complete and syntactically correct code unit.

[0039] It should be noted that the code recommendation and assembly method provided in this disclosure embodiment can generally be executed by server 105. Correspondingly, the code recommendation and assembly device provided in this disclosure embodiment can generally be located in server 105. The code recommendation and assembly method provided in this disclosure embodiment can also be executed by a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105. Correspondingly, the code recommendation and assembly device provided in this disclosure embodiment can also be located in a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105.

[0040] It should be understood that Figure 1 The number of terminal devices, networks, servers, and databases shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, servers, and databases can be included.

[0041] The following will be based on Figure 1 The described scene, through Figures 2-5 The code recommendation and assembly method of the disclosed embodiments are described in detail.

[0042] Figure 2 A flowchart illustrating a code recommendation and assembly method according to an embodiment of the present disclosure is shown. Figure 3 The schematic diagram illustrates the principle of the code recommendation and assembly method according to an embodiment of the present disclosure.

[0043] like Figure 2 and Figure 3 As shown, the code recommendation and assembly in this embodiment includes operations S210 to S250, and the code recommendation and assembly method can be executed by the server 105.

[0044] In operation S210, the code snippet currently being written in the editor is obtained, and context awareness is performed on the code snippet to obtain the context representation of the code snippet being written.

[0045] In operation S220, quality iterative evaluation is performed based on context representation to obtain quality information used to characterize code quality.

[0046] In operation S230, at least one candidate code snippet is obtained from the knowledge base based on context representation and quality information.

[0047] In operation S240, at least one target code segment is determined from at least one candidate code segment based on the user's intent.

[0048] In operation S250, at least one target code snippet is inserted into the target position of the currently written code snippet to obtain the code to be recommended.

[0049] According to embodiments of this disclosure, a knowledge base may be pre-stored with multiple code snippets, from which different code snippets can be retrieved for application according to different needs.

[0050] Figure 4 A schematic diagram illustrating the working principle of a knowledge base according to an embodiment of this disclosure is shown.

[0051] like Figure 3 and Figure 4 As shown, the knowledge base includes code snippets, historical data, and user preferences. Code snippets can be obtained through business logic. The knowledge base integrates multimodal data with natural language processing (NLP) technology, consolidating multi-source information such as images, tables, and text to construct a business logic knowledge base. Through NLP, it extracts text semantics, parses table structures, and recognizes image content, achieving cross-modal data association and knowledge fusion to form a structured knowledge graph. Business modules can accurately call knowledge fields from the knowledge base and simultaneously interact with data to optimize the knowledge base, forming a closed loop of "multimodal data - knowledge accumulation - business empowerment - feedback iteration," thereby improving the personalization and intelligence of educational services.

[0052] In some embodiments, context awareness is performed on the currently written code snippet to obtain a context representation of the currently written code snippet, including: using natural language processing to identify code comments, variable names, and function names in the currently written code snippet and extracting semantic information; obtaining relevant information about the project to which the currently written code snippet belongs, including at least one of the following: project structure, dependency libraries, configuration files, and existing knowledge bases; and generating a multi-dimensional context representation based on code comments, variable names, function names, semantic information, and relevant information.

[0053] Figure 5 A schematic diagram illustrating a context-aware principle according to an embodiment of the present disclosure is shown.

[0054] like Figure 5 As shown, the code snippet being written by the developer in the current editor can be obtained, which may be part or all of the current code file. This can include class definitions, function definitions, variable declarations, etc. Natural language processing techniques are used to parse code comments, variable names, function names, etc., to extract potential semantic information. Then, relevant information about the current project or engineering is obtained, such as project structure, dependency libraries, configuration files, and existing knowledge bases. Combining the above information, a multi-dimensional code context representation is constructed for subsequent intent understanding and code recommendation.

[0055] In some embodiments, iterative quality evaluation based on context representation is performed to obtain quality information characterizing code quality, including: constructing a detection environment based on context representation; performing multi-dimensional quality detection based on the detection environment, the multi-dimensional quality detection including correctness detection, readability detection, performance detection and security detection; and aggregating the detection results of correctness detection, readability detection, performance detection and security detection by weight and performing online incremental learning to obtain quality information.

[0056] Furthermore, a detection environment is constructed based on context representation, including configuring a symbolic execution engine, code style model, complexity analysis tool, and static analysis tool based on context representation to construct the detection environment.

[0057] Multi-dimensional quality testing is conducted based on the testing environment, including: verifying logical path coverage and boundary conditions through a symbolic execution engine for correctness testing; checking naming conventions and code format through a code style model for readability testing; analyzing time complexity and resource usage patterns through complexity analysis tools for performance testing; and statically scanning for vulnerabilities through static analysis tools for security testing.

[0058] For example, detection tools (such as symbolic execution engines and static analyzers) need to configure detection rules based on the contextual characteristics of the current code (such as function call relationships and variable scope). Multidimensional context vectors provide context-aware initialization parameters for detection tools by encoding the syntactic structure of the code (such as AST abstract syntax tree) and business intent (such as requirement descriptions in comments), which can avoid the "one-size-fits-all" approach of traditional static analysis.

[0059] In some embodiments, the preset weights of the correctness detection results, readability detection results, performance detection results, and security detection results are adjusted based on context representation.

[0060] For example, online incremental learning can be performed by aggregation based on weights (correctness: 0.4 / readability: 0.2 / performance: 0.3 / security: 0.1). By adding an online incremental learning process, the dynamic context acquisition and iterative evaluation modules can interact. This also allows the knowledge base to include new code information, improving the accuracy of the AI ​​model. The quality evaluation matrix also has a dynamic adjustment mechanism, forming a "evaluation-feedback-optimization" closed loop. The evaluation results of new code are used as training samples, input into the incremental learning model, and the rule base of the detection tool is updated, making the matrix adapt to the features of new code, forming a "evaluation data-model optimization-matrix adjustment" closed loop, continuously improving the timeliness of the evaluation matrix.

[0061] The weights (correctness: 0.4 / readability: 0.2 / performance: 0.3 / security: 0.1) are not fixed and can be adjusted in a context-sensitive manner using multi-dimensional context vectors.

[0062] For example, the business intent labels in the context vector (such as "high-concurrency scenario" or "financial transaction") can dynamically adjust the dimension weights. For instance, if the current code is detected to belong to payment logic, the security weight increases from 0.1 to 0.4, while the readability weight decreases (because security takes precedence over naming conventions).

[0063] For example, the stability stage of the code can be determined by checking the code history modification records in the context vector (such as whether it is a newly developed module). If it is the initial version of the code, the weight of correctness detection is increased (0.6), and the weight of performance optimization is reduced (0.1) to avoid premature optimization.

[0064] In some embodiments, syntactic structural features and business semantic features in the context representation are used as annotation labels for online incremental learning.

[0065] According to embodiments of this disclosure, the incremental learning model can optimize evaluation rules based on labeled data, with multidimensional context vectors providing multidimensional labels in the process.

[0066] Using syntactic structural features (such as nested loop depth) and business semantic features (such as those involving user privacy) from the context vectors as annotation labels helps the model learn "which context features are strongly correlated with specific quality issues (such as performance bottlenecks)". For example, the model finds that the context combination of "nested loops + large dataset operations" often leads to performance problems, and will proactively strengthen the performance analysis of such code during subsequent detection.

[0067] Quality assessment results (such as "SQL injection vulnerability exists") can be associated and stored with information such as dependency library versions and code locations in the context vector to form a "context-problem-solution" triple knowledge for subsequent closed-loop optimization.

[0068] In some embodiments, the code snippet that best matches the developer's intent is searched in a knowledge base. Matching considers not only textual similarity but also factors such as functionality, contextual applicability, performance, and readability. The retrieved candidate code snippets are sorted and filtered, prioritizing high-quality snippets that best fit the current context. User-weighted sorting can be incorporated. Several (e.g., Top-N) candidate code snippets are presented to the developer, each accompanied by a brief description or contextual matching score.

[0069] In some embodiments, inserting at least one target code fragment into the target position of the currently written code fragment to obtain code to be recommended includes: analyzing the potential relationships between at least one target code fragment and the integration point between at least one target code fragment and the currently written code fragment; the potential relationships include function call relationships, data transfer relationships, and logical order; and inserting at least one target code fragment into the target position of the currently written code fragment based on the potential relationships and the integration point to obtain code to be recommended.

[0070] The process is rational: the developer selects one or more code snippets from the recommended list; the system receives the developer's selection and obtains detailed information about the selected code snippets, including snippet content, required parameters, and possible dependencies; the system analyzes the potential relationships between the selected code snippets (e.g., function call relationships, data transfer relationships, logical order, etc.) and their integration points with the currently edited code; based on the analysis results, the system automatically or semi-automatically generates an assembly script or instructions. During automatic assembly, the system directly inserts the code snippets into the appropriate positions in the current code according to the analyzed logical order and format requirements, and handles necessary parameter passing, variable declarations, dependency imports, etc.; the assembled code is then displayed to the developer for confirmation or further editing. The assembly process may include code formatting, syntax checking, and other steps to ensure that the generated code conforms to specifications and is free of basic syntax errors.

[0071] In some embodiments, the method further includes updating the knowledge base using the code to be recommended.

[0072] The assembled code snippets to be recommended can be used to update the knowledge base, forming a closed loop of the entire process of "context awareness → evaluation → recommendation → assembly → optimization".

[0073] Based on the above code recommendation and assembly method, this disclosure also provides a code recommendation and assembly apparatus. The following will be combined with... Figure 6 The device is described in detail.

[0074] Figure 6 A schematic block diagram of a code recommendation and assembly apparatus according to an embodiment of the present disclosure is shown.

[0075] like Figure 6As shown, the code recommendation and assembly device 600 of this embodiment includes a sensing module 610, an evaluation module 620, an acquisition module 630, a determination module 640, and an insertion module 650.

[0076] The perception module 610 is used to obtain the currently written code fragment in the editor, perform context awareness on the currently written code fragment, and obtain the context representation of the currently written code fragment. In one embodiment, the perception module 610 can be used to perform the operation S210 described above, which will not be repeated here.

[0077] Evaluation module 620 is used to perform iterative quality evaluation based on context representation to obtain quality information characterizing code quality. In one embodiment, evaluation module 620 can be used to perform the operation S220 described above, which will not be repeated here.

[0078] The acquisition module 630 is used to acquire at least one candidate code fragment from the knowledge base based on context representation and quality information. In one embodiment, the acquisition module 630 can be used to perform the operation S230 described above, which will not be repeated here.

[0079] The determining module 640 is configured to determine at least one target code segment from at least one candidate code segment based on user intent. In one embodiment, the determining module 640 may be used to perform the operation S240 described above, which will not be repeated here.

[0080] The insertion module 650 is used to insert at least one target code fragment into the target position of the currently written code fragment to obtain the code to be recommended. In one embodiment, the insertion module 650 can be used to perform the operation S250 described above, which will not be repeated here.

[0081] According to embodiments of this disclosure, context awareness is performed on the currently written code snippet to obtain a context representation of the currently written code snippet, including: using natural language processing to identify code comments, variable names, and function names in the currently written code snippet, and extracting semantic information; obtaining relevant information about the project to which the currently written code snippet belongs, including at least one of the following: project structure, dependency libraries, configuration files, and existing knowledge bases; and generating a multi-dimensional context representation based on code comments, variable names, function names, semantic information, and relevant information.

[0082] According to embodiments of this disclosure, quality iterative evaluation based on context representation is performed to obtain quality information characterizing code quality, including: constructing a detection environment based on context representation; performing multi-dimensional quality detection based on the detection environment, the multi-dimensional quality detection including correctness detection, readability detection, performance detection and security detection; and aggregating the detection results of correctness detection, readability detection, performance detection and security detection according to weights and performing online incremental learning to obtain quality information.

[0083] According to embodiments of this disclosure, a detection environment is constructed based on context representation, including: configuring a symbolic execution engine, a code style model, a complexity analysis tool, and a static analysis tool based on context representation to construct the detection environment; and performing multi-dimensional quality detection based on the detection environment, including: verifying logical path coverage and boundary conditions through the symbolic execution engine to perform correctness detection; checking naming conventions and code format through the code style model to perform readability detection; analyzing time complexity and resource usage patterns through the complexity analysis tool to perform performance detection; and statically scanning for vulnerabilities through the static analysis tool to perform security detection.

[0084] According to embodiments of this disclosure, the preset weights of the correctness detection results, readability detection results, performance detection results, and security detection results are adjusted based on context representation; the syntactic structural features and business semantic features in the context representation are used as annotation labels for online incremental learning.

[0085] According to embodiments of this disclosure, inserting at least one target code fragment into the target position of a currently written code fragment to obtain code to be recommended includes: analyzing the potential relationships between at least one target code fragment and the integration point between at least one target code fragment and the currently written code fragment; the potential relationships include function call relationships, data transfer relationships, and logical order; and inserting at least one target code fragment into the target position of the currently written code fragment based on the potential relationships and the integration point to obtain code to be recommended.

[0086] According to embodiments of this disclosure, the apparatus further includes an update module for updating the knowledge base using the code to be recommended.

[0087] According to embodiments of this disclosure, any plurality of modules among the sensing module 610, evaluation module 620, acquisition module 630, determination module 640, and insertion module 650 may be combined into one module, or any one of these modules may be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of other modules and implemented in one module. According to embodiments of this disclosure, at least one of the sensing module 610, evaluation module 620, acquisition module 630, determination module 640, and insertion module 650 may be at least partially implemented as hardware circuitry, such as a field-programmable gate array (FPGA), a programmable logic array (PLA), a system-on-a-chip, a system-on-a-substrate, a system-on-package, an application-specific integrated circuit (ASIC), or any other reasonable means of integrating or packaging circuitry, or implemented in software, hardware, or firmware, or in any suitable combination of any of these three implementation methods. Alternatively, at least one of the sensing module 610, evaluation module 620, acquisition module 630, determination module 640, and insertion module 650 may be implemented at least partially as a computer program module that can perform corresponding functions when the computer program module is run.

[0088] Figure 7 A block diagram schematically illustrates an electronic device suitable for implementing a code recommendation and assembly method according to an embodiment of the present disclosure.

[0089] like Figure 7 As shown, an electronic device 700 according to an embodiment of the present disclosure includes a processor 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage portion 708 into a random access memory (RAM) 703. The processor 701 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 701 may also include onboard memory for caching purposes. The processor 701 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.

[0090] RAM 703 stores various programs and data required for the operation of electronic device 700. Processor 701, ROM 702, and RAM 703 are interconnected via bus 704. Processor 701 performs various operations of the method flow according to embodiments of the present disclosure by executing programs in ROM 702 and / or RAM 703. It should be noted that the programs may also be stored in one or more memories other than ROM 702 and RAM 703. Processor 701 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in said one or more memories.

[0091] According to embodiments of this disclosure, the electronic device 700 may further include an input / output (I / O) interface 705, which is also connected to a bus 704. The electronic device 700 may also include one or more of the following components connected to the input / output (I / O) interface 705: an input section 706 including a keyboard, mouse, etc.; an output section 707 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the input / output (I / O) interface 705 as needed. A removable medium 711, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 710 as needed so that computer programs read from it can be installed into the storage section 708 as needed.

[0092] This disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs that, when executed, implement the method according to the embodiments of this disclosure.

[0093] According to embodiments of this disclosure, the computer-readable storage medium can be a non-volatile computer-readable storage medium, such as including, but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of this disclosure, the computer-readable storage medium may include ROM 702 and / or RAM 703 and / or one or more memories other than ROM 702 and RAM 703 described above.

[0094] Embodiments of this disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code enables the computer system to implement the multi-source heterogeneous data augmentation method provided in the embodiments of this disclosure.

[0095] When the computer program is executed by the processor 701, it performs the functions defined in the system / apparatus of this disclosure embodiments. According to embodiments of this disclosure, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.

[0096] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and may be downloaded and installed via the communication section 709, and / or installed from a removable medium 711. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.

[0097] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 709, and / or installed from the removable medium 711. When the computer program is executed by the processor 701, it performs the functions defined in the system of this disclosure embodiment. According to embodiments of this disclosure, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.

[0098] According to embodiments of this disclosure, program code for executing the computer programs provided in embodiments of this disclosure can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, languages ​​such as Java, C++, Python, "C", or similar programming languages. The program code can execute entirely on a user's computing device, partially on a user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0099] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0100] Those skilled in the art will understand that the features described in the various embodiments of this disclosure can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this disclosure. In particular, the features described in the various embodiments of this disclosure can be combined and / or combined in various ways without departing from the spirit and teachings of this disclosure. All such combinations and / or combinations fall within the scope of this disclosure.

[0101] The embodiments of this disclosure have been described above. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of this disclosure. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. Various substitutions and modifications can be made by those skilled in the art without departing from the scope of this disclosure, and all such substitutions and modifications should fall within the scope of this disclosure.

Claims

1. A method of code recommendation and assembly, characterized by, The method comprises: acquiring a currently written code snippet in an editor, performing context awareness on the currently written code snippet to obtain a context representation of the currently written code snippet; performing quality iterative evaluation based on the context representation to obtain quality information for representing code quality; acquiring at least one candidate code snippet from a knowledge base based on the context representation and the quality information; determining at least one target code snippet from the at least one candidate code snippet based on a user intention; inserting the at least one target code snippet into a target position of the currently written code snippet to obtain to-be-recommended code.

2. The method of claim 1, wherein, The context awareness on the currently written code snippet to obtain a context representation of the currently written code snippet comprises: recognizing code comments, variable names, function names in the currently written code snippet and extracting semantic information by using natural language processing; acquiring related information of a project to which the currently written code snippet belongs, the related information comprising at least one of a project structure, a dependent library, a configuration file and an existing knowledge base; generating a multi-dimensional context representation based on the code comments, the variable names, the function names, the semantic information and the related information.

3. The method according to claim 1 or 2, characterized in that, The quality iterative evaluation based on the context representation to obtain quality information for representing code quality comprises: constructing a detection environment based on the context representation; performing multi-dimensional quality detection based on the detection environment, the multi-dimensional quality detection comprising correctness detection, readability detection, performance detection and security detection; performing online incremental learning by aggregating detection results of the correctness detection, detection results of the readability detection, detection results of the performance detection and detection results of the security detection according to weights to obtain the quality information.

4. The method of claim 3, wherein, The construction of the detection environment based on the context representation comprises: configuring a symbolic execution engine, a code style model, a complexity analysis tool and a static analysis tool based on the context representation to construct the detection environment; The multi-dimensional quality detection based on the detection environment comprises: verifying logical path coverage and boundary conditions by the symbolic execution engine to perform correctness detection; checking naming specification and code format by the code style model to perform readability detection; analyzing time complexity and resource usage mode by the complexity analysis tool to perform performance detection; statically scanning vulnerabilities by the static analysis tool to perform security detection.

5. The method of claim 3, wherein, Adjusting respective preset weights of detection results of correctness detection, detection results of readability detection, detection results of performance detection and detection results of security detection based on the context representation; Taking syntax structure features and business semantic features in the context representation as annotation labels to perform online incremental learning.

6. The method of claim 1, wherein, The insertion of the at least one target code snippet into a target position of the currently written code snippet to obtain to-be-recommended code comprises: analyzing potential relationships of the at least one target code snippet and integration points of the at least one target code snippet with the currently written code snippet; the potential relationships include function call relationships, data transmission relationships, and logical sequences; inserting the at least one target code snippet into a target position of the currently written code snippet based on the potential relationships and the integration points, to obtain recommended code.

7. The method of claim 1, wherein, The method further includes: updating the knowledge base by using the recommended code.

8. A code recommendation and assembly apparatus, characterized by, The device includes: a perception module configured to obtain a currently written code snippet in an editor, and perform context perception on the currently written code snippet to obtain a context representation of the currently written code snippet; an evaluation module configured to perform quality iterative evaluation based on the context representation to obtain quality information for representing code quality; an obtaining module configured to obtain at least one candidate code snippet from a knowledge base based on the context representation and the quality information; a determination module configured to determine at least one target code snippet from the at least one candidate code snippet based on a user intention; an insertion module configured to insert the at least one target code snippet into a target position of the currently written code snippet to obtain recommended code. 9.An electronic device, comprising: one or more processors; a memory for storing one or more computer programs, characterized in that the one or more processors execute the one or more computer programs to implement steps of the method according to any one of claims 1-7.

10. A computer readable storage medium having stored thereon a computer program or instructions, characterized in that, The computer program or instructions are executed by the processor to implement steps of the method according to any one of claims 1-7.