Code recommendation method and device, electronic equipment and medium

CN116501307BActive Publication Date: 2026-09-25BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310423162.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-19
Publication Date
2026-09-25
Estimated Expiration
2043-04-19

AI Technical Summary

Technical Problem

[0003]在该场景下,为用户推荐的代码与用户编辑的代码之间可能存在格式上的差异,进而导致用户体验感欠佳

Benefits of technology

[0010]应当理解,本部分所描述的内容并非旨在标识本公开的实施例的关键或重要特征,也不用于限制本公开的范围。本公开的其它特征将通过以下的说明书而变得容易理解。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116501307B_ABST
    Figure CN116501307B_ABST
Patent Text Reader

Abstract

The disclosure provides a code recommendation method and device, electronic equipment and medium, relating to the field of artificial intelligence such as natural language processing. The method comprises: obtaining a recommended code segment at a code recommendation position of an original code segment; obtaining remaining code segments in the original code segment after the code recommendation position; identifying target symbols required for code fusion operation in the recommended code segment and the remaining code segments; and fusing the recommended code segment and the remaining code segments according to the target symbols to obtain a target recommended code segment recommended to the original code segment. In the disclosure, the difference between the format of the target recommended code segment and the format of the original code segment is reduced, the consistency of the format of the target recommended code segment and the original code segment is achieved, the possibility of the user adopting the target recommended code segment is improved, and the user experience is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure pertains to the field of code recommendation, and particularly to artificial intelligence fields such as natural language processing. Background Technology

[0002] During code editing, when the editing operation meets the preset code recommendation trigger conditions, the code recommendation tool in the relevant technology will recommend code to the user. The code recommended by the code recommendation tool may be displayed in the middle of the code line.

[0003] In this scenario, there may be formatting differences between the code recommended to the user and the code edited by the user, which may lead to a poor user experience. Summary of the Invention

[0004] This disclosure presents a code recommendation method, apparatus, electronic device, and medium.

[0005] According to a first aspect of this disclosure, a code recommendation method is proposed, the method comprising: obtaining a recommended code segment at a code recommendation position in an original code segment, wherein the code recommendation position is the line position in the original code segment that triggers the code recommendation requirement; obtaining the remaining code segments in the original code segment located after the code recommendation position; identifying the target symbol required for code fusion operation in the recommended code segment and the remaining code segments; and fusing the recommended code segment and the remaining code segments according to the target symbol to obtain a target recommended code segment recommended to the original code segment.

[0006] According to a second aspect of this disclosure, a service request recommendation apparatus is proposed. The apparatus includes: a first acquisition module, configured to acquire a recommended code segment at a code recommendation position in an original code segment, wherein the code recommendation position is the line position in the original code segment that triggers the code recommendation request; a second acquisition module, configured to acquire the remaining code segments in the original code segment located after the code recommendation position; an identification module, configured to identify the target symbol required for code fusion operation in the recommended code segment and the remaining code segments; and a fusion module, configured to fuse the recommended code segment and the remaining code segments according to the target symbol to obtain a target recommended code segment recommended to the original code segment.

[0007] According to a third aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to said at least one processor; wherein the memory stores instructions executable by said at least one processor, said instructions being executed by said at least one processor to enable said at least one processor to perform the code recommendation method described in the first aspect above.

[0008] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the code recommendation method described in the first aspect above.

[0009] According to a fifth aspect of this disclosure, a computer program product is proposed, comprising a computer program that, when executed by a processor, implements the code recommendation method described in the first aspect above.

[0010] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0011] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:

[0012] Figure 1 This is a flowchart illustrating a code recommendation method according to an embodiment of the present disclosure;

[0013] Figure 2 This is a flowchart illustrating a code recommendation method according to another embodiment of the present disclosure;

[0014] Figure 3 This is a flowchart illustrating a code recommendation method according to another embodiment of the present disclosure;

[0015] Figure 4 This is a flowchart illustrating a code recommendation method according to another embodiment of the present disclosure;

[0016] Figure 5 This is a schematic diagram of the structure of a code recommendation device according to an embodiment of the present disclosure;

[0017] Figure 6 This is a schematic block diagram of an electronic device according to an embodiment of the present disclosure. Detailed Implementation

[0018] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0019] Natural Language Processing (NLP) is an important field within computer science and artificial intelligence. It studies the theories and methods for enabling effective communication between humans and computers using natural language. NLP is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language people use in daily life—and thus has a close relationship with linguistics, but also important differences. NLP is not simply the study of natural language in general, but rather the development of computer systems that can effectively achieve natural language communication.

[0020] Artificial Intelligence (AI) is a new branch of computer science that studies and develops theories, methods, technologies, and application systems to simulate, extend, and expand human intelligence. It attempts to understand the essence of intelligence and produce intelligent machines that can react in a way similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. Since its inception, AI has matured in both theory and technology, and its applications have expanded continuously. It is conceivable that future AI-driven technological products will serve as "containers" of human wisdom. AI can simulate the information processes of human consciousness and thought.

