Code structure tree library construction method and information push method

By building a code structure tree library and pushing matching target code blocks, the problems of low code editing efficiency and large recommendation errors in the existing technology are solved, and more efficient and accurate code editing and recommendation are achieved.

CN113296755BActive Publication Date: 2025-05-23ALIBABA GROUP HOLDING LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010513805.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-08
Publication Date
2025-05-23
Estimated Expiration
2040-06-08

AI Technical Summary

Technical Problem

In the prior art, code editing is inefficient, recommendation methods are prone to errors, and recommendation content is simple, making it difficult to meet the user's complex code needs.

Method used

By building a code structure tree library, obtain the structural characteristics of sample code blocks, build a code block structure tree, and determine the preset code structure tree library based on these structure trees. Then, the object code information input by the user is received, the matching branch structure is filtered from the preset code structure tree library, and the relevant object code blocks are generated and pushed.

Benefits of technology

It reduces the user's code input operation and improves the code editing efficiency. The recommended code blocks are more in line with the user's needs and reduces the recommendation error.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113296755B_ABST
    Figure CN113296755B_ABST
Patent Text Reader

Abstract

The present invention discloses a code structure tree library construction method and an information push method. The information push method comprises: receiving target code information input by a user; screening out at least one target branch structure that meets a preset matching condition with the target code information from a preset code structure tree library; a branch structure in a code structure tree in the preset code structure tree library is used to characterize the structural characteristics of a code block; based on the target code information, generating a target code block corresponding to each target branch structure; and pushing the target code block that meets the preset condition. According to the embodiment of the present invention, the efficiency of code editing can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information push, and in particular to a code structure tree library construction method and an information push method. Background Art

[0002] At present, online editor products based on cloud services not only support multiple languages, but are also used in multiple scenarios such as data processing and data conversion. At the same time, more and more people are increasingly fond of editing code, publishing, deploying tasks and other entire process operations online, and use this to more conveniently connect to the services provided by various cloud products.

[0003] With the popularity of online editors and the increasing demand, how to improve code editing efficiency has become an urgent problem that needs to be solved. Summary of the invention

[0004] The embodiments of the present invention provide a code structure tree library construction method, a code structure tree library construction device, an information push method, an information push device, a computing device and a medium, which can solve the problem of low code editing efficiency.

[0005] According to a first aspect of an embodiment of the present invention, a method for constructing a code structure tree library is provided, comprising:

[0006] Get multiple sample code blocks;

[0007] extracting a structural feature of each sample code block from a plurality of sample code blocks;

[0008] For each of the sample code blocks, based on the structural features of the sample code block, a code block structure tree corresponding to the sample code block is constructed;

[0009] Based on each code block structure tree, a preset code structure tree library is determined.

[0010] According to a second aspect of an embodiment of the present invention, there is provided an information push method, the method comprising:

[0011] Receive target code information input by a user;

[0012] At least one target branch structure that satisfies a preset matching condition with the target code information is screened out from a preset code structure tree library; a branch structure in a code structure tree in the preset code structure tree library is used to characterize a structural feature of a code block;

[0013] Based on the target code information, generate a target code block corresponding to each target branch structure;

[0014] Push target code blocks that meet preset conditions.

[0015] According to a third aspect of an embodiment of the present invention, a device for constructing a code structure tree library is provided, the device comprising:

[0016] A code block acquisition module, used to acquire multiple sample code blocks;

[0017] An extraction module, used for extracting structural features of each sample code block from a plurality of sample code blocks;

[0018] A construction module, used for constructing a code block structure tree corresponding to each sample code block based on the structural characteristics of the sample code block;

[0019] The determination module is used to determine a preset code structure tree library based on each code block structure tree.

[0020] According to a fourth aspect of an embodiment of the present invention, there is provided an information push device, the device comprising:

[0021] A receiving module, used for receiving target code information input by a user;

[0022] A screening module is used to screen out at least one target branch structure that satisfies a preset matching condition with the target code information from a preset code structure tree library; a branch structure in a code structure tree in the preset code structure tree library is used to characterize a structural feature of a code block;

[0023] A generation module, used for generating a target code block corresponding to each target branch structure based on the target code information;

[0024] The push module is used to push target code blocks that meet preset conditions.

[0025] According to a fifth aspect of an embodiment of the present invention, there is provided a computing device, comprising: a processor and a memory storing computer program instructions;

[0026] When the processor executes the computer program instructions, the method provided in the first aspect or the second aspect is implemented.

[0027] According to a sixth aspect of an embodiment of the present invention, a computer storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method provided in the first aspect or the second aspect is implemented.

[0028] According to the embodiment of the present invention, by pre-determining the structural features of each sample code block, a code block structure tree corresponding to the sample code block can be constructed, and then based on each code block structure tree, a preset code structure tree library is determined. By using the pre-established code structure tree library, at least one target branch structure that meets the preset matching condition with the target code information is screened out from the preset code structure tree library, and then by embedding the target code information input by the user into each target branch structure that meets the preset matching condition with the target code information, each target code block related to the user's needs can be obtained. By pushing the target code blocks that meet the preset conditions to the user, the code blocks related to the input needs can be recommended to the user, thereby reducing the user's code input operations and improving the code editing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the following briefly introduces the drawings required for use in the embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0030] Figure 1 A schematic diagram of a flow chart of an information push system provided by an embodiment of the present invention;

