Code processing method and device, electronic equipment, storage medium and computer program product
By performing word segmentation and correlation analysis on code units, highlighting parameters were determined, solving the problem of complexity in code highlighting methods under different programming languages and achieving universality and accuracy of code highlighting.
Patent Information
- Application Number
- CN202410502312.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-24
- Publication Date
- 2025-10-28
AI Technical Summary
Existing code highlighting methods are complex and lack versatility because different integrated development environments use different programming languages, requiring different word segmentation rules to be designed for each language.
By performing word segmentation on the code to be processed, the feature parameters of the code unit are obtained, the correlation between the code unit and other code units is determined, and the highlighting parameters are determined based on the correlation to achieve code highlighting.
Using the same word segmentation rules in different programming languages to achieve code highlighting improves the versatility and accuracy of code highlighting and reduces errors in highlighting.
Smart Images

Figure CN120848858A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to a code processing method, apparatus, electronic device, storage medium, and computer program product. Background Technology
[0002] In related technologies, code highlighting is a method of marking code with color to tell developers the special function of the code.
[0003] Currently, the existing code highlighting method is syntax highlighting, also known as syntax coloring. This method uses color to mark keywords of a certain programming language to tell developers the special function of the word.
[0004] However, different integrated development environments use different programming languages, and different programming languages have different keyword declarations in their design. This means that when implementing code highlighting, developers need to design different word segmentation rules for different programming languages, which makes the code highlighting method complex to write and has poor universality. Summary of the Invention
[0005] To overcome the problems existing in related technologies, this disclosure provides a code processing method, apparatus, electronic device, storage medium, and computer program product that can use the same word segmentation rules to achieve code highlighting in different programming languages, thereby improving the universality of code highlighting.
[0006] According to a first aspect of the present disclosure, a code processing method is provided, comprising at least:
[0007] The code to be processed is segmented into words to obtain a code sequence that includes at least one code unit.
[0008] Based on the feature parameters of any code unit in the code sequence, the correlation degree between the any code unit and other code units in the code sequence is determined; wherein, the correlation degree is used to characterize the degree of dependence between the any code unit and the other code units;
[0009] Based on the correlation degree corresponding to each code unit, the highlighting parameters of each code unit are determined respectively; wherein, the highlighting parameters are used to highlight the code unit.
[0010] In some embodiments, determining the correlation between any code unit and other code units in the code sequence, based on the feature parameters of any code unit in the code sequence, includes:
[0011] Based on the first and second feature parameters of any code unit in the code sequence, determine the similarity between any code unit and the other code units;
[0012] Based on the similarity and the third feature parameter of any code unit in the code sequence, the degree of association corresponding to any code unit is determined;
[0013] Wherein, the first feature parameter is used to characterize the information that the any code unit needs to query in the code sequence, the second feature parameter is used to characterize the information of the code units related to the any code unit in the code sequence, and the third feature parameter is used to characterize the semantic information of the any code unit.
[0014] In some embodiments, determining the relevance of any code unit based on the similarity and a third feature parameter of the code unit in the code sequence includes:
[0015] The similarity is normalized to obtain the weight coefficient of any code unit;
[0016] The correlation degree corresponding to any code unit is determined based on the weight coefficient and the third feature parameter of any code unit in the code sequence.
[0017] In some embodiments, determining the correlation degree corresponding to any code unit based on the weight coefficient and the third feature parameter of any code unit in the code sequence includes:
[0018] Based on the weight coefficients, the third feature parameters of each code unit are weighted and then summed to obtain the correlation degree.
[0019] The third feature parameter includes a value vector.
[0020] In some embodiments, determining the similarity between any code unit and the other code units based on a first feature parameter and a second feature parameter of the code unit in the code sequence includes:
[0021] The first feature parameter of any code unit is multiplied by the second feature parameter of all code units to obtain the similarity between the first feature parameter and the second feature parameter.
[0022] The first feature parameter includes a query vector, and the second feature parameter includes a key vector.
[0023] In some embodiments, the method further includes:
[0024] Each code unit in the code sequence is annotated to obtain the annotated code corresponding to each code unit;
[0025] A tag sequence is generated based on the position of each of the aforementioned annotation codes and the corresponding code units in the code sequence.
[0026] In some embodiments, determining the highlighting parameters of each code unit based on the relevance of each code unit includes:
[0027] Based on the annotation information carried by the tag sequence and the correlation degree of each code unit, the highlighting parameters of each code unit are determined;
[0028] The annotation information includes type information and semantic information for each code unit.
[0029] In some embodiments, determining the highlighting parameters of each code unit based on the annotation information carried by the tag sequence and the correlation degree of each code unit includes:
[0030] Based on the preset mapping relationship, the correlation degree and the type information and semantic information of each code unit are searched to obtain the highlighting parameters corresponding to each code unit;
[0031] The preset mapping relationship is used to characterize the relationship between the type information, the semantic information, the correlation degree, and the highlighting parameters.
[0032] In some embodiments, the step of annotating each code unit in the code sequence to obtain the annotated code corresponding to each code unit includes:
[0033] Based on a preset named entity recognition model, characters with preset information are identified from each of the code units, and the characters with the preset information are labeled; and / or,
[0034] Based on a pre-defined part-of-speech tagging model, each character in each code unit is classified into parts of speech, and the part of speech corresponding to each character is tagged.
[0035] In some embodiments, the highlighting parameters include the color of the code unit and the font style of the code unit.
[0036] According to a second aspect of the present disclosure, a code processing apparatus is provided, comprising at least:
[0037] The word segmentation module is configured to segment the code to be processed to obtain a code sequence that includes at least one code unit.
[0038] The first determining module is configured to determine the degree of correlation between any code unit and other code units in the code sequence, based on the feature parameters of any code unit in the code sequence; wherein the degree of correlation is used to characterize the degree of dependence between any code unit and the other code units;
[0039] The second determining module is configured to determine the highlighting parameters of each code unit based on the correlation degree corresponding to each code unit; wherein the highlighting parameters are used to highlight the code unit.
[0040] In some embodiments, the first determining module includes:
[0041] The first submodule is configured to determine the similarity between any code unit and the other code units based on the first feature parameter and the second feature parameter of any code unit in the code sequence;
[0042] The second submodule is configured to determine the correlation degree corresponding to any code unit based on the similarity and the third feature parameter of any code unit in the code sequence.
[0043] Wherein, the first feature parameter is used to characterize the information that the any code unit needs to query in the code sequence, the second feature parameter is used to characterize the information of the code units related to the any code unit in the code sequence, and the third feature parameter is used to characterize the semantic information of the any code unit.
[0044] In some embodiments, the second submodule includes:
[0045] The first calculation module is configured to normalize the similarity to obtain the weight coefficient of any code unit;
[0046] The second calculation module is configured to determine the correlation degree corresponding to any code unit based on the weight coefficient and the third feature parameter of any code unit in the code sequence.
[0047] In some embodiments, the second computing module includes:
[0048] The weighting module is configured to perform weighted processing on the third feature parameters of each code unit based on the weight coefficients, and to sum the weighted third feature parameters to obtain the correlation degree.
[0049] The third feature parameter includes a value vector.
[0050] In some embodiments, the first submodule includes:
[0051] The third calculation module is configured to perform dot product calculation on the first feature parameter of any code unit and the second feature parameter of all code units respectively to obtain the similarity between the first feature parameter and the second feature parameter;
[0052] The first feature parameter includes a query vector, and the second feature parameter includes a key vector.
[0053] In some embodiments, the code processing apparatus further includes:
[0054] The annotation processing module is configured to perform annotation processing on each code unit in the code sequence to obtain the annotation code corresponding to each code unit;
[0055] The generation module is configured to generate a tag sequence based on the position of each of the labeled codes and the corresponding code units in the code sequence.
[0056] In some embodiments, the second determining module includes:
[0057] The third submodule is configured to determine the highlighting parameters of each code unit based on the annotation information carried by the tag sequence and the correlation degree of each code unit;
[0058] The annotation information includes type information and semantic information for each code unit.
[0059] In some embodiments, the third submodule includes:
[0060] The search module is configured to search for the correlation degree and the type and semantic information of each code unit based on a preset mapping relationship, so as to obtain the highlighting parameters corresponding to each code unit.
[0061] The preset mapping relationship is used to characterize the relationship between the type information, the semantic information, the correlation degree, and the highlighting parameters.
[0062] In some embodiments, the annotation processing module includes:
[0063] The first annotation submodule is configured to identify characters with preset information from each of the code units based on a preset named entity recognition model, and to annotate the characters with the preset information; and / or,
[0064] The second annotation submodule is configured to classify each character in each code unit into parts of speech based on a preset part-of-speech tagging model, and to annotate the part of speech corresponding to each character.
[0065] In some embodiments, the highlighting parameters include the color of the code unit and the font style of the code unit.
[0066] According to a third aspect of the present disclosure, an electronic device is provided, comprising at least:
[0067] processor;
[0068] Memory used to store computer programs or instructions;
[0069] The processor executes the computer program or instructions to implement the steps of the method described in the first aspect.
[0070] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium is provided, the storage medium storing a computer program or instructions that, when executed by a processor, implement the steps of the method described in the first aspect.
[0071] According to a fifth aspect of the present disclosure, a computer program product is provided, including a computer program or instructions that, when executed by a processor, implement the steps of the method described in the first aspect.
[0072] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects:
[0073] The code processing method provided in this disclosure may include: performing word segmentation on the code to be processed to obtain a code sequence including at least one code unit; determining the correlation degree between any code unit and other code units in the code sequence based on the feature parameters of any code unit in the code sequence; wherein the correlation degree is used to characterize the degree of dependence between any code unit and other code units; determining the highlighting parameters of each code unit based on the correlation degree corresponding to each code unit; wherein the highlighting parameters are used to highlight the code unit.
[0074] Thus, unlike related technologies that require designing different word segmentation rules for different programming languages, the embodiments of this disclosure can obtain a code sequence including at least one code unit by performing word segmentation on the code to be processed. Then, based on the feature parameters of any code unit in the code sequence, the correlation between any code unit and other code units in the code sequence is captured to determine the highlighting parameters of each code unit. This allows the same word segmentation rules to be used to achieve code highlighting in different programming languages, improving the versatility of code highlighting. At the same time, since the correlation between any code unit and other code units is calculated after word segmentation, the highlighting parameters of the code unit can be determined through this correlation, thereby reducing the error in highlighting code units and improving the accuracy of highlighting code units.
[0075] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0076] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0077] Figure 1 This is a flowchart illustrating a code processing method according to an exemplary embodiment. Figure 1 .
[0078] Figure 2 This is a schematic diagram illustrating a code processing method according to an exemplary embodiment.
[0079] Figure 3 This is a flowchart illustrating a code processing method according to an exemplary embodiment. Figure 2 .
[0080] Figure 4 This is a flowchart illustrating a code processing method according to an exemplary embodiment. Figure 3 .
[0081] Figure 5 This is a block diagram illustrating a code processing apparatus according to an exemplary embodiment.
[0082] Figure 6 This is a block diagram illustrating an electronic device according to an exemplary embodiment.
[0083] Figure 7 This is a hardware structure block diagram of a code processing apparatus according to an exemplary embodiment. Detailed Implementation
[0084] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0085] The technical solutions provided by the embodiments of this disclosure are described in detail below with reference to the accompanying drawings.
[0086] Figure 1 This is a flowchart illustrating a code processing method according to an exemplary embodiment. Figure 1 .like Figure 1 As shown, the code processing method provided in this disclosure includes at least the following steps:
[0087] Step 110: Perform word segmentation on the code to be processed to obtain a code sequence that includes at least one code unit;
[0088] Step 120: Based on the feature parameters of any code unit in the code sequence, determine the degree of association between any code unit and other code units in the code sequence; wherein, the degree of association is used to characterize the degree of dependence between any code unit and other code units.
[0089] Step 130: Based on the correlation degree of each code unit, determine the highlighting parameters for each code unit; the highlighting parameters are used to highlight the code unit.
[0090] In this embodiment of the disclosure, the code processing method described above can be applied to electronic devices or servers. Here, electronic devices can include terminal devices, such as mobile terminals or fixed terminals. Mobile terminals can include devices such as mobile phones, tablets, laptops, and wearable electronic devices. Fixed terminals can include desktop computers, smart TVs, and in-vehicle systems. As a type of computer, a server can provide computing or application services to other clients on a network, such as computers, smartphones, Automated Teller Machines (ATMs), and even large equipment like train systems.
[0091] In other embodiments, the code processing methods in this disclosure can be configured in a code processing device, which can be located in an electronic device or in a server, and this disclosure does not limit this.
[0092] It should be noted that the execution entity of the embodiments of this disclosure can be a central processing unit (CPU) in an electronic device or server in terms of hardware, and can be a related background service in an electronic device or server in terms of software, without limitation.
[0093] The code processing method proposed in this embodiment can be applied to code highlighting. After the code to be processed is segmented, the correlation between any code unit and other code units in the code sequence is captured to determine the highlighting parameters of each code unit. Thus, the highlighting parameters can be used to achieve the highlighting display of the code to be processed.
[0094] In step 110, the code to be processed can be the source code that needs to be highlighted; for example, the code to be processed can be function test(){const a=1;}.
[0095] A code unit can be a code fragment containing one or more characters after the code to be processed is segmented using a word segmentation algorithm; a code sequence can be a sequence composed of at least one code unit after word segmentation.
[0096] For example, such as Figure 2 As shown, in step 201, the code to be processed is segmented. Specifically, if the code to be processed is function test(){const a=1;}, then the code sequence after segmentation can be [function,test,(,),{,const,a,=,1,;,}]. Here, “function” can be the first code unit, “test” can be the second code unit, and “}” can be the last code unit in the code sequence.
[0097] It should be noted that the word segmentation algorithm used in this embodiment can be selected according to the actual application situation, and there is no limitation thereto. For example, the word segmentation algorithm used to segment the code to be processed can be the maximum matching method or the bidirectional matching method, etc.
[0098] Here, the maximum matching method is a dictionary-based word segmentation algorithm that breaks down source code into a series of tokens. The principle of the maximum matching method is to attempt to match the longest word in the code to be processed, either from left to right or from right to left, based on a pre-defined maximum word length, thus achieving word segmentation processing. The maximum matching method can be divided into forward maximum matching and backward maximum matching. The main difference between the two lies in the matching direction: forward maximum matching matches from left to right; backward maximum matching matches from right to left.
[0099] Bidirectional matching is a word segmentation method that combines forward maximum matching and backward maximum matching, which can improve the accuracy of word segmentation. In bidirectional matching, the word segmenter simultaneously uses both forward and backward maximum matching algorithms to segment the same code to be processed. Then, based on preset strategies or principles (such as word granularity, the number of segmentation results, etc.), the most suitable segmentation result is selected from the results of the two matching methods.
[0100] In step 120, the embodiments of this disclosure can determine the correlation degree that can characterize the degree of dependence between any code unit and other code units in the code sequence based on a preset deep learning model and the feature parameters of any code unit in the code sequence.
[0101] Here, any code unit can be any code unit in a code sequence; the feature parameter can be a parameter used to characterize the information associated with any code unit.
[0102] It should be noted that the aforementioned preset deep learning model may include a self-attention model or a recurrent neural network model, etc., and the embodiments disclosed herein do not impose any limitations on this.
[0103] Understandably, a pre-defined self-attention model can be built upon a self-attention mechanism. A self-attention mechanism is a mechanism that allows a model to handle dependencies between different positions in an input sequence. It allows the model to assign different weights to different parts of the input sequence, thus determining which positions in the input sequence should be focused on when generating the output at a certain position.
[0104] Here, self-attention models, such as the self-attention layer in a Transformer model, are able to capture long-term dependencies within the code sequence input to the model, and since all positions in the code sequence are considered during computation, additional positional encoding is required to provide positional information.
[0105] For example, in a self-attention model, each code unit in the input code sequence generates multiple corresponding feature parameters. For instance, each code unit may generate a query vector, a key vector, and a value vector. These vectors are typically obtained from the original input code units through a linear transformation (e.g., multiplying by a weight matrix). The self-attention model then calculates the similarity between the query vector of each code unit and the key vectors of other code units. These similarities are normalized to obtain attention weight coefficients. Based on these weight coefficients, the value vectors of each code unit are weighted and summed to obtain an output vector that characterizes the correlation between any code unit and other code units.
[0106] In step 130, the highlighting parameters of each code unit are determined based on the correlation degree corresponding to each code unit. This may include: determining the highlighting parameters of each code unit based on a preset mapping relationship and the correlation degree corresponding to each code unit; or, determining the highlighting parameters of each code unit based on a preset highlighting mapping model and the correlation degree corresponding to each code unit.
[0107] It should be noted that the preset mapping relationship can be used to characterize the relationship between the relevance and the highlighting parameters; or, it can be used to characterize the relationship between the type information, relevance and highlighting parameters of the code unit; or, it can be used to characterize the relationship between the type information, semantic information, relevance and highlighting parameters of the code unit, etc., and the embodiments disclosed herein do not limit this.
[0108] Here, the preset highlight mapping model can be a model capable of finding the highlight parameters corresponding to the correlation degree of each code unit in the code sequence. In this embodiment, the code sequence and the correlation degree corresponding to each code unit can be input into the highlight mapping model to output the highlight parameters of each code unit corresponding to that correlation degree.
[0109] In one embodiment of this disclosure, the highlighting parameters include the color and font style of the code unit. Thus, the highlighting of code units can be achieved by determining the color and font style of each code unit, thereby better ensuring the accuracy of code unit highlighting.
[0110] It is understandable that the preset mapping relationships can include the relationship between relevance and the color of the code unit, as well as the relationship between relevance and the font style of the code unit. The preset highlight mapping model can include a color mapping model and a font mapping model.
[0111] In some embodiments, after determining the highlighting parameters of each code unit, all code units in the code sequence can be highlighted based on the highlighting parameters; or, some code units in the code sequence can be highlighted based on the highlighting parameters, and this disclosure does not limit this.
[0112] In another embodiment, after the color and font style of each code unit are determined, all code units in the code sequence can be highlighted based on color; or, all code units in the code sequence can be highlighted based on font style; or, all code units in the code sequence can be highlighted based on both color and font style. This disclosure does not limit the scope of the embodiments.
[0113] In related technologies, the current code highlighting method is syntax highlighting, which uses color to highlight keywords of a programming language to inform developers of their specific function. However, different integrated development environments use different programming languages, and these languages have different keyword declarations in their design. This means that developers need to design different word segmentation rules for different programming languages when implementing code highlighting, making this code highlighting method complex to write and lacking in versatility.
[0114] Based on this, the code processing method provided in this disclosure may include: performing word segmentation on the code to be processed to obtain a code sequence including at least one code unit; determining the correlation degree between any code unit and other code units in the code sequence, based on the feature parameters of any code unit in the code sequence; wherein the correlation degree is used to characterize the degree of dependence between any code unit and other code units; determining the highlighting parameters of each code unit based on the correlation degree corresponding to each code unit; wherein the highlighting parameters are used to highlight the code unit.
[0115] Thus, unlike related technologies that require designing different word segmentation rules for different programming languages, the embodiments of this disclosure can obtain a code sequence including at least one code unit by performing word segmentation on the code to be processed. Then, based on the feature parameters of any code unit in the code sequence, the correlation between any code unit and other code units in the code sequence is captured to determine the highlighting parameters of each code unit. This allows the same word segmentation rules to be used to achieve code highlighting in different programming languages, improving the versatility of code highlighting. At the same time, since the correlation between any code unit and other code units is calculated after word segmentation, the highlighting parameters of the code unit can be determined through this correlation, thereby reducing the error in highlighting code units and improving the accuracy of highlighting code units.
[0116] In some embodiments, step 120 may include:
[0117] Based on the first and second feature parameters of any code unit in the code sequence, determine the similarity between any code unit and other code units;
[0118] Based on similarity and the third feature parameter of any code unit in the code sequence, the degree of association corresponding to any code unit is determined;
[0119] The first feature parameter is used to characterize the information that any code unit needs to query in the code sequence, the second feature parameter is used to characterize the information of the code units related to any code unit in the code sequence, and the third feature parameter is used to characterize the semantic information of any code unit.
[0120] In this way, the similarity between any code unit and other code units can be determined by the first and second feature parameters of any code unit in the code sequence. Then, the correlation can be determined based on the similarity and the third feature parameter of any code unit in the code sequence, which prepares for the subsequent determination of the highlighting parameters of the code unit. This can reduce the error in highlighting code units and improve the accuracy of highlighting code units.
[0121] In this embodiment of the disclosure, the first feature parameter can represent the information that any code unit at the current position wants to focus on or query in the code sequence, and can be used to calculate the similarity between it and the second feature parameter at other positions in the code sequence, so as to determine which code units at which positions are most important to the current position.
[0122] Here, the first feature parameter can be obtained by converting any code unit at the current position into a word embedding vector and then performing a linear transformation on that word embedding vector, i.e., multiplying it by a weight matrix. For example, the first feature parameter can be a query vector.
[0123] The second feature parameter can be used to calculate similarity with the first feature parameter to determine which code units in the code sequence are relevant to the code unit at the current position. By comparing the similarity between the first and second feature parameters, it can be determined which code units are important to the code unit at the current position, and the attention weights at the corresponding positions can be adjusted based on this similarity.
[0124] It should be noted that the second feature parameter can be obtained by converting the code unit at the corresponding position into a word embedding vector, and then performing a linear transformation on that word embedding vector, i.e., multiplying it by a weight matrix. This transformation allows the second feature parameter to capture the key information needed for comparison with the first feature parameter. For example, the second feature parameter can be a key vector.
[0125] It is understood that, in the embodiments of this disclosure, the similarity between any code unit and other code units can be determined by performing dot product calculation or other metric calculation (such as cosine similarity) between the first feature parameter of any code unit and the second feature parameter of all code units respectively.
[0126] In one embodiment of this disclosure, determining the similarity between any code unit and other code units based on the first and second feature parameters of any code unit in the code sequence includes:
[0127] The similarity between the first feature parameter and the second feature parameter of all code units is obtained by performing a dot product between the first feature parameter and the second feature parameter.
[0128] The first feature parameter includes the query vector, and the second feature parameter includes the key vector.
[0129] In this way, the similarity between the first feature parameter and the second feature parameter of any code unit can be obtained by performing a dot product between the first feature parameter and the second feature parameter of all code units. This prepares the basis for subsequent calculation of the correlation between any code unit and other code units, so as to capture the degree of dependence between any code unit and other code units and improve the accuracy of highlighting code units.
[0130] Here, the dot product, also known as the dot product or scalar product, is used to calculate the similarity between the query vector and the key vector, or the angle between them. Similarity can be a measure of how similar two objects, such as any unit of code, are to other units of code.
[0131] For example, the formula for calculating the dot product of query vector Q and key vector K is: Q·K=|Q|×|K|×cos(θ); by calculating the dot product of query vector Q and key vector K, the similarity between the code units corresponding to query vector Q and key vector K can be obtained. Here, |Q| and |K| are the magnitudes (lengths) of vectors Q and K, respectively; θ is the angle between vectors Q and K.
[0132] It should be noted that, in this embodiment of the present disclosure, the first feature parameter of any code unit can be calculated with the second feature parameters of all code units to obtain the similarity between any code unit and other code units, without limitation. In this calculation method, the closer the cosine value is to 1, the more similar the two feature parameters are; the closer the cosine value is to 0, the less similar the two feature parameters are.
[0133] In this embodiment of the disclosure, the third feature parameter may include actual information associated with the second feature parameter, which can be used to generate the final output. After calculating the similarity between the first and second feature parameters, the third feature parameter can be weighted and aggregated according to the similarity to generate the output vector of any code unit at the current position.
[0134] Here, the third feature parameter is also obtained by converting the code unit at the corresponding position into a word embedding vector, and then performing a linear transformation on that word embedding vector, i.e., multiplying it by a weight matrix. This transformation allows the third feature parameter to contain information useful for the current task, which is then weighted and aggregated according to the degree of matching between the first and second feature parameters. For example, the third feature parameter can be a value vector.
[0135] It should be noted that the first feature parameter, the second feature parameter, and the third feature parameter undergo different linear transformations; that is, the weight matrix multiplied by the word embedding vector obtained by the transformation of the same code unit is different, so as to obtain the first feature parameter, the second feature parameter, and the third feature parameter of the code unit in the code sequence respectively.
[0136] It is understood that the embodiments of this disclosure can determine the correlation degree of any code unit by using the third feature parameter of any code unit and the similarity between any code unit and other code units, so as to capture the degree of dependence of each code unit on other code units in the code sequence.
[0137] In one embodiment of this disclosure, determining the relevance of any code unit based on similarity and a third feature parameter of any code unit in the code sequence includes:
[0138] The similarity is normalized to obtain the weight coefficient of any code unit;
[0139] The degree of correlation corresponding to any code unit is determined based on the weight coefficient and the third feature parameter of any code unit in the code sequence.
[0140] In this way, by normalizing the similarity, the weight coefficient of any code unit can be obtained, which can speed up the training of deep learning models such as self-attention models that obtain correlation and improve the stability of the model. Then, based on the weight coefficient and the third feature parameter of any code unit, the correlation corresponding to any code unit can be determined, thereby improving the accuracy of subsequent highlighting of code units.
[0141] In this embodiment of the disclosure, the weighting coefficient can be used to represent a proportionality coefficient indicating the importance of other code units relative to any given code unit. The weighting coefficient can range from 0 to 1.
[0142] Here, the degree of dependence of other code units at other positions in the code sequence on any code unit at the current position is different, and the weight coefficients corresponding to any code unit are different from those of other code units.
[0143] Understandably, the Softmax function can be used to normalize the similarity between any given code unit and other code units, thus obtaining the weight coefficients of other code units relative to that given code unit. The Softmax function is a commonly used classification function that standardizes an n-dimensional vector input to it into an n-dimensional probability distribution. In this n-dimensional probability distribution, each element has a value between 0 and 1, and the sum of all elements is 1.
[0144] It should be noted that, in the embodiments of this disclosure, the correlation degree corresponding to any code unit can be determined by weighted summation of the weight coefficient and the third feature parameter of any code unit; or, after weighting the weight coefficient and the third feature parameter of any code unit, the weighted third feature parameter can be weighted summation again according to a preset coefficient to obtain the correlation degree corresponding to any code unit, etc.
[0145] In some embodiments, determining the relevance of any code unit based on the weighting coefficient and the third feature parameter of any code unit in the code sequence includes:
[0146] Based on the weight coefficients, the third feature parameters of each code unit are weighted and then summed to obtain the correlation degree.
[0147] The third feature parameter includes a value vector.
[0148] In this way, the third feature parameter of each code unit can be weighted by weighting coefficients, and the weighted third feature parameters can be summed to obtain the correlation degree corresponding to any code unit. This can prepare for the subsequent determination of the highlighting parameters of each code unit, thereby reducing the error in highlighting code units and improving the accuracy of highlighting code units.
[0149] In this embodiment of the disclosure, the third feature parameter of each code unit is weighted based on weight coefficients. This can be understood as multiplying the weight coefficients corresponding to any code unit and all code units by the third feature parameter of all code units to obtain the weighted third feature parameter of each code unit. After weighting, the weighted third feature parameters of each code unit are summed to obtain the correlation degree corresponding to any code unit.
[0150] Exemplarily, the vector set composed of the query vectors of all code units in the code sequence is {q1, q2,..., qn}, the vector set composed of the key vectors of all code units is {k1, k2,..., kn}, and the vector set composed of the value vectors of all code units is {v1, v2,..., vn}; then the degree of association between the first code unit in the code sequence and other code units can be: (q1·k1)ˊ×v1 + (q1·k2)ˊ×v2 + … + (q1·kn)ˊ×vn. Among them, from (q1·k1)ˊ, (q1·k2)ˊ to (q1·kn)ˊ can be the weight coefficients of all code units relative to the first code unit.
[0151] Similarly, the degree of association between the i-th code unit in the code sequence and other code units can be: (qi·k1)ˊ×v1 + (qi·k2)ˊ×v2 + … + (qi·kn)ˊ×vn; where 1 < i < n, and i is a positive integer.
[0152] It should be noted that after calculating the degree of association corresponding to any code unit in the embodiments of the present disclosure, each code unit in the code sequence can be corrected according to this degree of association, so as to improve the recognition accuracy of the type information and semantic information corresponding to each code unit.
[0153] Figure 3 It is a flowchart showing a code processing method according to an exemplary embodiment Figure 2 As Figure 3 shown, the code processing method provided by the embodiments of the present disclosure may further include:
[0154] Step 140, perform annotation processing on each code unit in the code sequence respectively to obtain the annotation code corresponding to each code unit;
[0155] Step 150, generate a tag sequence based on each annotation code and the position of the corresponding code unit in the code sequence.
[0156] It should be noted that steps 140-150 of the embodiments of the present disclosure can be executed before step 120, can also be executed after step 120, or can be executed simultaneously with step 120, as long as it is satisfied that it is executed after step 110 and before step 130, and there is no limitation on this.
[0157] In step 140, the annotation code may include the original code unit and the recognized type information and semantic information of the code unit.
[0158] It is understood that the embodiments of this disclosure can utilize named entity recognition models and / or part-of-speech tagging models to annotate each code unit in the code sequence to obtain annotated codes that include the annotation information of each code unit, thereby further improving the accuracy of subsequently determining the highlight parameters of the code units.
[0159] For example, such as Figure 2 As shown, in step 202, the code sequence can be annotated based on the named entity recognition model and / or the part-of-speech tagging model. Specifically, if the code sequence is [function,test,(,),{,const,a,=,1,;,}], then the structure corresponding to the annotated code after the code sequence annotation process can be [keyword, identifier, parentheses, parentheses, parentheses, keyword, variable, operator, constant, semicolon, parentheses].
[0160] In one embodiment of this disclosure, step 140 may include:
[0161] Based on a pre-defined named entity recognition model, characters with pre-defined information are identified from each code unit, and these characters are labeled; and / or,
[0162] Based on a pre-defined part-of-speech tagging model, each character in each code unit is classified into parts of speech, and the part of speech corresponding to each character is tagged.
[0163] In this way, characters in each code unit can be labeled using a pre-defined named entity recognition model and / or part-of-speech tagging model, thereby replacing the regular expressions used in related technologies to identify the meaning of characters in each code unit.
[0164] In this embodiment, the named entity recognition model can identify entities with specific meanings from code units, such as names of people, places, organizations, dates, or times. These entities are typically important for understanding the content of code units, extracting key information, and performing subsequent semantic analysis. Named entity recognition models usually rely on labeled data from large-scale corpora and algorithms such as deep learning to train the model to identify entity boundaries and categories within code units.
[0165] Here, the preset information can be the specific meaning represented by the code unit. That is, after identifying the character with the preset information from the code unit, the character with the preset information can be labeled.
[0166] For example, such as Figure 2 As shown, using the named entity recognition model, characters of types such as identifiers and variables can be identified from each code unit in a code sequence.
[0167] In this embodiment, the part-of-speech tagging model can classify each character in a code unit into its part of speech, such as noun, verb, adjective, adverb, etc. Part-of-speech tagging is one of the fundamental tasks in natural language processing, and it helps to understand the grammatical function and contextual relationships of characters in a code unit. Part-of-speech tagging models are typically based on rule-based methods or statistical learning methods, determining the part of speech of a character by analyzing its morphology, context, and grammatical structure.
[0168] For example, such as Figure 2 As shown, by using part-of-speech tagging models, characters of the type of operators and separators such as parentheses can be identified from each code unit in a code sequence.
[0169] It should be noted that the embodiments of this disclosure may use only a preset named entity recognition model to annotate each code unit in the code sequence; or, may use only a preset part-of-speech tagging model to annotate each code unit in the code sequence; or, may first use a preset named entity recognition model to annotate each code unit in the code sequence, and then use a preset part-of-speech tagging model to annotate each code unit in the code sequence. The embodiments of this disclosure do not limit this.
[0170] In step 150, the label sequence may consist of individual code units and the annotation information corresponding to each code unit.
[0171] It is understandable that the tag sequence can carry annotation information for each code unit, which may include type and semantic information for each code unit. For example, the type information of a code unit may include keywords, identifiers, operators, variables, constants, delimiters, etc.
[0172] It should be noted that when the type information of a code unit is a keyword, the annotation information of that code unit may include both type information and semantic information; when the type information of a code unit is a separator such as parentheses, the annotation information of that code unit may only include type information.
[0173] Here, after generating the label sequence, the data input into a preset deep learning model, such as a self-attention layer, to determine the correlation between any code unit and other code units can be a code sequence or a label sequence, and this embodiment of the disclosure does not limit it.
[0174] In some embodiments, step 130 may include:
[0175] Based on the annotation information carried by the label sequence and the correlation between each code unit, the highlighting parameters of each code unit are determined;
[0176] The annotation information includes type information and semantic information for each code unit.
[0177] In this way, the highlighting parameters of each code unit can be determined by the annotation information carried by the label sequence and the correlation between each code unit, thereby reducing the error in highlighting code units and improving the accuracy of highlighting code units.
[0178] Here, when the type information of a code unit is a keyword, identifier, or variable, the highlighting parameters of the code unit can be determined based on its type information, semantic information, and relevance; when the type information of a code unit is an operator or separator, the highlighting parameters of the code unit can be determined based on its type information and relevance.
[0179] It should be noted that the embodiments of this disclosure can determine the highlighting parameters of each code unit based on a preset mapping relationship, annotation information, and the correlation degree of each code unit; or, they can determine the highlighting parameters of each code unit based on a preset highlighting mapping model, annotation information, and the correlation degree of each code unit.
[0180] In this embodiment of the disclosure, the preset highlight mapping model may include a preset color mapping function and a preset font mapping function. Based on the preset color mapping function, annotation information, and the correlation between each code unit, the color corresponding to each code unit is determined; based on the preset font mapping function, annotation information, and the correlation between each code unit, the font style corresponding to each code unit is determined.
[0181] In one embodiment of this disclosure, determining the highlighting parameters of each code unit based on the annotation information carried by the tag sequence and the correlation between each code unit includes:
[0182] Based on the preset mapping relationship, the correlation degree and the type and semantic information of each code unit are searched to obtain the highlighting parameters corresponding to each code unit;
[0183] Among them, the preset mapping relationship is used to represent the relationship between type information, semantic information, relevance, and highlighting parameters.
[0184] In this way, the correlation degree and the type and semantic information of each code unit can be searched separately by pre-setting the mapping relationship to obtain the highlighting parameters corresponding to each code unit. This can further improve the accuracy of determining the highlighting parameters corresponding to the code unit, so as to better realize the highlighting display of the code unit.
[0185] It is understandable that the preset mapping relationship can include the relationship between type information, semantic information, relevance and color, as well as the relationship between type information, semantic information, relevance and font style.
[0186] Here, the highlighting parameter corresponding to the type information, semantic information, and relevance of each code unit can be found in the preset mapping relationship, so that the highlighting parameter can be used to highlight each code unit.
[0187] It should be noted that, in this embodiment, the target interface corresponding to the Integrated Development Environment (IDE) displayed by the code to be processed can be determined first; then, by calling the target interface, the code units corresponding to the code to be processed can be highlighted in the IDE based on the highlighting parameters. Alternatively, existing plugin technology can be used to highlight the code units corresponding to the code to be processed in the IDE based on the highlighting parameters.
[0188] An IDE is an application that provides a program development environment, which may include tools such as code editors, compilers, debuggers, and graphical user interfaces; for example, highlighting of individual code units corresponding to the code to be processed can be implemented in a source code editor (Visual Studio Code). The target interface mentioned above can be an Application Programming Interface (API).
[0189] It is understood that the embodiments of this disclosure can automatically learn the structure of the code to be processed and the correlation between any code unit and other code units by adding a self-attention mechanism. This enables intelligent processing of the dependencies between various code units in complex code, and can also be extended to different programming languages and IDE environments, providing developers with a richer and more accurate code highlighting experience and improving the versatility of code highlighting.
[0190] The code processing method provided in this disclosure can obtain a tag sequence carrying annotation information by annotating the segmented code sequence. Then, based on the type information, semantic information, and correlation degree of each code unit in the annotation information, the highlighting parameters of each code unit are determined. This allows the same segmentation rules to be used to achieve code highlighting in different programming languages, improving the universality of code highlighting. At the same time, since the correlation degree between any code unit and other code units is calculated after segmentation, the highlighting parameters of the code unit can be determined through this correlation degree, thereby reducing the error in highlighting code units and improving the accuracy of highlighting code units.
[0191] Figure 4 This is a flowchart illustrating a code processing method according to an exemplary embodiment. Figure 3 .like Figure 4 As shown, the code processing methods provided in the embodiments of this disclosure are merely examples and not limitations, intended to facilitate a better understanding of the technical solutions of this disclosure by those skilled in the art. See also Figure 4 The code processing method provided in this disclosure, when applied to an electronic device, may include at least the following steps:
[0192] Step 401: Perform word segmentation on the code to be processed to obtain a code sequence that includes at least one code unit.
[0193] Step 402: Annotate each code unit in the code sequence to obtain the annotation code corresponding to each code unit.
[0194] Here, based on a preset named entity recognition model, characters with preset information are identified from each code unit and labeled; and / or, based on a preset part-of-speech tagging model, each character in each code unit is classified by part of speech and labeled with the part of speech corresponding to each character.
[0195] Step 403: Generate a label sequence based on the position of each labeled code and its corresponding code unit in the code sequence; the label sequence carries label information including the type information and semantic information of each code unit.
[0196] Here, the label sequence can be composed of each code unit and the annotation information corresponding to each code unit; the annotation information can include the type information and semantic information of each code unit.
[0197] Step 404: Perform a dot product between the first feature parameter of any code unit in the code sequence and the second feature parameters of all code units to obtain the similarity between any code unit and other code units.
[0198] Here, the first feature parameter may include the query vector, and the second feature parameter may include the key vector.
[0199] Step 405: Normalize the similarity to obtain the weight coefficient of any code unit.
[0200] Step 406: Determine the correlation degree corresponding to any code unit based on the weight coefficient and the third feature parameter of any code unit in the code sequence.
[0201] Here, the third feature parameter can include a value vector.
[0202] Step 407: Based on the preset mapping relationship, search for the correlation degree and the type and semantic information of each code unit to obtain the highlighting parameters corresponding to each code unit; the highlighting parameters are used to highlight the code unit.
[0203] Here, the preset mapping relationship can include the relationship between type information, semantic information, correlation degree and color, as well as the relationship between type information, semantic information, correlation degree and font style.
[0204] The code processing method provided in this disclosure can obtain a code sequence including at least one code unit by segmenting the code to be processed, and then perform annotation processing on the code sequence to obtain a tag sequence carrying annotation information. Then, based on the first feature parameter, second feature parameter and third feature parameter of any code unit in the code sequence, the correlation between any code unit and other code units in the code sequence is captured to determine the highlighting parameters of each code unit. This allows the same segmentation rules to be used to achieve code highlighting in different programming languages, improving the universality of code highlighting. At the same time, since the correlation between any code unit and other code units is calculated after segmentation, the highlighting parameters of the code unit can be determined through the correlation, thereby reducing the error in highlighting code units and improving the accuracy of highlighting code units.
[0205] Figure 5 This is a block diagram illustrating a code processing apparatus according to an exemplary embodiment. Figure 5 As shown, the code processing device 500 provided in this embodiment may include: a word segmentation processing module 510, a first determination module 520, and a second determination module 530.
[0206] The word segmentation module 510 is configured to perform word segmentation on the code to be processed, and obtain a code sequence including at least one code unit.
[0207] The first determining module 520 is configured to determine the degree of association between any code unit and other code units in the code sequence, based on the feature parameters of any code unit in the code sequence; wherein, the degree of association is used to characterize the degree of dependence between any code unit and other code units.
[0208] The second determining module 530 is configured to determine the highlighting parameters of each code unit based on the correlation degree of each code unit; wherein the highlighting parameters are used to highlight the code unit.
[0209] The code processing apparatus provided in this embodiment performs word segmentation on the code to be processed to obtain a code sequence including at least one code unit; determines the correlation degree between any code unit and other code units in the code sequence based on the feature parameters of any code unit in the code sequence; wherein the correlation degree is used to characterize the degree of dependence between any code unit and other code units; and determines the highlighting parameters of each code unit based on the correlation degree corresponding to each code unit; wherein the highlighting parameters are used to highlight the code unit.
[0210] Thus, unlike related technologies that require designing different word segmentation rules for different programming languages, the embodiments of this disclosure can obtain a code sequence including at least one code unit by performing word segmentation on the code to be processed. Then, based on the feature parameters of any code unit in the code sequence, the correlation between any code unit and other code units in the code sequence is captured to determine the highlighting parameters of each code unit. This allows the same word segmentation rules to be used to achieve code highlighting in different programming languages, improving the versatility of code highlighting. At the same time, since the correlation between any code unit and other code units is calculated after word segmentation, the highlighting parameters of the code unit can be determined through this correlation, thereby reducing the error in highlighting code units and improving the accuracy of highlighting code units.
[0211] for Figure 5 In one possible implementation of the technical solution shown, the first determining module 520 includes:
[0212] The first submodule is configured to determine the similarity between any code unit and other code units based on the first and second feature parameters of any code unit in the code sequence.
[0213] The second submodule is configured to determine the relevance of any code unit based on similarity and a third feature parameter of any code unit in the code sequence.
[0214] The first feature parameter is used to characterize the information that any code unit needs to query in the code sequence, the second feature parameter is used to characterize the information of the code units related to any code unit in the code sequence, and the third feature parameter is used to characterize the semantic information of any code unit.
[0215] for Figure 5 In one possible implementation of the technical solution shown, the second sub-module includes:
[0216] The first calculation module is configured to normalize the similarity to obtain the weight coefficient of any code unit;
[0217] The second calculation module is configured to determine the correlation degree of any code unit based on the weight coefficient and the third feature parameter of any code unit in the code sequence.
[0218] for Figure 5 In one possible implementation of the technical solution shown, the second computing module includes:
[0219] The weighting module is configured to weight the third feature parameters of each code unit based on weight coefficients, and then sum the weighted third feature parameters to obtain the correlation degree.
[0220] The third feature parameter includes a value vector.
[0221] for Figure 5 In one possible implementation of the technical solution shown, the first sub-module includes:
[0222] The third calculation module is configured to perform a dot product calculation on the first feature parameter of any code unit and the second feature parameter of all code units respectively to obtain the similarity between the first feature parameter and the second feature parameter.
[0223] The first feature parameter includes the query vector, and the second feature parameter includes the key vector.
[0224] for Figure 5 In one possible implementation of the technical solution shown, the code processing device 500 further includes:
[0225] The annotation processing module is configured to annotate each code unit in the code sequence to obtain the annotation code corresponding to each code unit.
[0226] The generation module is configured to generate a label sequence based on each labeled code and the position of each corresponding code unit in the code sequence.
[0227] for Figure 5 In one possible implementation of the technical solution shown, the second determining module 530 includes:
[0228] The third submodule is configured to determine the highlighting parameters of each code unit based on the annotation information carried by the label sequence and the correlation between each code unit.
[0229] The annotation information includes type information and semantic information for each code unit.
[0230] for Figure 5 In one possible implementation of the technical solution shown, the third sub-module includes:
[0231] The search module is configured to search for the correlation degree and the type and semantic information of each code unit based on the preset mapping relationship, and obtain the highlight parameters corresponding to each code unit.
[0232] Among them, the preset mapping relationship is used to represent the relationship between type information, semantic information, relevance, and highlighting parameters.
[0233] for Figure 5 In one possible implementation of the technical solution shown, the annotation processing module includes:
[0234] The first annotation submodule is configured to identify characters with preset information from various code units based on a preset named entity recognition model, and to annotate the characters with preset information; and / or,
[0235] The second annotation submodule is configured to classify each character in each code unit into parts of speech based on a preset part-of-speech tagging model, and to annotate the part of speech corresponding to each character.
[0236] for Figure 5 In one possible implementation of the technical solution shown, the highlighting parameters include the color of the code unit and the font style of the code unit.
[0237] It should be noted that, regarding Figure 5 The code processing apparatus in the illustrated embodiment, wherein the specific manner in which each module performs operations has been described in detail in the embodiments related to the method, will not be elaborated upon here.
[0238] Figure 6 This is a schematic diagram illustrating the structure of an electronic device according to an exemplary embodiment. For example, the electronic device 600 may be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.
[0239] Reference Figure 6 The electronic device 600 may include one or more of the following components: processing component 602, memory 604, power supply component 606, multimedia component 608, audio component 610, input / output (I / O) interface 612, sensor component 614, and communication component 616.
[0240] Processing component 602 typically controls the overall operation of electronic device 600, such as operations associated with at least one of display, telephone call, data communication, camera operation, and recording operation. Processing component 602 may include one or more processors 620 to execute instructions to perform all or part of the steps of the methods described above. Furthermore, processing component 602 may include one or more modules to facilitate interaction between processing component 602 and other components. For example, processing component 602 may include a multimedia module to facilitate interaction between multimedia component 608 and processing component 602.
[0241] Memory 604 is configured to store various types of data to support the operation of electronic device 600. Examples of such data include at least one of the following: instructions for any application or method operating on electronic device 600, contact data, phonebook data, messages, pictures, and videos. Memory 604 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0242] Power supply component 606 provides power to various components of electronic device 600. Power supply component 606 may include at least one of the following: a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to electronic device 600.
[0243] Multimedia component 608 includes a screen that provides an output interface between electronic device 600 and user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a Touch Panel, the screen may be implemented as a touchscreen to receive input signals from the user. The Touch Panel includes one or more touch sensors to sense touches, swipes, and gestures on the Touch Panel. The touch sensors may sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 608 includes a front-facing camera and / or a rear-facing camera. When electronic device 600 is in an operating mode, such as a shooting mode or video mode, the front-facing camera and / or rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0244] Audio component 610 is configured to output and / or input audio signals. For example, audio component 610 includes a microphone (MIC) configured to receive external audio signals when electronic device 600 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 604 or transmitted via communication component 616. In some embodiments, audio component 610 also includes a speaker for outputting audio signals.
[0245] I / O interface 612 provides an interface between processing component 602 and peripheral interface modules, such as keyboards, click wheels, and buttons. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0246] Sensor assembly 614 includes one or more sensors for providing state assessments of various aspects of electronic device 600. For example, sensor assembly 614 may detect the on / off state of electronic device 600, the relative positioning of components such as the display and keypad of electronic device 600, changes in position of electronic device 600 or one of its components, the presence or absence of user contact with electronic device 600, orientation or acceleration / deceleration of electronic device 600, and temperature changes of electronic device 600. Sensor assembly 614 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 614 may also include an optical sensor, such as a complementary metal-oxide-semiconductor (CMOS) or charge-coupled device (CCD) image sensor, for use in imaging applications. In some embodiments, sensor assembly 614 may also include, but is not limited to, at least one of the following: an accelerometer, a gyroscope, a magnetometer, a pressure sensor, and a temperature sensor.
[0247] Communication component 616 is configured to facilitate wired or wireless communication between electronic device 600 and other devices. Electronic device 600 can access wireless networks based on communication standards, such as Wi-Fi, 4G, 5G, or combinations thereof. In one exemplary embodiment, communication component 616 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 616 also includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID), Infrared Data Association (IrDA), Ultra Wide Band (UWB), Bluetooth (BT), and other technologies.
[0248] In an exemplary embodiment, the electronic device 600 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components.
[0249] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory including executable instructions or a computer program that can be executed by a processor of an electronic device to perform a code processing method. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device, etc.
[0250] A non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to perform any of the code processing methods described in the above embodiments. For example, the method includes: performing word segmentation on the code to be processed to obtain a code sequence including at least one code unit; determining the correlation degree between any code unit and other code units in the code sequence, based on the feature parameters of any code unit in the code sequence; wherein the correlation degree is used to characterize the degree of dependence between any code unit and other code units; and determining the highlighting parameters for each code unit based on the correlation degree corresponding to each code unit; wherein the highlighting parameters are used to highlight the code unit.
[0251] This disclosure provides a computer program product comprising a computer program or executable instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer program or executable instructions from the computer-readable storage medium and executes the computer program or executable instructions, causing the computer device to perform any of the periodic identification methods described above.
[0252] Figure 7This is a hardware structure block diagram illustrating a code processing apparatus according to an exemplary embodiment. For example, the code processing apparatus 700 may be provided as a server. (Refer to...) Figure 7 The code processing apparatus 700 includes a processing component 722, which further includes one or more processors, and memory resources represented by a memory 732 for storing instructions executable by the processing component 722, such as application programs. The application programs stored in the memory 732 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 722 is configured to execute instructions to perform any of the aforementioned code processing methods. For example, the method includes: performing word segmentation on the code to be processed to obtain a code sequence including at least one code unit; determining the correlation degree between any code unit and other code units in the code sequence, excluding the code unit itself, based on feature parameters of any code unit in the code sequence; wherein the correlation degree characterizes the degree of dependence between any code unit and other code units; and determining highlight parameters for each code unit based on the correlation degree corresponding to each code unit; wherein the highlight parameters are used to highlight the code unit.
[0253] The code processing device 700 may also include a power supply component 726 configured to perform power management of the code processing device 700, a wired or wireless network interface 750 configured to connect the code processing device 700 to a network, and an input / output (I / O) interface 758. The code processing device 700 can operate an operating system stored in memory 732, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or similar.
[0254] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0255] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the claims.
[0256] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A code processing method, characterized in that, include: The code to be processed is segmented into words to obtain a code sequence that includes at least one code unit. Based on the feature parameters of any code unit in the code sequence, the correlation degree between the any code unit and other code units in the code sequence is determined; wherein, the correlation degree is used to characterize the degree of dependence between the any code unit and the other code units; Based on the correlation degree corresponding to each code unit, the highlighting parameters of each code unit are determined respectively; wherein, the highlighting parameters are used to highlight the code unit.
2. The method according to claim 1, characterized in that, Determining the correlation between any code unit and other code units in the code sequence based on the feature parameters of any code unit in the code sequence includes: Based on the first and second feature parameters of any code unit in the code sequence, determine the similarity between any code unit and the other code units; Based on the similarity and the third feature parameter of any code unit in the code sequence, the degree of association corresponding to any code unit is determined; Wherein, the first feature parameter is used to characterize the information that the any code unit needs to query in the code sequence, the second feature parameter is used to characterize the information of the code units related to the any code unit in the code sequence, and the third feature parameter is used to characterize the semantic information of the any code unit.
3. The method according to claim 2, characterized in that, Determining the correlation degree corresponding to any code unit based on the similarity and the third feature parameter of any code unit in the code sequence includes: The similarity is normalized to obtain the weight coefficient of any code unit; The correlation degree corresponding to any code unit is determined based on the weight coefficient and the third feature parameter of any code unit in the code sequence.
4. The method according to claim 3, characterized in that, Based on the weighting coefficients and the third feature parameter of any code unit in the code sequence, the correlation degree corresponding to any code unit is determined, including: Based on the weight coefficients, the third feature parameters of each code unit are weighted and then summed to obtain the correlation degree. The third feature parameter includes a value vector.
5. The method according to claim 2, characterized in that, Determining the similarity between any code unit and the other code units based on the first and second feature parameters of the code unit in the code sequence includes: The first feature parameter of any code unit is multiplied by the second feature parameter of all code units to obtain the similarity between the first feature parameter and the second feature parameter. The first feature parameter includes a query vector, and the second feature parameter includes a key vector.
6. The method according to any one of claims 1 to 4, characterized in that, The method further includes: Each code unit in the code sequence is annotated to obtain the annotated code corresponding to each code unit; A tag sequence is generated based on the position of each of the aforementioned annotation codes and the corresponding code units in the code sequence.
7. The method according to claim 6, characterized in that, The step of determining the highlighting parameters for each code unit based on the correlation degree of each code unit includes: Based on the annotation information carried by the tag sequence and the correlation degree of each code unit, the highlighting parameters of each code unit are determined; The annotation information includes type information and semantic information for each code unit.
8. The method according to claim 7, characterized in that, The step of determining the highlighting parameters of each code unit based on the annotation information carried by the tag sequence and the correlation degree of each code unit includes: Based on the preset mapping relationship, the correlation degree and the type information and semantic information of each code unit are searched to obtain the highlighting parameters corresponding to each code unit; The preset mapping relationship is used to characterize the relationship between the type information, the semantic information, the correlation degree, and the highlighting parameters.
9. The method according to claim 6, characterized in that, The step of annotating each code unit in the code sequence to obtain the annotated code corresponding to each code unit includes: Based on a preset named entity recognition model, characters with preset information are identified from each of the code units, and the characters with the preset information are labeled; and / or, Based on a pre-defined part-of-speech tagging model, each character in each code unit is classified into parts of speech, and the part of speech corresponding to each character is tagged.
10. The method according to any one of claims 1 to 4, characterized in that, The highlighting parameters include the color of the code unit and the font style of the code unit.
11. A code processing device, characterized in that, include: The word segmentation module is configured to segment the code to be processed to obtain a code sequence that includes at least one code unit. The first determining module is configured to determine the degree of correlation between any code unit and other code units in the code sequence, based on the feature parameters of any code unit in the code sequence; wherein the degree of correlation is used to characterize the degree of dependence between any code unit and the other code units; The second determining module is configured to determine the highlighting parameters of each code unit based on the correlation degree corresponding to each code unit; wherein the highlighting parameters are used to highlight the code unit.
12. An electronic device, characterized in that, include: processor; Memory used to store computer programs or instructions; The processor executes the computer program or instructions to implement the steps of the method according to any one of claims 1 to 10.
13. A non-transitory computer-readable storage medium storing a computer program or instructions, characterized in that, When the computer program or instructions in the storage medium are executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
14. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 10.