[0021] Figure 1 This is a flowchart illustrating a code recommendation method according to an embodiment of the present disclosure, as shown below. Figure 1 As shown, the method includes:

[0022] S101, obtain the recommended code snippet at the recommended code position of the original code snippet, where the recommended code position is the line position in the original code snippet that triggers the code recommendation requirement.

[0023] In this embodiment of the disclosure, when a user is editing and modifying code, if the editing operation is paused and the pause duration reaches a preset threshold for triggering code recommendation requirements, it can be determined that the code currently being edited and modified by the user has triggered a code recommendation requirement.

[0024] Among these features, the code snippet currently being edited and modified by the user can be identified as the original code snippet.

[0025] Optionally, when the pause duration of the editing operation at a position in the line of the original code snippet reaches a preset duration threshold for triggering code recommendation requirements, that position in the line becomes the code recommendation position in the original code snippet.

[0026] Accordingly, the code snippet recommended and displayed at this code recommendation position is the recommended code snippet of the original code snippet.

[0027] It should be noted that the recommended code snippets can consist of a single line of code or multiple lines of code; no specific limitation is made here.

[0028] S102, retrieve the remaining code snippet located after the recommended code position in the original code snippet.

[0029] In this embodiment of the disclosure, the recommended code position is the middle position of the original code snippet.

[0030] In this scenario, there is a code snippet after the code recommendation position. The code snippet that exists after the code recommendation position in the original code snippet can be marked as the remaining code snippet.

[0031] S103, Identify the target symbols required for code fusion operations in the recommended code snippets and the remaining code snippets.

[0032] In this embodiment of the disclosure, there may be differences in format between the recommended code snippet and the remaining code snippets.

[0033] In this scenario, the format of the recommended code snippets and the remaining code snippets can be made more consistent by adjusting the code symbols in the recommended code snippets and the remaining code snippets.

[0034] Optionally, the recommended code snippets and the remaining code snippets can be processed using symbol recognition algorithms in related technologies to identify code symbols in the recommended code snippets and the remaining code snippets.

[0035] As an example, code symbols can include delimiters and suffixes, where delimiters can include ",", ",", " / ", and " / / ", etc., and suffixes can include ")", ");", ":", ";", and "}", etc.

[0036] Optionally, the delimiters and suffixes in the recommended code snippets and the remaining code snippets can be identified based on symbol recognition algorithms in related technologies, and the identified delimiters and suffixes can be determined as code symbols in the recommended code snippets and the remaining code snippets.

[0037] In this scenario, the code symbols in the identified recommended code snippets and the remaining code snippets can be compared and analyzed. Based on the analysis results, the separators and suffixes in the recommended code snippets and the remaining code snippets can be filtered to obtain the code symbols needed for code fusion of the recommended code snippets and the remaining code snippets as target symbols.

[0038] S104, the recommended code fragment and the remaining code fragment are fused according to the target symbol to obtain the target recommended code fragment recommended to the original code fragment.

[0039] In this embodiment of the disclosure, after determining the target symbols in the recommended code segment and the remaining code segment, the recommended code segment and the remaining code segment can be fused based on the target symbols.

[0040] Optionally, the recommended code snippet and the remaining code snippet can be joined by a target symbol, and the code snippet obtained by the join operation can be determined as the target recommended code snippet to be recommended to the original code snippet.

[0041] It should be noted that the recommended code snippet and the remaining code snippet are fused based on the target symbol to obtain the target recommended code snippet recommended to the original code snippet. There is no need to limit the length of the recommended code snippet. It can be understood that when the recommended code snippet is multi-line, the code fusion of the recommended code snippet and the remaining code snippet can still be achieved based on the target symbol to obtain the multi-line target recommended code snippet recommended to the original code snippet.

[0042] The code recommendation method proposed in this disclosure obtains the recommended code segment at the code recommendation position corresponding to the line position of the original code segment, as well as the remaining code segments in the original code segment located after the code recommendation position. It then identifies the target symbol required for code fusion between the recommended and remaining code segments. Accordingly, it fuses the recommended and remaining code segments based on the target symbol to obtain the target recommended code segment. This disclosure achieves multi-line code recommendation by identifying the target symbol and fusing the recommended and remaining code segments based on the target symbol. This reduces the difference in format between the target recommended code segment and the original code segment, achieves consistency in format between the target recommended code segment and the original code segment, increases the likelihood of users adopting the target recommended code segment, and optimizes the user experience.

[0043] In the above embodiments, the acquisition of target symbols required for code fusion can be combined with... Figure 2 To understand further, Figure 2 This is a flowchart illustrating a code recommendation method according to another embodiment of this disclosure, as shown below. Figure 2 As shown, the method includes:

[0044] S201, retrieve candidate delimiters and candidate suffixes from the recommended code snippets and the remaining code snippets.

[0045] In this embodiment of the disclosure, a preset recommended code snippet and a set of all delimiters and suffixes that may be included in the remaining code snippets can be obtained.

[0046] The complete set of separators can include “,”, “,”, “ / ” and “ / / ”, and the complete set of suffixes can include “)”, “);”, “):”, “;” and “}”, without specific limitations here.

[0047] Optionally, based on the obtained delimiter set and suffix set, the delimiters and suffixes present in the recommended code fragments and the remaining code fragments can be identified using a symbol recognition algorithm in related technologies. Then, the delimiters and suffixes present in the recommended code fragments and the remaining code fragments can be identified as candidate delimiters and candidate suffixes, respectively.

[0048] As an example, the candidate delimiters and candidate suffixes present in the recommended code snippet and the remaining code snippet may include: the suffix of the remaining code snippet, the suffix of the recommended code snippet, the middle delimiter of the recommended code snippet, the last delimiter of the recommended code snippet, the last delimiter of the remaining code snippet, and the first delimiter of the remaining code snippet.

[0049] It should be noted that the candidate delimiters and candidate suffixes present in the recommended code snippets and the remaining code snippets may include the delimiters and suffixes in the above examples, and may also include other suffixes and / or delimiters that may exist in the recommended code snippets and the remaining code snippets, without specific limitations here.

[0050] S202, determine the target delimiter required for code fusion operation from the candidate delimiters.

[0051] In this embodiment of the disclosure, there may be a separator between the recommended code segment and the remaining code segment. In this scenario, the separator to be retained in the target recommended code segment during the code fusion operation can be determined based on the candidate separators identified between the recommended code segment and the remaining code segment, and the separator can be determined as the target separator required for the code fusion operation.

[0052] Optionally, in response to the presence of a post-delimiter of the recommended code snippet and a pre-delimiter of the remaining code snippets among the candidate delimiters, either the post-delimiter or the pre-delimiter is determined as the target delimiter.

[0053] This can be understood as follows: when it is detected that the recommended code snippet has a back delimiter and the remaining code snippet has a front delimiter, either the back delimiter of the recommended code snippet or the front delimiter of the remaining code snippet can be selected as the target delimiter required for code fusion.

[0054] Optionally, in response to the fact that only the recommended code snippet exists as a middle separator in the candidate separators, a middle separator is added at the position after the recommended code snippet or at the position before the remaining code snippets as the target separator.

[0055] This can be understood as follows: when it is detected that the recommended code snippet does not have a post separator, and the remaining code snippet does not have a pre separator, while the recommended code snippet has a middle separator, in order to separate the recommended code snippet from the remaining code snippet, a middle separator can be added to the post separator position corresponding to the recommended code snippet or the pre separator position corresponding to the remaining code snippet. The separator added to either of these two positions is determined as the target separator required for the code fusion operation.

[0056] S203, determine the target suffix from the candidate suffixes for the code fusion operation.

[0057] In this embodiment of the disclosure, the recommended code snippet and the remaining code snippet may contain suffixes. In this scenario, it is necessary to identify the suffixes in the recommended code snippet and the remaining code snippet, and based on the candidate suffixes included in the identified recommended code snippet and the remaining code snippet, determine the target suffix to be retained in the target recommended code snippet during the code fusion operation.

[0058] In scenarios where candidate suffixes include the suffixes of the recommended code snippet:

[0059] Optionally, in response to the presence of a suffix for the recommended code snippet and a suffix for the remaining code snippet among the candidate suffixes, the suffix for the remaining code snippet is determined as the target suffix.

[0060] This can be understood as follows: when both the recommended code snippet and the remaining code snippet have suffixes, the suffixes of the remaining code snippets in the original code snippet need to be retained as the target suffixes to be retained in the target recommended code snippet during the code fusion operation.

[0061] Optionally, in response to the fact that only the recommended code snippet's suffix exists among the candidate suffixes, the suffix of the recommended code snippet is adjusted to the suffix of the remaining code snippets, and the suffix of the remaining code snippets is determined as the target suffix.

[0062] This can be understood as follows: when the recommended code snippet has a suffix but the remaining code snippet does not, the suffix of the recommended code snippet can be adjusted to the corresponding suffix position of the remaining code snippet and used as the suffix of the remaining code snippet. The suffix adjusted to the corresponding suffix position of the remaining code snippet will then be used as the target suffix to be retained in the target recommended code snippet during the code fusion operation.

[0063] In scenarios where candidate suffixes do not include the suffixes of the recommended code snippet:

[0064] Optionally, in response to the existence of a suffix in the remaining code segment among the candidate suffixes and the absence of a suffix in the recommended code segment, the suffix of the remaining code segment is determined as the target suffix.