[0031] Figure 2 A schematic diagram of a flow chart of a method for constructing a code structure tree library provided by an embodiment of the present invention;

[0032] Figure 3 A schematic diagram of a flow chart of an information push method provided in the first embodiment of the present invention;

[0033] Figure 4 A schematic diagram of a flow chart of an information push method provided in a second embodiment of the present invention;

[0034] Figure 5 A schematic diagram of a flow chart of an information push method provided in a third embodiment of the present invention;

[0035] Figure 6 A schematic diagram of a flow chart of an information push method provided in a fourth embodiment of the present invention;

[0036] Figure 7 A schematic diagram of the structure of a code structure tree library construction device provided by an embodiment of the present invention;

[0037] Figure 8 A schematic diagram of the structure of an information push device provided by an embodiment of the present invention;

[0038] Fig. 9 A schematic diagram of the structure of a computing device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0039] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and Examples. It should be understood that the specific embodiments described herein are only configured to explain the present invention and are not configured to limit the present invention. For those skilled in the art, the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present invention by illustrating examples of the present invention.

[0040] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0041] Current code editors can also recommend code information to users. Current recommendation methods include generative algorithm recommendations or recommendations based on the probability of the next method, parameter, or keyword appearing calculated through prior knowledge. Recommendations based on generative algorithms are based on the previous one or more characters to generate recommended content, but there is a certain probability that the recommended characters do not conform to the coding rules. In fact, the combinations of codes are diverse, the amount of code is huge, and the code rules are cumbersome. Probability-based recommendations often prioritize characters with high probability, and some characters that are not commonly used but are needed by users are often not recommended.

[0042] In other words, current recommendation methods, whether generative algorithm recommendations or probability-based recommendations, may have recommendation errors. In real-world application development, it is impossible to understand the use of every language, function method, and keyword. This potentially erroneous recommendation brings users more complex error correction steps, reducing the efficiency of user code editing. In addition, current code recommendation methods mostly recommend only method names, parameters, or keywords to users. The recommended content is relatively simple, which also reduces the efficiency of code editing.

[0043] Based on the above technical problems, an embodiment of the present invention provides a code structure tree library construction method, a code structure tree library construction device, an information push method, an information push device, a computing device and a medium. By combining the user's target code information, code blocks related to the user's input requirements can be recommended to the user, thereby reducing the user's code input operations and improving code editing efficiency.

[0044] It should be noted that a code block is not a keyword, a parameter or a method name. A code block is a functional unit consisting of a section of code, and a code block can run independently.

[0045] Figure 1 FIG. 2 is a schematic diagram showing the architecture of the information push system provided by an embodiment of the present invention. Figure 1 As shown, the system includes a terminal 110 and a server 120 .

[0046] In an embodiment of the present invention, the terminal 110 may be an electronic device such as a laptop, a smart phone, a tablet computer or a personal computer. The server 120 may be a high-performance electronic calculator that can process data in response to a service request sent by the terminal 110. The terminal 110 and the server 120 may communicate with each other via a network.

[0047] The user can use the code editor through the terminal 110 and input the target code information on the code editor. The terminal 110 receives the target code information input by the user and sends the target code information to the server 120. As an example, the target code information is "select a, b from t".

[0048] The server 120 selects at least one target branch structure that satisfies a preset matching condition with the target code information from the preset code structure tree library, and generates a target code block corresponding to each target branch structure based on the target code information; and then pushes the target code block that satisfies the preset condition to the terminal 110. The terminal 110 receives the target code block that satisfies the preset condition and displays the target code block.

[0049] Among them, a branch structure in a code structure tree in the preset code structure tree library is used to characterize the structural characteristics of a code block. That is, the preset code structure tree library includes at least one code structure tree. For each code structure tree, the code structure tree includes at least one branch structure. Each branch structure is used to characterize the structural characteristics of a code block.

[0050] See also Figure 1, assuming that there are two target branch structures that meet the preset matching conditions with the target code information, and the two target branch structures are: "select*from*where*" and "select*from*where*Limit*". By combining the target code information input by the user, the target code block corresponding to "select*from*where*" can be obtained as "select a,bfrom t where*", and the target code block corresponding to "select*from*where*Limit*" can be obtained as "select a,b from t where*Limit*".

[0051] By displaying the target code block on the terminal 110, it is convenient for the user to directly select the required code block, which reduces the time for the user to input code and improves the code editing efficiency.

[0052] When implementing the information push method provided by the embodiment of the present application, it is necessary to use the pre-built preset code structure tree library. Therefore, the specific implementation process of establishing the preset code structure tree library is first introduced below. Figure 2 Schematic diagram of the code structure tree library construction method provided in the embodiment of the present application. Figure 2 As shown, the code structure tree library construction method provided in the embodiment of the present application includes S210 to S240.

[0053] First, S210, multiple sample code blocks are obtained. Then, S220, the structural features of each sample code block in the multiple sample code blocks are extracted. Then, S230, for each sample code block, based on the structural features of the sample code block, a code block structure tree corresponding to the sample code block is constructed. Then, S240, based on each code block structure tree, a preset code structure tree library is determined.

[0054] In an embodiment of the present application, by utilizing the structural features of each sample code block, a corresponding code block structure tree of the sample code block is constructed, and then based on each code block structure tree, a preset code structure tree library is determined, so that the code block can be searched and pushed.

[0055] In some embodiments of the present invention, S210 includes: obtaining a plurality of sample code statements; and performing statement splitting on each sample code statement based on a preset statement splitting rule to obtain a plurality of sample code blocks.