[0065] This can be understood as follows: when the recommended code snippet does not have a suffix but the remaining code snippet does, the suffix of the remaining code snippet can be retained in the target recommended code snippet and used as the target suffix to be retained in the target recommended code snippet during code fusion.

[0066] Optionally, in response to the absence of a suffix for the recommended code snippet and a suffix for the remaining code snippets among the candidate suffixes, the target suffix is ​​determined to be empty.

[0067] This can be understood as follows: when neither the recommended code snippet nor the remaining code snippets have any suffixes, it can be determined that the target recommended code snippet does not need a suffix. In this scenario, it can be determined that the target suffix is ​​empty.

[0068] S204, define the target delimiter and target suffix as the target symbol.

[0069] In this embodiment of the disclosure, after determining the target delimiter from the candidate delimiters and the target suffix from the candidate suffixes, the target delimiter and the target suffix can be determined as the target symbols required for code fusion of the recommended code snippets and the remaining code snippets.

[0070] As an example, if we set the target delimiter to the post-delimiter of the recommended code snippet and the target suffix to the suffix of the remaining code snippets, then the post-delimiter and suffix are the target symbols required when merging the recommended code snippet and the remaining code snippets.

[0071] The code recommendation method proposed in this disclosure obtains candidate delimiters and candidate suffixes from recommended code snippets and remaining code snippets, and determines the target delimiter from the candidate delimiters and the target delimiter from the candidate suffixes, thereby obtaining the target symbol required for code fusion of recommended and remaining code snippets. In this disclosure, by selecting and determining the target symbol, format conflicts between recommended and remaining code snippets are avoided, achieving format consistency after fusion, thus increasing the likelihood of users adopting the target recommended code snippet and optimizing the user experience.

[0072] In the above embodiments, the fusion of recommended code snippets and remaining code snippets can be combined with... Figure 3 To understand further, Figure 3This is a flowchart illustrating a code recommendation method according to another embodiment of this disclosure, as shown below. Figure 3 As shown, the method includes:

[0073] S301, retrieve the target separator and target suffix from the target symbol.

[0074] S302, delete the remaining delimiters between the recommended code snippet and the remaining code snippet except for the target delimiter, and delete the remaining suffixes in the candidate suffixes except for the target suffix, to obtain the deleted target recommended code snippet and target remaining code snippet.

[0075] In this embodiment of the disclosure, after determining the target delimiter and the target suffix, the recommended code snippet and the remaining code snippet may also contain other remaining delimiters and remaining suffixes.

[0076] In this scenario, the remaining separators and suffixes can be further processed.

[0077] Optionally, when there are residual delimiters other than the target delimiter between the recommended code snippet and the remaining code snippets, these residual delimiters can be deleted.

[0078] As an example, suppose the recommended code snippet has a post-delimiter and the remaining code snippets have a pre-delimiter, where the pre-delimiter of the remaining code snippets is the target delimiter. Then the post-delimiter of the recommended code snippet is the remaining delimiter between the recommended code snippet and the remaining code snippets, excluding the target delimiter.

[0079] In this scenario, the delimiter at the end of the recommended code snippet can be removed.

[0080] Optionally, when the suffix of the recommended code snippet and the suffix of the remaining code snippets are used as the target suffix, the suffix of the recommended code snippet is the remaining suffix among the candidate suffixes excluding the target suffix.

[0081] In this scenario, the remaining suffixes in the candidate suffixes, excluding the target suffix, can be deleted.

[0082] In this embodiment of the disclosure, after deleting the remaining suffixes in the candidate suffixes (excluding the target suffix) and the remaining delimiters between the recommended code segments and the remaining code segments (excluding the target delimiter), the candidate recommended code segments and candidate remaining code segments required for code fusion can be obtained.

[0083] Among them, the candidate recommended code segment is the recommended code segment after deleting the remaining suffixes in the candidate suffixes excluding the target suffix, as well as the remaining delimiters between the recommended code segment and the remaining code segment excluding the target delimiter. The candidate remaining code segment is the remaining code segment after deleting the remaining suffixes in the candidate suffixes excluding the target suffix, as well as the remaining delimiters between the recommended code segment and the remaining code segment excluding the target delimiter.

[0084] S303, concatenate the candidate recommended code fragment, the remaining candidate code fragment, the target separator, and the target suffix in sequence to obtain the target recommended code fragment recommended to the original code fragment.

[0085] Optionally, there is a preset concatenation order among the candidate recommended code snippets, the candidate remaining code snippets, the target separator, and the target suffix.

[0086] Specifically, the candidate recommended code snippet, the remaining candidate code snippet, the target separator, and the target suffix can be concatenated in a pre-defined concatenation order, and the concatenated code snippet can be determined as the target recommended code snippet to be recommended to the original code snippet.