[0056] In an embodiment of the present invention, a plurality of sample code statements may be obtained according to the actual input data of the user, wherein the code statement includes at least one code block.

[0057] It should be noted that before splitting the sample code statements, keywords in the sample code statements may be extracted, and non-keywords may be replaced with "*".

[0058] As an example, the sample code statements are split into the smallest structural form, namely, code blocks, by using a pre-defined statement splitting rule in a regularized manner, wherein the regularized manner refers to splitting the sample code statements using a regular expression corresponding to the preset statement splitting rule.

[0059] In S220, a feature structure is extracted from each sample code block obtained by splitting. In some embodiments, many predefined feature extraction functions can be used to extract the structural features of the sample code block. For example, the feature extraction function may include a keyword structure (select from Where, etc.), a repeated feature structure (*, **and*, casewhen*, etc.) or a structural feature composed of various symbols (sum(*), LEFT(*,*)), etc.

[0060] After the structural features of each sample code block are obtained, a code block structure tree corresponding to the sample code block is constructed based on the structural features of the sample code block. In other words, the code block structure tree is used to characterize the structural features of a code block.

[0061] For example, if the sample code block is "select a from b", the code block structure tree corresponding to the sample code block may be "select*from*", where the structure tree is displayed in a chain form.

[0062] In some embodiments, S240 includes: merging all code block structure trees based on a preset merging rule to obtain each code structure tree in a preset code structure tree library.

[0063] In some embodiments of the present invention, since some code block structure trees have similar structural features, for example, the code block structure tree "select*from*" and the code block structure tree "select*,*,*from*" have similar structural features, the code block structure tree "select*from*" and the code block structure tree "select*,*,*from*" can be merged, that is, the code block structure tree "select*,*,*from*" can be simplified to the code block structure tree "select*from*".

[0064] In other embodiments of the present invention, a code block structure tree is an extension of another code block structure tree. For example, the code block structure tree "select*from*where*" is an extension of the code block structure tree "select*from*". Therefore, "select*from*where*" and "select*from*" can be merged into one code structure tree, and "select*from*where*" is used as a subordinate extension of "select*from*".

[0065] That is to say, a code structure tree includes multiple code block structure trees, that is, the code block structure tree is a branch structure of the code structure tree. The branch structure in the code structure tree can be a code block structure tree corresponding to the root node itself, or a code block structure tree corresponding to the path from the root node in the code structure tree to any node in the structure tree except the root node.

[0066] As an example, the code block structure tree "select*from*" can be used as the root node of a new code structure tree A, and then "where*" can be used as the second-level node of the code structure tree A, and "Limit*" can be used as the third-level node of the code structure tree A. The code structure tree A includes three branch structures, namely "select*from*", "select*from*where*" and "select*from*where*Limit*". The branch structure "select*from*" is the code block structure tree corresponding to the root node; the branch structure "select*from*where*" is the code block structure tree corresponding to the path from the root node to the second-level node; the branch structure "select*from*where*Limit*" is the code block structure tree corresponding to the path from the root node to the third-level node.

[0067] By merging the code block structure trees, at least one more generalized code structure tree can be obtained, which can reduce the time for screening the target branch structure, thereby improving the efficiency of information push.

[0068] In an embodiment of the present invention, by utilizing sample code statements actually input by the user and using preset statement splitting rules, the sample code statements are divided into smallest units (i.e., code blocks), which greatly reduces the number of structure trees, improves the recommendation efficiency, and makes the recommended code more in line with expectations.

[0069] The information push method provided in the embodiment of the present application is described in detail below in conjunction with a preset code structure tree library. Figure 3 FIG. 3 is a flow chart showing an information push method 300 provided in an embodiment of the present invention. Figure 3As shown, the method includes S310 to S340.

[0070] First, S310, receiving target code information input by a user; then, S320, screening out at least one target branch structure that satisfies a preset matching condition with the target code information from a preset code structure tree library; a branch structure in a code structure tree in the preset code structure tree library is used to characterize the structural characteristics of a code block; then, S330, based on the target code information, generating a target code block corresponding to each target branch structure; and then, S340, pushing the target code block that satisfies the preset condition.

[0071] By utilizing a pre-established code structure tree library, at least one target branch structure that satisfies a preset matching condition with the target code information is screened out from the preset code structure tree library, and then by embedding the target code information input by the user into each target branch structure that satisfies the preset matching condition with the target code information, each target code block related to the user's needs can be obtained. By pushing target code blocks that meet the preset conditions to the user, code blocks related to the user's input needs can be recommended to the user, thereby reducing the user's code input operations and improving code editing efficiency.

[0072] The specific implementation method of each step in S310 to S340 is described in detail below.

[0073] In S310, target code information may be obtained from a terminal, wherein the target code information is at least part of information of a code block.

[0074] In some embodiments of the present invention, S320 includes S3201 to S3203. S3201, extracting target structural features of target code information; S3202, constructing a target feature structure tree corresponding to the target code information based on the target structural features; S3203, selecting at least one target branch structure that meets a preset matching condition with the target feature structure tree from a preset code structure tree library.

[0075] In some embodiments of the present invention, a preset feature extraction function may be used to extract the target structure features of the target code information. Then, the target structure features of the target code information may be used to construct a target feature structure tree corresponding to the target code information.