[0087] It should be noted that the recommended code snippet may contain content of remaining code snippets. In response to the inclusion of remaining code snippets in the recommended code snippet, the recommended code snippet is determined to be the target recommended code snippet for the original code snippet.

[0088] This can be understood as follows: when the recommended code snippet includes the code content of the remaining code snippet, there is no need to identify candidate delimiters and candidate suffixes or determine the target symbol for the recommended code snippet and the remaining code snippet.

[0089] In this scenario, the recommended code snippet can be identified as the target recommended code snippet to be recommended to the original code snippet.

[0090] It should be noted that other code snippets can be included after the remaining code snippets. In this scenario, there are certain limitations on the display area that the code triggering position can provide for the target recommended code.

[0091] In this scenario, the first code length of the target recommended code snippet and the second code length of the code replacement region of the original code snippet can be obtained.

[0092] In response to the second code length being less than the first code length, the target recommended code segment is adjusted until the second code length is greater than or equal to the adjusted first code length of the adjusted target recommended code segment.

[0093] This can be understood as follows: when the second code length is greater than or equal to the first code length, it can be determined that the display range of the target recommended code snippet is within the code replacement area corresponding to the original code snippet. In this scenario, when the target recommended code snippet is displayed at the code recommendation position of the original code snippet, it will not affect other code snippets adjacent to the original code snippet.

[0094] Accordingly, when the second code length is less than the first code length, it can be determined that the display range of the target recommended code snippet exceeds the code replacement area corresponding to the original code snippet. In this scenario, when the target recommended code snippet is displayed at the code recommendation position of the original code snippet, it will have a certain impact on other code snippets adjacent to the original code snippet.

[0095] Optionally, the target recommended code snippet can be adjusted, and the adjusted first code length of the adjusted target recommended code snippet can be compared with the second code length.

[0096] When the second code length is greater than or equal to the adjusted first code length, it can be determined that the display range of the adjusted target recommended code snippet is within the code replacement area corresponding to the original code snippet. In this scenario, when the adjusted target recommended code snippet is displayed at the code recommendation position of the original code snippet, it will not affect other code snippets adjacent to the original code snippet.

[0097] The code recommendation method proposed in this disclosure involves obtaining the target delimiter and target suffix, then deleting the remaining delimiters (excluding the target delimiter) between the recommended code snippet and the remaining code snippets, as well as the remaining suffixes (excluding the target suffix) among the candidate suffixes, to obtain candidate recommended code snippets and candidate remaining code snippets. Further, the candidate recommended code snippets, candidate remaining code snippets, target delimiters, and target suffixes are concatenated in sequence to obtain the target recommended code snippet recommended to the original code snippet. In this disclosure, the selection and determination of target symbols avoids format conflicts between the recommended code snippets and the remaining code snippets. Code fusion based on target symbols reduces the difference in format between the target recommended code snippet and the original code snippet, achieving format consistency between the target recommended code snippet and the original code snippet, increasing the likelihood of users adopting the target recommended code snippet, and optimizing the user experience.

[0098] To better understand the above embodiments, it can be combined with Figure 4 , Figure 4 This is a flowchart illustrating a code recommendation method according to another embodiment of the present disclosure, such as... Figure 4 As shown, the method includes:

[0099] Retrieve candidate delimiters and candidate suffixes from the recommended code snippets and the remaining code snippets.

[0100] In scenarios where the candidate delimiter includes both the post-delimiter of the recommended code snippet and the pre-delimiter of the remaining code snippets, either delimiter is determined as the target delimiter.

[0101] In scenarios where candidate delimiters differ, including the latter delimiter of the recommended code snippet and the former delimiter of the remaining code snippets:

[0102] Optionally, when the candidate delimiter only includes the last delimiter of the recommended code snippet, the last delimiter of the recommended code snippet is determined as the target delimiter.

[0103] Optionally, when the candidate delimiter only includes the previous delimiter of the remaining code segment, the previous delimiter of the remaining code segment is determined as the target delimiter.

[0104] Optionally, when the candidate delimiter does not include the post-delimiter of the recommended code snippet or the pre-delimiter of the remaining code snippets, the middle delimiter of the recommended code snippet is obtained, and the target delimiter is obtained based on the middle delimiter of the recommended code snippet.

[0105] In scenarios where candidate suffixes include the suffixes of the recommended code snippet:

[0106] Optionally, if the candidate suffix includes the suffix of the remaining code segment, the suffix of the remaining code segment is determined as the target suffix.

[0107] Optionally, if the candidate suffix does not include the suffix of the remaining code segment, the suffix of the recommended code segment is adjusted to the suffix of the remaining code segment, and the adjusted suffix of the remaining code segment is determined as the target suffix.

[0108] In scenarios where candidate suffixes do not include the recommended code suffix:

[0109] Optionally, if the candidate suffixes do not include the suffixes of the remaining code snippets, the target suffix is ​​determined to be empty.

[0110] Furthermore, based on the obtained target delimiter and target suffix, the recommended code snippet and the remaining code snippet are subjected to symbol adjustment processing to obtain the adjusted candidate recommended code snippet and candidate remaining code snippet. The candidate recommended code snippet, the candidate remaining code snippet, the target delimiter and the target suffix are then concatenated and merged to obtain the target recommended code snippet recommended to the original code snippet.

[0111] It should be noted that the recommended code snippets may contain logical incompleteness. In such cases, the logical integrity of the recommended code snippets can be analyzed using the logical integrity judgment method corresponding to Polish notation in relevant technologies, thereby identifying whether the recommended code snippets are logically complete.

[0112] In cases where the recommended code snippet logic is incomplete, the recommended code snippet may contain a suffix. In this scenario, the target suffix required for code fusion can still be obtained based on the above method. This can be understood as follows: when the candidate suffix includes the suffix of the remaining code snippet, the suffix of the remaining code snippet is determined as the target suffix; when the candidate suffix does not include the suffix of the remaining code snippet, the suffix of the recommended code snippet is adjusted to be the suffix of the remaining code snippet, and then the adjusted suffix of the remaining code snippet is determined as the target suffix.

[0113] The code recommendation method proposed in this disclosure achieves multi-line code recommendation by identifying target symbols and fusing recommended code snippets and remaining code snippets based on target symbols. This reduces the difference between the format of the target recommended code snippet and the original code snippet, achieves consistency between the format of the target recommended code snippet and the original code snippet, increases the likelihood of users adopting the target recommended code snippet, and optimizes the user experience.

[0114] Corresponding to the code recommendation methods proposed in the above embodiments, one embodiment of this disclosure also proposes a code recommendation device. Since the code recommendation device proposed in this disclosure corresponds to the code recommendation methods proposed in the above embodiments, the implementation methods of the above code recommendation methods are also applicable to the code recommendation device proposed in this disclosure, and will not be described in detail in the following embodiments.

[0115] Figure 5 This is a schematic diagram of the structure of a code recommendation device according to an embodiment of the present disclosure, as shown below. Figure 5 As shown, the code recommendation device 500 includes a first acquisition module 51, a second acquisition module 52, an identification module 53, and a fusion module 54, wherein:

[0116] The first acquisition module 51 is used to acquire the recommended code fragment at the code recommendation position of the original code fragment, wherein the code recommendation position is the line position in the original code fragment that triggers the code recommendation requirement;

[0117] The second acquisition module 52 is used to acquire the remaining code segment located after the recommended code position in the original code segment;

[0118] The identification module 53 is used to identify the target symbols required for code fusion operations in the recommended code snippets and the remaining code snippets;

[0119] The fusion module 54 is used to fuse the recommended code fragment and the remaining code fragment according to the target symbol to obtain the target recommended code fragment recommended to the original code fragment.

[0120] In this embodiment of the disclosure, the identification module 53 is further configured to: obtain candidate delimiters and candidate suffixes from the recommended code snippets and the remaining code snippets; determine the target delimiter required for code fusion operation from the candidate delimiters; determine the target suffix required for code fusion operation from the candidate suffixes; and determine the target delimiter and target suffix as target symbols.

[0121] In this embodiment of the disclosure, the identification module 53 is further configured to: in response to the presence of a post-separator of the recommended code fragment and a pre-separator of the remaining code fragment in the candidate separators, determine either the post-separator or the pre-separator as the target separator; in response to the presence of only a middle separator of the recommended code fragment in the candidate separators, add a middle separator at the post-separator position corresponding to the recommended code fragment or the pre-separator position corresponding to the remaining code fragment as the target separator.

[0122] In this embodiment of the disclosure, the identification module 53 is further configured to: in response to the presence of a suffix for the recommended code segment and a suffix for the remaining code segment among the candidate suffixes, determine the suffix for the remaining code segment as the target suffix; in response to the presence of only a suffix for the recommended code segment among the candidate suffixes, adjust the suffix for the recommended code segment to the suffix for the remaining code segment, and determine the suffix for the remaining code segment as the target suffix.

[0123] In this embodiment of the disclosure, the identification module 53 is further configured to: determine the suffix of the remaining code segment as the target suffix in response to the presence of a suffix in the candidate suffixes where the remaining code segment has a suffix and there is no suffix in the recommended code segment; and determine that the target suffix is ​​empty in response to the absence of both the suffix of the recommended code segment and the suffix of the remaining code segment in the candidate suffixes.

[0124] In this embodiment of the disclosure, the fusion module 54 is further configured to: obtain the target separator and the target suffix in the target symbol; delete the remaining separators between the recommended code segment and the remaining code segment except for the target separator, and the remaining suffixes in the candidate suffixes except for the target suffix, to obtain the deleted candidate recommended code segment and the candidate remaining code segment; and concatenate the candidate recommended code segment, the candidate remaining code segment, the target separator, and the target suffix in sequence to obtain the target recommended code segment recommended to the original code segment.

[0125] In this embodiment of the disclosure, the fusion module 54 is further configured to: in response to the code content in the recommended code fragment including the remaining code fragment, determine the recommended code fragment as the target recommended code fragment recommended to the original code fragment.

[0126] In this embodiment of the disclosure, the fusion module 54 is further configured to: obtain a first code length of the target recommended code segment and a second code length of the code replacement region of the original code segment; and adjust the target recommended code segment in response to the second code length being less than the first code length, until the second code length is greater than or equal to the adjusted first code length of the adjusted target recommended code segment.

[0127] The code recommendation device proposed in this disclosure acquires the recommended code segment at the code recommendation position corresponding to the line position of the original code segment, as well as the remaining code segments in the original code segment located after the code recommendation position. It then identifies the target symbol required for code fusion between the recommended and remaining code segments. Accordingly, it fuses the recommended and remaining code segments based on the target symbol to obtain the target recommended code segment. This disclosure, through the identification of the target symbol and the code fusion based on the target symbol, achieves multi-line code recommendation, reduces the difference in format between the target recommended code segment and the original code segment, achieves consistency in format between the target recommended code segment and the original code segment, increases the likelihood of users adopting the target recommended code segment, and optimizes the user experience.

[0128] According to embodiments of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0129] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0130] like Figure 6As shown, device 600 includes a computing unit 601, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 602 or a computer program loaded from storage unit 608 into random access memory (RAM) 603. RAM 603 may also store various programs and data required for the operation of device 600. The computing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.

[0131] Multiple components in device 600 are connected to I / O interface 605, including: input unit 606, such as keyboard, mouse, etc.; output unit 606, such as various types of monitors, speakers, etc.; storage unit 608, such as disk, optical disk, etc.; and communication unit 609, such as network card, modem, wireless transceiver, etc. Communication unit 609 allows device 600 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0132] The computing unit 601 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as the code recommendation method. For example, in some embodiments, the code recommendation method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the code recommendation method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the code recommendation method by any other suitable means (e.g., by means of firmware).

[0133] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0134] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0135] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0136] To initiate interaction with a user account, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user account; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user account can submit input to the computer. Other types of devices can also be used to initiate interaction with the user account; for example, feedback submitted to the user account can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user account can be received in any form (including voice input, speech input, or tactile input).

[0137] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user account computer with a graphical user interface or web browser through which a user account can interact with the implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0138] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0139] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0140] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A code recommendation method, wherein, The method includes: Obtain the recommended code snippet at the recommended code position of the original code snippet, wherein the recommended code position is the position in the line of the original code snippet that triggers the code recommendation requirement; Obtain the remaining code segment located after the recommended code position in the original code segment; Identify the target symbols required for code fusion operations in the recommended code snippets and the remaining code snippets; The recommended code fragment and the remaining code fragment are fused according to the target symbol to obtain the target recommended code fragment recommended to the original code fragment; The identification of the target symbols required for code fusion operations in the recommended code fragments and the remaining code fragments includes: Obtain the candidate delimiters and candidate suffixes from the recommended code snippets and the remaining code snippets; From the candidate delimiters, determine the target delimiter required for code fusion operation; From the candidate suffixes, determine the target suffix required for the code fusion operation; The target separator and the target suffix are determined as the target symbol; The step of fusing the recommended code fragment and the remaining code fragment according to the target symbol to obtain the target recommended code fragment recommended to the original code fragment includes: Obtain the target separator and target suffix from the target symbol; Delete the remaining delimiters between the recommended code snippet and the remaining code snippet, excluding the target delimiter, and delete the remaining suffixes in the candidate suffixes, excluding the target suffix, to obtain the deleted candidate recommended code snippet and candidate remaining code snippet; The candidate recommended code fragment, the candidate remaining code fragment, the target separator, and the target suffix are concatenated in sequence to obtain the target recommended code fragment recommended to the original code fragment.

2. The method according to claim 1, wherein, The step of determining the target delimiter required for code fusion from the candidate delimiters includes: In response to the presence of a post-delimiter of the recommended code fragment and a pre-delimiter of the remaining code fragments in the candidate delimiters, determine either the post-delimiter or the pre-delimiter as the target delimiter; In response to the fact that only the middle separator of the recommended code fragment exists in the candidate separators, the middle separator is added at the position of the last separator corresponding to the recommended code fragment or the position of the first separator corresponding to the remaining code fragment, as the target separator.