[0076] For example, if the target code information is "select a,b from t", the target feature structure tree is "select*from*". Since the target code information input by the user may only be part of a code block, the target code information is not necessarily constructed as a code block structure tree, so it can be called a target feature structure tree, that is, a structure used to characterize the target code information.

[0077] In some embodiments of the present invention, S3203 includes: starting from the starting position of the target code information, sequentially extracting n characteristic keywords of the target code information; matching the n characteristic keywords with at least one index of each code structure tree in a preset code structure tree library; using the code structure tree corresponding to the index matching the n characteristic keywords as the target code structure tree; using the branch structure in the target code structure tree that meets the preset matching condition with the target characteristic structure tree as the target branch structure. n is a positive integer.

[0078] It should be noted that each code structure tree in the preset code structure tree library has at least one index. By extracting the first N keywords in the code structure tree as the N feature indexes of the code structure tree, the time for finding the target code structure tree can be saved, thereby improving the recommendation efficiency. Wherein, N is a positive integer greater than 1.

[0079] For example, the code structure tree A in the above example can have three levels of indexes, namely, "select", "select from", and "select from where". Each of the three indexes corresponds to the same code structure tree, namely, code structure tree A, which can save time in querying the target code structure tree and avoid querying from the root node every time.

[0080] As an example, starting from the starting position of the target code information, n characteristic keywords of the target code information are extracted in sequence, that is, the first n characteristic keywords of the target code information are extracted. For example, if the target code information is "selecta,b from t", the first two characteristic keywords are "select" and "from".

[0081] It should be noted that, since the order of the characteristic keywords of the code block also represents a structural feature of the target code information, when using the n keywords of the target code information to match the index in the code structure tree, the first keyword to the i-th keyword of the target code information can be used as a whole to match the index of the code structure tree, where i is greater than or equal to 1 and less than or equal to n.

[0082] For example, at least one of "select" and "select from" can be used to match at least one index of each code structure tree. Since the three-level indexes of code structure tree A are respectively: "select", "select from", and "select from where", it can be seen that the n characteristic keywords of the target code information match both indexes of code structure tree A. Therefore, code structure tree A can be used as the target code structure tree.

[0083] Then, each branch structure in the code structure tree A is matched with the target feature structure tree, and the branch structure in the code structure tree A that meets the preset matching condition with the target feature structure tree is used as the target branch structure.

[0084] As an example, the preset matching condition may be that the branch structure and the target feature structure tree have partially the same structural features.

[0085] In the above example, the target feature structure tree is "select*from*", and the code structure tree A includes three branch structures, namely "select*from*", "select*from*where*" and "select*from*where*Limit*". Then the three branch structures of the code structure tree A all match the target feature structure tree, that is, they are all target branch structures.

[0086] In the embodiment of the present invention, by setting at least one index for the code structure tree, the efficiency of searching the target code structure tree can be increased.

[0087] In S330, the target code information input by the user is embedded into each target branch structure, that is, the target code block is recommended to the user without replacing the content input by the user.

[0088] In the above example, there are three target branch structures that match the target feature structure tree, namely: "select*from*", "select*from*where*" and "select*from*where*Limit*". By combining the target code information input by the user, the "select a,b from t" input by the user can be embedded into each target branch structure to generate a target code block corresponding to each target branch structure.

[0089] In some embodiments of the present invention, in order to improve the user's code editing efficiency, input prompts can be provided for the parts of the target code block that the user has not entered, so as to further improve the code editing efficiency. Specifically, S330 includes: for each target branch structure, executing steps A to C. Step A, extracting the characteristic keywords in the target branch structure; Step B, for the characteristic keywords in the target branch structure, inputting the characteristic keywords and m characteristic keywords adjacent to the characteristic keywords into a pre-trained type feature determination model to obtain the type feature information adjacent to the characteristic keywords; m is a positive integer; Step C, based on the target code information and the type feature information adjacent to the characteristic keywords, generating a target code block corresponding to the target branch structure.

[0090] It should be noted that the type feature determination module can be obtained through supervised training. The following briefly introduces the training process of the type feature determination module.

[0091] First, obtain the training sample set.

[0092] Among them, each training sample in the training sample set includes a sample feature keyword and m feature keywords adjacent to the sample feature keyword. It should be noted that the m feature keywords adjacent to the sample feature keyword include m feature keywords adjacent to the left of the sample feature keyword and m feature keywords adjacent to the right of the sample feature keyword. Since the type feature information adjacent to the sample feature keyword is closely related to the feature keywords adjacent to the left and right of the keyword, the m feature keywords adjacent to the sample feature keyword need to be included in the training sample.

[0093] Then, each training sample is input into the type feature determination model to be trained to obtain the subsequent adjacent predicted type feature information corresponding to each sample feature keyword.

[0094] Next, the subsequent adjacent predicted type feature information corresponding to each sample feature keyword and the subsequent adjacent type feature information label corresponding to each sample feature keyword are used to adjust the parameters of the type feature determination model to be trained.

[0095] Then determine whether the preset training conditions are met. If not, continue to use the training sample set to iteratively train the adjusted type feature determination model until the preset training conditions are met to obtain the trained type feature determination model.

[0096] In one embodiment of the present specification, the preset training condition includes the number of iterations reaching a preset threshold.

[0097] In another embodiment of the present specification, the preset training condition includes that the difference between the loss function value of the type feature determination model to be trained and the loss function value determined in the last iteration process does not exceed the preset difference threshold. That is to say, if the loss function value of the type feature determination model to be trained is relatively close to the loss function value calculated in the last iteration process, it can be considered that the performance of the trained type feature determination model is relatively good.