3. The method according to claim 1, wherein, Determining the target suffix required for code fusion from the candidate suffixes includes: In response to the presence of both the suffix of the recommended code segment and the suffix of the remaining code segment among the candidate suffixes, the suffix of the remaining code segment is determined to be the target suffix. In response to the fact that only the suffix of the recommended code snippet exists among the candidate suffixes, the suffix of the recommended code snippet is adjusted to the suffix of the remaining code snippets, and the suffix of the remaining code snippets is determined as the target suffix.

4. The method according to claim 3, wherein, The method further includes: In response to the existence of a suffix in the candidate suffixes where the remaining code segment has a suffix and the recommended code segment does not have a suffix, the suffix of the remaining code segment is determined to be the target suffix; In response to the absence of the suffix of the recommended code snippet and the suffix of the remaining code snippets among the candidate suffixes, it is determined that the target suffix is ​​empty.

5. The method according to claim 1, wherein, The method further includes: In response to the fact that the recommended code fragment includes the code content of the remaining code fragment, the recommended code fragment is determined to be the target recommended code fragment recommended to the original code fragment.

6. The method according to claim 5, wherein, The method further includes: Obtain the first code length of the target recommended code snippet and the second code length of the code replacement region of the original code snippet; In response to the second code length being less than the first code length, the target recommended code segment is adjusted until the second code length is greater than or equal to the adjusted first code length of the adjusted target recommended code segment.

7. A code recommendation device, wherein, The device includes: The first acquisition module is used to acquire the recommended code fragment at the code recommendation position of the original code fragment, wherein the code recommendation position is the position in the line of the original code fragment that triggers the code recommendation requirement; The second acquisition module is used to acquire the remaining code segment located after the recommended code position in the original code segment; The identification module is used to identify the target symbols required for code fusion operations in the recommended code snippets and the remaining code snippets; The fusion module is used to fuse the recommended code fragment and the remaining code fragment according to the target symbol to obtain the target recommended code fragment recommended to the original code fragment; The identification module is further configured to: Obtain the candidate delimiters and candidate suffixes from the recommended code snippets and the remaining code snippets; From the candidate delimiters, determine the target delimiter required for code fusion operation; From the candidate suffixes, determine the target suffix required for the code fusion operation; The target separator and the target suffix are determined as the target symbol; The fusion module is further configured to: Obtain the target separator and target suffix from the target symbol; Delete the remaining delimiters between the recommended code snippet and the remaining code snippet, excluding the target delimiter, and delete the remaining suffixes in the candidate suffixes, excluding the target suffix, to obtain the deleted candidate recommended code snippet and candidate remaining code snippet; The candidate recommended code fragment, the candidate remaining code fragment, the target separator, and the target suffix are concatenated in sequence to obtain the target recommended code fragment recommended to the original code fragment.

8. The apparatus according to claim 7, wherein, The identification module is also used for: In response to the presence of a post-delimiter of the recommended code fragment and a pre-delimiter of the remaining code fragments in the candidate delimiters, determine either the post-delimiter or the pre-delimiter as the target delimiter; In response to the fact that only the middle separator of the recommended code fragment exists in the candidate separators, the middle separator is added at the position of the last separator corresponding to the recommended code fragment or the position of the first separator corresponding to the remaining code fragment, as the target separator.

9. The apparatus according to claim 7, wherein, The identification module is also used for: In response to the presence of both the suffix of the recommended code segment and the suffix of the remaining code segment among the candidate suffixes, the suffix of the remaining code segment is determined to be the target suffix. In response to the fact that only the suffix of the recommended code snippet exists among the candidate suffixes, the suffix of the recommended code snippet is adjusted to the suffix of the remaining code snippets, and the suffix of the remaining code snippets is determined as the target suffix.

10. The apparatus according to claim 9, wherein, The identification module is also used for: In response to the existence of a suffix in the candidate suffixes where the remaining code segment has a suffix and the recommended code segment does not have a suffix, the suffix of the remaining code segment is determined to be the target suffix; In response to the absence of the suffix of the recommended code snippet and the suffix of the remaining code snippets among the candidate suffixes, it is determined that the target suffix is ​​empty.

11. The apparatus according to claim 7, wherein, The fusion module is also used for: In response to the fact that the recommended code fragment includes the code content of the remaining code fragment, the recommended code fragment is determined to be the target recommended code fragment recommended to the original code fragment.

12. The apparatus according to claim 11, wherein, The fusion module is also used for: Obtain the first code length of the target recommended code snippet and the second code length of the code replacement region of the original code snippet; In response to the second code length being less than the first code length, the target recommended code segment is adjusted until the second code length is greater than or equal to the adjusted first code length of the adjusted target recommended code segment.

13. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.

14. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-6.

15. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Code search method and device, readable storage medium and electronic equipment

    CN112328743A

  • Method for constructing semantic code search model in large-scale candidate set and related device

    CN114896368A