[0098] In one or more embodiments of the present specification, the type feature determination model is any one of the following models: a linear regression model, a random forest model, a support vector machine regression model, a neural network regression model, and a gradient boosting iterative decision tree regression model.

[0099] As an example, the features following select are mostly field type features, and the features following where are mostly conditional judgment type features.

[0100] In the embodiment of the present invention, only the last characteristic keyword in the target code information input by the user in the target branch structure and the characteristic keywords not input by the user need to be extracted. That is, only the type characteristic information after the characteristic keyword not input by the user in the target branch structure and the type characteristic information adjacent to the last characteristic keyword input by the user need to be determined.

[0101] For example, for the target branch structure "select*from*", since the user has already entered a and b after select, the type feature information of the feature keyword will no longer be determined. Since only one "t" is entered after "from", the type feature information adjacent to "from" can be determined.

[0102] Assuming m=1, from and the feature keyword select adjacent to from are input into the pre-trained type feature determination model, and the type feature information adjacent to from can be obtained as a table type feature.

[0103] Similarly, using the pre-trained type feature determination model, it can be determined that in the target branch structures "select*from*where*" and "select*from*where*Limit*", the type feature information adjacent to where is a conditional judgment type feature, and the type feature information adjacent to Limit is a constant type feature.

[0104] Then, the code block corresponding to select*from* can be "select a,b from tab1"; the target code block corresponding to "select*from*where*" can be "select a,b from tab1 where condition1"; and the target code block corresponding to "select*from*where*Limit*" can be "select a,b from tab1 wherecondition1 Limit constant1".

[0105] Among them, tab1 is used to prompt the user that the adjacent type feature information after from is a table type feature; condition1 is used to prompt the user that the adjacent type feature information after where is a conditional judgment type feature; constant1 is used to prompt the user that the adjacent type feature information after Limit is a constant type feature.

[0106] By displaying prompt information after the part of the feature keyword that the user has not entered, the prompt information prompts the user with the type feature information adjacent to the feature keyword, so that the user can quickly enter the corresponding code, thereby improving the code editing efficiency.

[0107] In S340, the preset condition includes that the usage frequency of the target branch structure corresponding to the target code block is greater than a preset usage frequency threshold.

[0108] It should be noted that when constructing the preset code structure tree library, the frequency of occurrence of each branch structure in the code structure tree in the obtained multiple sample code statements can be counted as the usage frequency of the branch structure.

[0109] By pushing target code blocks that meet preset conditions to users, code blocks that are used more frequently can be recommended to users, thereby improving the accuracy of recommendations.

[0110] In some embodiments of the present invention, the information push method provided by the embodiment of the present invention may also be executed on a terminal. Therefore, after S340, the information push method provided by the embodiment of the present invention further includes S350, displaying a target code block that meets a preset condition.

[0111] By displaying target code blocks that meet preset conditions to users, users can independently select the required code blocks, reducing the time for users to input codes, thereby improving the efficiency of code editing.

[0112] In some aspects of the present invention, S350 includes: displaying each target code block that meets the preset condition in sequence according to the usage frequency of the target branch structure corresponding to each target code block that meets the preset condition from high to low.

[0113] In an embodiment of the present invention, by displaying target code blocks in descending order of the usage frequency of the target branch structure, the target code blocks with the highest usage frequency can be preferentially recommended to the user, further reducing the user's operation time and improving the efficiency of code editing.

[0114] See also Figure 4 The construction of the preset code structure tree library is an offline process. By obtaining multiple sample code statements from the code library, the keywords in the sample code statements are extracted, and non-keywords are replaced by "*", that is, Figure 5 Code preprocessing function in offline processing in . Figure 4 Then, the sample code statements after non-keyword replacement are split based on the preset statement splitting rules to obtain multiple sample code blocks, that is, the sample code statements are split into the minimum structure, that is, Figure 5 Structural splitting function in offline processing.

[0115] Continue to see Figure 4 , and then extract the characteristic structure of each sample code block, namely Figure 5 Based on the feature structure, a code block structure tree corresponding to each sample code block is constructed, that is, Figure 5 The structure tree construction function in the offline processing in . Then aggregate each code block structure tree to obtain the code structure tree library.

[0116] It should be noted that in Figure 5 The offline processing also includes a custom module, which is used to support users to customize the content of the recommended target code block to adapt to each user's coding style. In other words, users can customize the code block recommendation rules in the custom module.

[0117] See also Figure 4 ,By utilizing the preset code structure tree library obtained by offline learning and combining ,the target code information input by the user, online prediction ,can be performed in real time and the predicted code blocks can be ,recommended to the user.

[0118] Continue to see Figure 4 When a user uses a code editor, the user enters the target code information in the code editor. Then the feature keywords of the target code information are parsed, that is, the target structure features of the target code information (i.e. Figure 5 The input parsing function of the intelligent prediction part in the code structure is used to construct a target feature structure tree corresponding to the target code information based on the target structure feature. Then, at least one target branch structure that meets the preset matching condition with the target feature structure tree is screened out from the preset code structure tree library, that is, at least one matching target branch structure.

[0119] Then, the target code blocks corresponding to each target branch structure are displayed in order from high to low in the order of the frequency of use of the target branch structure, so that the user can select the target code block to be used according to the needs (i.e. Figure 5 Real-time recommendation function in intelligent prediction in ).

[0120] The information push method provided by the embodiment of the present invention is an intelligent recommendation based on actual executable code (i.e., sample code statements), and does not generate new code itself, thus reducing recommendation errors. In addition, the embodiment of the present invention also combines the target code information input by the user, that is, it makes personalized recommendations based on the needs of the user.

[0121] See also Figure 5The intelligent prediction function includes a switch verification function, which refers to a switch in the code editor that can be used to set whether the intelligent prediction is turned on. If it is verified that the user has not turned on the intelligent prediction switch, no code block recommendation will be made to the user. The rule verification function in the intelligent prediction function refers to verifying whether the user has customized the code block recommendation rules in the custom template. If the user has customized the code block recommendation rules, the recommendation will be made according to the user-defined code block recommendation rules. If the user has not customized it, the code block is pushed according to the method in S310~S340.

[0122] Continue to see Figure 5 The underlying configuration functions include language switch, algorithm model, filtering rules and timed loading functions. Among them, the language switch means that users can choose different programming languages.

[0123] The embodiment of the present invention can establish corresponding preset code structure tree libraries for different programming languages, so as to implement code block recommendations for different programming languages.

[0124] The algorithm model refers to a pre-trained type feature determination model, which is used to determine the type feature information adjacent to the feature keyword. The filtering rule refers to the user-defined code block recommendation rule.

[0125] The timed loading function means that the updated code structure tree library can be loaded at a time, that is, the code structure tree library can be updated. As the sample code statements are updated, the code structure tree library can be updated.

[0126] At the application level, the information push method provided by the embodiment of the present invention is more practical. By setting switch verification, rule verification and filtering rules, the recommendation structure can be intervened in real time without making any changes to the release. In addition, during the implementation of the information push method, the type feature determination model can be dynamically loaded, and the code structure tree library can be updated regularly without interfering with the user.

[0127] For further explanation, see Figure 6 ,for Figure 5 The intelligent prediction function in can realize the combination of user-defined recommendations and algorithm recommendations to better meet the personalized needs of users.

[0128] Each user has his or her own coding style, so the user can customize the offline code block recommendation template in advance. As an example, the offline code block recommendation template may include the correspondence between code information and recommended code blocks. After the user enters a code information, the user-defined recommended code block corresponding to the code information can be found from the correspondence, and the recommended code block can be pushed to the user, so that the user can use the recommended code block according to his or her needs.

[0129] The code block recommendation template set by the user can be updated in real time, so the offline code block recommendation module can be dynamically effective, so that users can set the template according to their needs at any time. In addition, for code editors in any language, user-defined recommendation functions can be set so that users can edit code according to their needs when editing code in different languages.

[0130] In addition to setting the function that the user can customize the recommendation, for the code information other than the customization input by the user, it can be recommended according to the information push algorithm provided in the embodiment of the present application. Before using the information push algorithm to recommend the code block, it is necessary to first build a code structure tree library offline for the recommendation of the code block. With the update of the sample code statement, the code structure tree library can be updated. When the updated code structure tree library appears, the updated code structure tree library can be loaded for the push of the code block, that is to say, the code structure tree library is dynamically effective. In addition, before recommending the code block, it is also necessary to pre-train the type feature determination model to determine the type feature information adjacent to the feature keyword.

[0131] At the application level, you can set code style, filtering rules, switch verification and other functions to achieve application-level sharing, and you can intervene in the recommended structure in real time without making release changes.

[0132] Figure 7 FIG. 2 is a schematic diagram showing the structure of a code structure tree library construction device provided by an embodiment of the present invention. Figure 7 As shown, the code structure tree library construction device 700 includes:

[0133] The code block acquisition module 710 is used to acquire multiple sample code blocks.

[0134] The extraction module 720 is configured to extract the structural features of each sample code block in the plurality of sample code blocks.

[0135] The construction module 730 is configured to construct, for each of the sample code blocks, a code block structure tree corresponding to the sample code block based on the structural features of the sample code block.

[0136] The determination module 740 is used to determine the preset code structure tree library based on each of the code block structure trees.

[0137] In an embodiment of the present application, by utilizing the structural features of each sample code block, a corresponding code block structure tree of the sample code block is constructed, and then based on each code block structure tree, a preset code structure tree library is determined, so that the code block can be searched and pushed.

[0138] In some embodiments of the present invention, the code block acquisition module 710 is used to:

[0139] Get multiple sample code statements;

[0140] Based on the preset statement splitting rule, each sample code statement is split to obtain multiple sample code blocks.

[0141] In some embodiments of the present invention, the determination module 740 is used to:

[0142] Based on the preset merging rules, all code block structure trees are merged to obtain each code structure tree in the preset code structure tree library.

[0143] Other details of the code structure tree library construction device 700 according to the embodiment of the present invention are combined with the above Figure 2 The code structure tree library construction method described in the embodiment of this specification is similar and will not be repeated here.

[0144] Figure 8 FIG. 2 is a schematic diagram showing the structure of an information push device provided by an embodiment of the present invention. Figure 8 As shown, the information push device 800 includes:

[0145] The receiving module 810 is used to receive the target code information input by the user.

[0146] The screening module 820 is used to screen out at least one target branch structure that meets a preset matching condition with the target code information from the preset code structure tree library. A branch structure in a code structure tree in the preset code structure tree library is used to characterize the structural features of a code block.

[0147] The generating module 830 is used to generate a target code block corresponding to each target branch structure based on the target code information.

[0148] The push module 840 is used to push target code blocks that meet preset conditions.

[0149] By utilizing a pre-established code structure tree library, at least one target branch structure that satisfies a preset matching condition with the target code information is screened out from the preset code structure tree library, and then by embedding the target code information input by the user into each target branch structure that satisfies the preset matching condition with the target code information, each target code block related to the user's needs can be obtained. By pushing target code blocks that meet the preset conditions to the user, code blocks related to the user's input needs can be recommended to the user, thereby reducing the user's code input operations and improving code editing efficiency.

[0150] In some embodiments of the present invention, the screening module 820 includes:

[0151] The extraction unit is used to extract the target structure features of the target code information.

[0152] The construction unit is used to construct a target feature structure tree corresponding to the target code information based on the target structure feature.

[0153] The screening unit is used to screen out at least one target branch structure that meets a preset matching condition with the target feature structure tree from a preset code structure tree library.

[0154] In some embodiments of the present invention, the screening unit is used to:

[0155] Starting from the starting position of the target code information, n characteristic keywords of the target code information are extracted in sequence; n is a positive integer;

[0156] Matching the n characteristic keywords with at least one index of each code structure tree in a preset code structure tree library;

[0157] The code structure tree corresponding to the index matching the n characteristic keywords is used as the target code structure tree;

[0158] The branch structure in the target code structure tree that meets the preset matching condition with the target feature structure tree is used as the target branch structure.

[0159] In some embodiments of the present invention, the preset condition includes that the usage frequency of the target branch structure corresponding to the target code block is greater than a preset usage frequency threshold.

[0160] In some embodiments of the present invention, the information push device 800 further includes:

[0161] A display module is used to display target code blocks that meet preset conditions.

[0162] In some embodiments of the present invention, the display module is used to:

[0163] Each target code block that meets the preset condition is displayed in sequence according to the usage frequency of the target branch structure corresponding to each target code block that meets the preset condition from high to low.

[0164] In some embodiments of the present invention, the generation module 830 is used to:

[0165] For each target branch structure, perform the following steps:

[0166] Extract characteristic keywords in the target branch structure;

[0167] For the characteristic keyword in the target branch structure, the characteristic keyword and m characteristic keywords adjacent to the characteristic keyword are input into the pre-trained type feature determination model to obtain the type feature information adjacent to the characteristic keyword; m is a positive integer;

[0168] Based on the target code information and the type feature information adjacent to the feature keyword, a target code block corresponding to the target branch structure is generated.

[0169] Other details of the information push device 800 according to the embodiment of the present invention are combined with the above Figures 3 to 6 The information push method described in the embodiment of this specification is similar and will not be repeated here.

[0170] Combination Figure 2 and Figure 8 The code structure tree library construction method, code structure tree library construction device, information push method and information push device according to the embodiments of the present invention described above can be implemented by a computing device. Fig. 9 FIG. 9 is a schematic diagram showing a hardware structure 900 of a computing device according to an embodiment of the invention.

[0171] like Fig. 9 As shown, the computing device 900 includes an input device 901, an input interface 902, a processor 903, a memory 904, an output interface 905, and an output device 906. The input interface 902, the processor 903, the memory 904, and the output interface 905 are connected to each other via a bus 910, and the input device 901 and the output device 906 are connected to the bus 910 via the input interface 902 and the output interface 905, respectively, and are further connected to other components of the computing device 900.

[0172] Among them, the processor 903 may include: a central processing unit (CPU), a network processor (NPU), a tensor processing unit (TPU), a field programmable gate array (FPGA) chip or an artificial intelligence (AI) chip and other types of processors. The figure is only for illustrative purposes and is not limited to the types of processors listed in the text.

[0173] Specifically, the input device 901 receives input information from the outside and transmits the input information to the processor 903 through the input interface 902; the processor 903 processes the input information based on the computer executable instructions stored in the memory 904 to generate output information, temporarily or permanently stores the output information in the memory 904, and then transmits the output information to the output device 906 through the output interface 905; the output device 906 outputs the output information to the outside of the computing device 900 for user use.

[0174] That is to say, Fig. 9 The computing device shown may also be implemented as including: a memory storing computer executable instructions; and a processor, which can implement the combination of Figures 2 to 8 The described code structure tree library construction method, code structure tree library construction device, information push method and information push device.

[0175] The embodiment of the present invention further provides a computer storage medium, on which computer program instructions are stored; when the computer program instructions are executed by a processor, the information push method provided by the embodiment of the present invention is implemented.

[0176] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present invention are programs or code segments that are used to perform the required tasks. Programs or code segments can be stored in machine-readable media, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable media" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.

[0177] It should also be noted that the exemplary embodiments mentioned in the present invention describe some methods or systems based on a series of steps or devices. However, the present invention is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiments, or in a different order from the embodiments, or several steps can be performed simultaneously.

[0178] The above is only a specific implementation of the present invention. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be covered within the protection scope of the present invention.

Claims

1. A method for constructing a code structure tree library. in, The method comprises: Get multiple sample code blocks; extracting a structural feature of each sample code block from the plurality of sample code blocks; For each of the sample code blocks, based on the structural features of the sample code block, construct a code block structure tree corresponding to the sample code block; Based on each of the code block structure trees, a preset code structure tree library is determined; the preset code structure tree library is used to extract n characteristic keywords of the target code information in sequence starting from the starting position of the target code information; n is a positive integer; the n characteristic keywords are matched with at least one index of each code structure tree in the preset code structure tree library; the code structure tree corresponding to the index matching the n characteristic keywords is used as the target code structure tree; the branch structure in the target code structure tree that meets the preset matching condition with the target characteristic structure tree is used as the target branch structure; Among them, a branch structure in a code structure tree in the preset code structure tree library is used to characterize the structural characteristics of a code block; the target code information is used to generate a target code block corresponding to each target branch structure; and the target feature structure tree is constructed based on the target structural characteristics of the target code information.

2. The method according to claim 1, in, The obtaining of multiple sample code blocks includes: Get multiple sample code statements; Based on a preset statement splitting rule, each of the sample code statements is split to obtain the multiple sample code blocks.

3. The method according to claim 1, in, The step of determining the preset code structure tree library based on each of the code block structure trees comprises: Based on the preset merging rule, all code block structure trees are merged to obtain each code structure tree in the preset code structure tree library.

4. A method for pushing information, in, The method comprises: Receive target code information input by a user; From a preset code structure tree library, at least one target branch structure that meets a preset matching condition with the target code information is screened out, comprising: starting from the starting position of the target code information, sequentially extracting n characteristic keywords of the target code information; n is a positive integer; matching the n characteristic keywords with at least one index of each code structure tree in the preset code structure tree library; using the code structure tree corresponding to the index matching the n characteristic keywords as the target code structure tree; using the branch structure in the target code structure tree that meets the preset matching condition with the target characteristic structure tree as the target branch structure; wherein a branch structure in a code structure tree in the preset code structure tree library is used to characterize the structural characteristics of a code block; the target characteristic structure tree is constructed based on the target structural characteristics of the target code information; Based on the target code information, generating a target code block corresponding to each target branch structure; Push the target code block that meets the preset condition.

5. The method according to claim 4, in, The method further comprises: Extracting target structural features of the target code information; Based on the target structural features, a target feature structure tree corresponding to the target code information is constructed.

6. The method according to claim 4, in, The preset condition includes that the usage frequency of the target branch structure corresponding to the target code block is greater than a preset usage frequency threshold.

7. The method according to claim 4, in, After pushing the target code block that meets the preset condition, the method further includes: The target code blocks that meet the preset conditions are displayed.

8. The method according to claim 7, in, The displaying of the target code block that meets the preset condition includes: Each target code block that meets the preset condition is displayed in sequence according to the usage frequency of the target branch structure corresponding to each target code block that meets the preset condition from high to low.

9. The method according to claim 4, in, The step of generating a target code block corresponding to each target branch structure based on the target code information includes: For each target branch structure, perform the following steps: Extracting characteristic keywords in the target branch structure; For the characteristic keyword in the target branch structure, the characteristic keyword and m characteristic keywords adjacent to the characteristic keyword are input into a pre-trained type feature determination model to obtain type feature information adjacent to the characteristic keyword; m is a positive integer; A target code block corresponding to the target branch structure is generated based on the target code information and the type feature information adjacent to the feature keyword.

10. A code structure tree library construction device, in, The device comprises: A code block acquisition module, used to acquire multiple sample code blocks; An extraction module, used for extracting structural features of each sample code block among the plurality of sample code blocks; A construction module, configured to construct, for each of the sample code blocks, a code block structure tree corresponding to the sample code block based on the structural features of the sample code block; A determination module, for determining a preset code structure tree library based on each of the code block structure trees, wherein the preset code structure tree library is used to extract n characteristic keywords of the target code information in sequence starting from the starting position of the target code information; n is a positive integer; the n characteristic keywords are matched with at least one index of each code structure tree in the preset code structure tree library; the code structure tree corresponding to the index matched with the n characteristic keywords is used as the target code structure tree; the branch structure in the target code structure tree that meets the preset matching condition with the target characteristic structure tree is used as the target branch structure; Among them, a branch structure in a code structure tree in the preset code structure tree library is used to characterize the structural characteristics of a code block; the target code information is used to generate a target code block corresponding to each target branch structure; and the target feature structure tree is constructed based on the target structural characteristics of the target code information.

11. An information push device, in, The device comprises: A receiving module, used for receiving target code information input by a user; A screening module, used to screen out at least one target branch structure that meets a preset matching condition with the target code information from a preset code structure tree library, comprising: starting from the starting position of the target code information, sequentially extracting n feature keywords of the target code information; n is a positive integer; matching the n feature keywords with at least one index of each code structure tree in the preset code structure tree library; using the code structure tree corresponding to the index matching the n feature keywords as the target code structure tree; using the branch structure in the target code structure tree that meets the preset matching condition with the target feature structure tree as the target branch structure; wherein a branch structure in a code structure tree in the preset code structure tree library is used to characterize the structural characteristics of a code block, and the target feature structure tree is constructed based on the target structural characteristics of the target code information; A generating module, configured to generate a target code block corresponding to each target branch structure based on the target code information; The push module is used to push the target code block that meets the preset conditions.

12. A computing device, in, The computing device includes: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the method according to any one of claims 1 to 9 is implemented.

13. A computer storage medium, in, The computer storage medium stores computer program instructions, which, when executed by a processor, implement the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Generation method and device for code prompt information

    CN107239264A

  • Code completion method and device, storage medium and electronic device

    CN110502227A