Annotation recognition method, device, equipment and computer-readable storage medium

By segmenting the program code and identifying symbols, the problem of low annotation recognition accuracy when the programming language cannot be predicted is solved, universal annotation recognition is achieved, and the misjudgment rate is reduced.

CN114610382BActive Publication Date: 2024-10-18CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011444403.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-08
Publication Date
2024-10-18
Estimated Expiration
2040-12-08

AI Technical Summary

Technical Problem

When the specific programming language cannot be predicted in the existing technology, the annotation recognition accuracy is low, and different solutions need to be designed for different programming languages, which lacks versatility, and irregularly written annotations may lead to misjudgment.

Method used

By segmenting the program code, determining the line start symbol and line end symbol, determining the comment identifier based on these symbols, and performing comment recognition, the comment recognition in the program code is realized.

Benefits of technology

Without knowing the specific programming language, it improves the accuracy of annotation identification, has universality, reduces misjudgments, and enhances the ability to identify irregular annotations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114610382B_ABST
    Figure CN114610382B_ABST
Patent Text Reader

Abstract

The present application provides a comment recognition method, device, equipment and computer-readable storage medium, the method comprising: segmenting the acquired program code to be recognized to obtain at least one text line, the program code comprising code and comments; determining the line start character of the text line according to the first character of the text line, and determining the line end character of the text line according to the last character of the text line; determining the comment identifier in the program code based on the line start character and the line end character; and performing comment recognition on the program code based on the comment identifier to obtain a recognition result. The present application can realize the recognition of comments in the program code without knowing the specific programming language in advance, is independent of the specific programming language, has universality, and can improve the accuracy of comment recognition for unpredictable specific programming languages.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer programming technology, and relates to but is not limited to an annotation recognition method, device, equipment and computer-readable storage medium. Background Art

[0002] Software code usually consists of two parts: code and comments. Among them, code is a string that conforms to the special syntax specifications of the programming language, which can be converted by tools such as compilation and interpretation, and executed on the computer, expressing the process of how the business logic of the software is implemented. Comments are strings that conform to the grammar of human natural language, generally existing in the header of the code file, the header of the function, and inside the program block, etc., used to explain the ideas and reasons for the implementation of business logic, and have no effect during the execution of the program.

[0003] The extraction of comments in software code is of great value for analyzing the quality of the software development process, identifying inconsistencies between comments and code implementations, and analyzing the relationship between the same topic in comments and multiple codes. The comment recognition methods in related technologies require different implementation schemes for different programming languages ​​and are not universal. In particular, for software projects that are developed in a large number of different programming languages ​​and are subject to dynamic upgrades and changes, the recognition ability is insufficient, and misjudgment may occur for comments that are not written in a standardized manner, resulting in low comment recognition accuracy. Summary of the invention

[0004] In view of this, the present application provides an annotation recognition method, apparatus, device and computer-readable storage medium, which at least solve the problem of low annotation recognition accuracy when the specific programming language cannot be predicted.

[0005] The technical solution of the embodiment of the present application is implemented as follows:

[0006] At least one embodiment of the present application provides an annotation recognition method, the method comprising:

[0007] Segmenting the acquired program code to be identified to obtain at least one text line, wherein the program code includes code and comments;

[0008] Determine the start character of the text line according to the first character of the text line, and determine the end character of the text line according to the last character of the text line;

[0009] Determining a comment mark in the program code based on the line start character and the line end character;

[0010] Annotation recognition is performed on the program code based on the annotation identifier to obtain a recognition result.

[0011] In addition, according to at least one embodiment of the present application, the segmentation process of the acquired program code to be identified to obtain at least one text line includes:

[0012] Obtaining the program code to be identified and a preset line ending mark;

[0013] Segment the program code according to the line end identifier to obtain a plurality of segmented lines;

[0014] Delete blank lines from the multiple segmentation lines to obtain at least one text line, wherein the blank line is a segmentation line containing only blank characters.

[0015] In addition, according to at least one embodiment of the present application, determining the line start character of the text line according to the first character of the text line includes:

[0016] Extract the first non-blank character in each line of text;

[0017] When it is determined that the first non-blank character of the current text line is not an English character, the first non-blank character of the current text line is determined as the line start character of the current text line;

[0018] When it is determined that the first non-blank character of the current text line is an English character, the blank character is determined as the line start character of the current text line.

[0019] In addition, according to at least one embodiment of the present application, determining the line terminator of the text line according to the line end character of the text line includes:

[0020] Extract the last non-blank character in each line of text;

[0021] When it is determined that the last non-blank character of the current text line is neither an English character nor a Chinese character, the last non-blank character of the current text line is determined as the line terminator of the current text line;

[0022] When it is determined that the last non-blank character of the current text line is an English character or a Chinese character, and there is a line start character in the current text line, a blank character is determined as the line end character of the current text line;

[0023] When it is determined that the last non-blank character of the current text line is an English character or a Chinese character, and there is no line start character in the current text line, the line end character of the next text line of the current text line is determined as the line end character of the current text line.

[0024] In addition, according to at least one embodiment of the present application, determining the comment mark in the program code based on the line start character and the line end character includes:

[0025] Based on the characters included in the text line, determining the number of target segmented words included in the text line, wherein the part of speech of the target segmented words is not a noun;

[0026] Determine the comment start mark based on the line start mark of each text line and the number of target segmented words, and determine the comment end mark based on the line end mark of each text line and the number of target segmented words;

[0027] The comment start marker and the comment end marker are determined as comment markers.

[0028] In addition, according to at least one embodiment of the present application, before determining the number of target segmented words included in the text line based on the characters included in the text line, the method further includes:

[0029] Perform word segmentation on the characters included in the current text line according to the preset segmentation rules to obtain each word segment of the current text line;

[0030] The part of speech of each word segment is obtained.

[0031] In addition, according to at least one embodiment of the present application, determining the comment start marker based on the line start symbol of each text line and the number of target segmented words includes:

[0032] Based on the target number of segmented words in each text line and the line start symbol of each text line, determine the total support number of each line start symbol that is not a blank character, the total support number of the line start symbol being the sum of the target number of segmented words included in each text line corresponding to the line start symbol;

[0033] Determine the total number of target text lines corresponding to each line start symbol, wherein the target text lines only include text lines of noun participles;

[0034] Calculate the difference between the total support number of each line start character that is not a blank character and the corresponding total number of lines to obtain the start support number of each line start character that is not a blank character;

[0035] The line start character corresponding to the maximum start support number is determined as the comment start marker.

[0036] In addition, according to at least one embodiment of the present application, determining the comment end mark based on the line terminator of each text line and the number of target segmented words includes:

[0037] Based on the target number of segmented words in each text line and the line terminator of each text line, determine the total support number of each line terminator that is not a blank character, the total support number of the line terminator being the sum of the target number of segmented words included in each text line corresponding to the line terminator;

[0038] Determine the total number of target text lines corresponding to each line ending character, wherein the target text lines only include text lines of noun participles;

[0039] Calculate the difference between the total support number of each line terminator that is not a blank character and the corresponding total number of lines to obtain the end support number of each line terminator that is not a blank character;

[0040] The line terminator corresponding to the maximum end support number is determined as the comment end marker.

[0041] In addition, according to at least one embodiment of the present application, the performing annotation recognition on the program code based on the annotation identifier to obtain a recognition result includes:

[0042] Adding a text line whose line start character is the comment start mark to the first text line set;

[0043] Adding a text line whose line terminator is the comment end mark to the second text line set;

[0044] A union of the first text line set and the second text line set is determined as the recognized comment line.

[0045] In addition, according to at least one embodiment of the present application, after determining the union of the first text line set and the second text line set as the recognized comment line, the method further includes:

[0046] The text lines in the program code other than the comment lines are determined as the identified code lines.

[0047] At least one embodiment of the present application provides an annotation recognition device, the device comprising:

[0048] A segmentation module, used for segmenting the acquired program code to be identified to obtain at least one text line, wherein the program code includes code and comments;

[0049] A first determination module, used to determine the start character of the text line according to the first character of the text line, and to determine the end character of the text line according to the last character of the text line;

[0050] A second determination module, configured to determine a comment mark in the program code based on the line start character and the line end character;

[0051] The recognition module is used to perform annotation recognition on the program code based on the annotation identifier to obtain a recognition result.

[0052] At least one embodiment of the present application provides an annotation recognition device, including:

[0053] Processor; and

[0054] a memory for storing a computer program executable on the processor;

[0055] Wherein, when the computer program is executed by the processor, the steps of the above-mentioned annotation recognition method are implemented.

[0056] At least one embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute the steps of the above-mentioned annotation recognition method.

[0057] The embodiment of the present application provides a comment recognition method, device, equipment and computer-readable storage medium, the method comprising: segmenting the acquired program code to be recognized to obtain at least one text line, the program code comprising code and comments; determining the line start character of the text line according to the first character of the text line, and determining the line end character of the text line according to the last character of the text line; determining the comment identifier in the program code based on the line start character and the line end character; and performing comment recognition on the program code based on the comment identifier to obtain a recognition result. The present application can realize the recognition of comments in the program code without knowing the specific programming language in advance, is independent of the specific programming language, has universality, and can improve the accuracy of comment recognition for unpredictable specific programming languages. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] In the drawings, which are not necessarily drawn to scale, like reference numerals may describe similar components in different views.The drawings generally illustrate, by way of example and not limitation, various embodiments discussed herein.

[0059] Figure 1 A schematic diagram of an implementation flow of the annotation recognition method provided in an embodiment of the present application;

[0060] Figure 2 For program code including code and comments;

[0061] Figure 3 A schematic diagram of another implementation flow of the annotation recognition method provided in an embodiment of the present application;

[0062] Figure 4 A schematic diagram of another implementation flow of the annotation recognition method provided in the embodiment of the present application;

[0063] Figure 5 A schematic diagram of the structure of the annotation recognition device provided in the embodiment of the present application;

[0064] Figure 6 A schematic diagram of the composition structure of the annotation recognition device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0065] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.

[0066] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0067] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0068] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0069] Based on the problems existing in the related art, an embodiment of the present application provides an annotation recognition method, which is applied to an annotation recognition device. The method provided by the embodiment of the present application can be implemented by a computer program, and when the computer program is executed, each step of the annotation recognition method provided by the embodiment of the present application is completed. In some embodiments, the computer program can be executed by a processor in the annotation recognition device. Figure 1 A schematic diagram of an implementation flow of the annotation recognition method provided in the embodiment of the present application is as follows: Figure 1 As shown, the annotation recognition method comprises the following steps:

[0070] Step S101, segmenting the acquired program code to be recognized to obtain at least one text line.

[0071] In the embodiment of the present application, the annotation recognition device may be a user equipment (UE), a mobile device, a terminal, a laptop computer, a tablet computer, a desktop computer, or other device capable of performing annotation recognition.

[0072] The program code to be identified includes code and comments. Code is a string that conforms to the special syntax specification of the programming language, which can be converted by tools such as compilation and interpretation and executed on the computer, expressing the process of how the business logic of the software is implemented. Comments are strings that conform to the grammar of human natural language, generally existing in the header of the code file, the header of the function, and inside the program block, etc., used to explain the ideas and reasons for the implementation of the business logic, and have no effect during the execution of the program. Figure 2 For program code including code and comments, see Figure 2 , where lines 9 to 15 are a code, and lines 5 to 8 are comments.

[0073] In the embodiment of the present application, the program code to be identified is a text file. The character "\n" of the American Standard Code for Information Interchange (ASCII) can be used to determine the end of a single line of text. Based on this, the character "\n" is used to segment the text in different lines of the program code to obtain at least one text line.

[0074] For example, the program code obtained in the embodiment of the present application is as follows:

[0075] / / this is a function

[0076] int add(int a,int b)

[0077] {int move = a + b;

[0078] return move;}

[0079] / *this is a single line comment* /

[0080] / *

[0081] this

[0082] is

[0083] a

[0084] multiline

[0085] comments

[0086] * /

[0087] The text lines obtained by segmenting based on the line break character "\n" are shown in Table 1:

[0088] Table 1 Segmented text lines

[0089] / / this is a function int add(int a,int b) {int move = a + b; return move;} / *this is a single line comment* / / * this is a multiline comments * /

[0090] In actual implementation, for the convenience of storage, the text lines obtained by segmentation are numbered at the same time, and the text lines and the numbers corresponding to the text lines are stored in the form of a list. The i-th row element of the list is recorded as<wl-i,ln(wl-i)> , where the i-th variable wl-i stores the content of the i-th line of text, and the line number corresponding to the line of text is stored in the variable ln(wl-i). Then the ordered list WL=(<wl-1,ln(wl-1)> , …,<wl-N,ln(wl-N)> )

[0091] The program code obtained above is divided into the following list:

[0092] WL={<" / / this is a function", 1>, <"int add(int a, int b)", 2>, <"{intmove=a+b;", 3>, <"return move;}", 4>, <" / *this is a single line comment* / ", 5>, <" / *", 6>, <"this", 7>, <"is", 8>, <"a", 9>, <"multiline", 10>, <"comments", 11>, <"* / ", 12>}

[0093] For ease of understanding, the list WL is presented in a table, as shown in Table 2:

[0094] Table 2 Storage list of text lines

[0095]

[0096]

[0097] Step S102, determining the start character of the text line according to the first character of the text line, and determining the end character of the text line according to the last character of the text line.

[0098] ASCII code uses a specified 7-bit or 8-bit binary number combination to represent 128 or 256 possible characters. Standard ASCII code, also called basic ASCII code, uses 7-bit binary numbers (the remaining 1 bit is 0) to represent all uppercase and lowercase letters, numbers 0 to 9, punctuation marks, and special control characters used in American English. Among them:

[0099] ASCII codes include control characters (or communication-specific characters) and displayable characters, among which:

[0100] 0 to 31 and 127 (33 in total) are control characters or communication-specific characters, and the rest are displayable characters, such as control characters: LF (line feed), CR (carriage return), FF (form feed), DEL (delete), BS (backspace), BEL (bell), etc.; communication-specific characters: SOH (head of text), EOT (end of text), ACK (acknowledgement), etc. ASCII values ​​8, 9, 10, and 13 are backspace, tab, line feed, and carriage return, respectively. They do not have specific graphic displays, but have different effects on text display.

[0101] 32 to 126 (a total of 95) are displayable characters, of which 32 is a space character, 48 to 57 are ten Arabic numerals from 0 to 9, 65 to 90 are 26 uppercase English letters, 97 to 122 are 26 lowercase English letters, and the rest are some punctuation marks, operation symbols, etc.

[0102] When programming, symbols are generally used as comment markers. Control characters or communication-specific characters, space characters, numbers, and English letters are not used as comment markers. Therefore, the line start symbol and line end symbol can be characters other than 0 to 32, 48 to 57, 65 to 90, 97 to 122, and 127 in ASCII, that is, they can be characters in 33 to 47, 58 to 64, 91 to 96, and 123 to 126.

[0103] When it is a single-line comment (i.e., line comment), the comment mark can only have a comment start marker, but general program codes support multi-line comments (i.e., paragraph comments). Therefore, the comment marker includes a comment start marker and a comment end marker. The comment start marker represents the beginning of the comment, and the comment end marker represents the end of the comment. The text lines between the comment start marker and the comment end marker are all comments.

[0104] In standard program code, the comment start marker is usually at the beginning of a line. Based on this, the line start symbol of the current text line is determined according to the first character of the current text line. For example, the first character "\" of the first line of text is determined as the line start symbol of the first line; when the first character of the current text line is an English character, the line start symbol of the current text line is determined to be NULL, that is, there is no line start symbol for the current text line.

[0105] In standard program code, the comment end marker is generally at the end of the line. Based on this, the line terminator of the current text line is determined according to the end character of the current text line. For example, the end character ")" of the second line is determined as the line terminator of the second line; when the end character of the current text line is an English character or a Chinese character, at this time, it is necessary to further determine the line terminator of the current text line according to the end character of the following text line.

[0106] Step S103: Determine the comment mark in the program code based on the line start character and the line end character.

[0107] The line start and end symbols of each text line may be different. From multiple different line start symbols, a line start symbol is determined as a comment start mark according to a certain rule, and from multiple different line end symbols, a line end symbol is determined as a comment end mark according to a certain rule. Thus, a comment mark including a comment start mark and a comment end mark is obtained.

[0108] Still taking the above program code as an example, for example, the comment start mark is determined to be “ / ” and the comment end mark is determined to be “ / ”. The comment start mark and the comment end mark may be the same or different.

[0109] Step S104: perform annotation recognition on the program code based on the annotation identifier to obtain a recognition result.

[0110] According to the comment start mark determined in step S103, the start position of the comment is identified in the program code, and according to the comment end mark, the end position of the comment is identified in the program code. The program code between the start position and the end position is the comment part of the program code, which is used to explain the code part. The other part except the comment part is the code part of the program code, which is the part of the program code that actually runs.

[0111] For example, the comment start mark is " / ", and the comment end mark is " / ", and the recognized comment is:

[0112] / / this is a function

[0113] / *this is a single line comment* /

[0114] / *

[0115] this

[0116] is

[0117] a

[0118] multiline

[0119] comments

[0120] * /

[0121] In the embodiment of the present application, the annotation recognition method is automatically executed without the need to know the specific programming language in advance. Compared with manual recognition, it can greatly improve the accuracy of annotation recognition and improve the recognition efficiency.

[0122] The comment recognition method provided by the embodiment of the present application includes: segmenting the acquired program code to be recognized to obtain at least one text line, wherein the program code includes code and comments; determining the line start character of the text line according to the first character of the text line, and determining the line end character of the text line according to the last character of the text line; determining the comment identifier in the program code based on the line start character and the line end character; and performing comment recognition on the program code based on the comment identifier to obtain a recognition result. The present application can realize the recognition of comments in the program code without knowing the specific programming language in advance, does not rely on the specific programming language, has universality, and can improve the accuracy of comment recognition for unpredictable specific programming languages.

[0123] In some embodiments, the above step S101 of "segmenting the acquired program code to be identified to obtain at least one text line" can be implemented by the following steps.

[0124] Step S1011, obtaining the program code to be identified and a preset line end mark.

[0125] In an embodiment of the present application, the program code to be identified can be input into the annotation recognition device by a user, or the user can specify a path and the annotation recognition device can obtain it according to the specified path, or the annotation recognition device can automatically obtain it according to preset conditions based on a start recognition instruction.

[0126] In the embodiment of the present application, the program code may be segmented by line, and the preset line end marker may be a line feed character “\n”.

[0127] Step S1012: segment the program code according to the line end identifier to obtain a plurality of segmented lines.

[0128] Based on the line break character "\n", the obtained program code to be identified is segmented in a line segmentation manner, and each segmentation obtains a segmented line. The entire program code is segmented to obtain multiple segmented lines.

[0129] In actual implementation, there may be non-standard code writing, such as writing multiple lines of code in one line, not indenting, etc., or format incompatibility may occur when saving as a text file. Therefore, before executing step S1012, the program code to be identified may be standardized. For example, when writing the code, {int move = a + b; return move;} is written in one line, and standardized according to the coding specification to obtain

[0130]

[0131] After standardization, the program code can be easier to view and more readable.

[0132] Step S1013, deleting blank lines from the multiple segmented lines to obtain at least one text line.

[0133] The blank line is a line that contains only blank characters, i.e., a blank line. Blank characters include space, horizontal tab "\t", vertical tab "\v", carriage return "\r", line feed "\n" and page feed "\f". Blank characters take up space in the program code, but there is no text. A blank line may include at least one of the blank characters, space, horizontal tab "\t", vertical tab "\v", carriage return "\r", line feed "\n" and page feed "\f", and does not include other characters except blank characters.

[0134] In some embodiments, different code blocks may be separated by blank lines in the program code. Blank lines are not code lines, but they do not have any practical meaning as comment lines. Blank lines that are only used for separation and have no practical meaning can be deleted.

[0135] For example, a snippet from the program code is as follows:

[0136] / / this is a function

[0137] int add(int a,int b)

[0138] {int move = a + b;

[0139] return move;}

[0140] The above program fragment is split into lines according to the line break character "\n", and 5 split lines are obtained. The second split line only includes space characters, which occupy a place in the text but have no text. The second split line is a blank line. Delete the second split line to get all non-blank split lines:

[0141] / / this is a function

[0142] int add(int a,int b)

[0143] {int move = a + b;

[0144] return move;}

[0145] Deleting blank lines and not storing them in the WL list can not only save storage space, but also reduce the number of recognized lines and improve recognition efficiency.

[0146] In some embodiments, Figure 1 In the illustrated embodiment, "determining the line start character of the text line according to the first character of the text line" in step S102 can be implemented by the following steps.

[0147] Step S1021, extracting the first non-blank character in each text line.

[0148] Step S1022, determining whether the first non-blank character of the current text line is an English character.

[0149] When it is determined that the first non-blank character of the current text line is not an English character, it indicates that the first non-blank character may be a comment start symbol, and the current text line may be a comment. At this time, go to step S1023; when it is determined that the first non-blank character of the current text line is an English character, it indicates that the current text line is a code, and go to step S1024.

[0150] Step S1023, determining the first non-blank character of the current text line as the line start character of the current text line.

[0151] Step S1024, determining the space character as the line start character of the current text line.

[0152] In some embodiments, Figure 1 In the illustrated embodiment, "determining the line terminator of the text line according to the line-end character of the text line" in step S102 can be implemented by the following steps.

[0153] Step S1025, extract the last non-blank character in each text line.

[0154] Step S1026, determining whether the last non-blank character of the current text line is an English character or a Chinese character.

[0155] When it is determined that the last non-blank character of the current text line is neither an English character nor a Chinese character, it indicates that the last non-blank character may be a comment end symbol, and the current text line may be a comment. At this time, enter step S1027; when it is determined that the last non-blank character of the current text line is an English character or a Chinese character, and there is a line start character in the current text line, it indicates that the current text line may be a comment, but whether it is a comment is determined by the line start character. At this time, the line end character of the current text line is set to a null character, and enter step S1028; when it is determined that the last non-blank character of the current text line is an English character or a Chinese character, and there is no line start character in the current text line, it indicates that the current text line is the middle line of multiple lines of comments. At this time, enter step S1029.

[0156] Step S1027, determining the last non-blank character of the current text line as the line terminator of the current text line.

[0157] Step S1028, determine the space character as the line terminator of the current text line.

[0158] Step S1029, determining the line terminator of the next text line of the current text line as the line terminator of the current text line.

[0159] Taking the above program code as an example, the start character of each text line is determined according to the first character of each text line, recorded as sc, and the end character of each text line is determined according to the last character of each text line, recorded as ec. The results are shown in Table 3:

[0160] Table 3 Line start and end characters of text lines

[0161]

[0162] It should be noted that in Table 3, the empty character is represented as NULL.

[0163] In some embodiments, Figure 1 In the illustrated embodiment, step S103 “determining the comment mark in the program code based on the line start character and the line end character” can be implemented by the following steps S1031 to S1036.

[0164] Step S1031, performing word segmentation processing on the characters included in the current text line according to a preset segmentation rule to obtain each word segment of the current text line.

[0165] Step S1032, obtaining the part of speech of each word segment.

[0166] In actual implementation, the word segmentation processing can be performed based on the pre-built domain knowledge graph (KG, Knowledge Graph) and domain action model set (AG, Action model Gather) and text word segmentation software. The part of speech of each word segmentation can be determined based on the part of speech tagging results of the text part of speech tagging software and the part of speech tagging results based on the open source natural language processing tool of Stanford University. The word segmentation results of the above program code and the part of speech of each word segmentation are shown in Table 4.

[0167] Table 4 Each word in each text line and the part of speech of each word

[0168]

[0169] Step S1033, based on the characters included in the text line, determine the number of target word segments included in the text line.

[0170] The part of speech of the target word is not a noun.

[0171] For example, the non-noun participles of the first text line include this, is, and a, so the target participles are this, is, and a; the number of target participles in this line is 3. For another example, the non-noun participles of the fourth text line do not exist, that is, there are no target participles; the number of target participles in this line is 0.

[0172] Step S1034, determining the comment start marker based on the line start symbol of each text line and the number of target segmented words.

[0173] Step S1035, determining the comment end marker based on the line terminators of each text line and the number of target segmented words.

[0174] Since there may be multiple characters among 33-47, 58-64, 91-96, 123-126 in the program code, the determined line start characters and line end characters may be multiple. In the embodiment of the present application, the support number of each line start character and line end character is calculated respectively, and the line start character with the largest support number among the multiple line start characters is used as the comment start mark, and the line end character with the largest support number among the multiple line end characters is used as the comment end mark.

[0175] Step S1036: determine the annotation start marker and the annotation end marker as annotation markers.

[0176] In an embodiment of the present application, without knowing the specific programming language in advance, by obtaining the line start symbol and line end symbol of each text line, and determining the comment identifier based on the support number of the line start symbol and the line end symbol, it is possible to implement comment recognition that is independent of the programming language, has universality, and can improve the accuracy of comment recognition for unpredictable specific programming languages.

[0177] In some embodiments, the above step S1034 "determining the annotation start mark based on the line start symbol of each text line and the number of target segmented words" can be implemented by the following steps:

[0178] Step S10341, based on the target number of word segments of each text line and the line start symbol of each text line, determine the total support number of each line start symbol that is not a blank character.

[0179] First, determine the support number of each line start symbol in each text line, then add up the support numbers of the same line start symbol in each text line to obtain the total support number of each line start symbol. That is, the total support number of the line start symbol is the sum of the number of target word segments included in each text line corresponding to the line start symbol.

[0180] The support number of each line start character in each line + support(cs) is shown in Table 5.

[0181] Table 5 Support number of each line start character and each line end character in each line

[0182]

[0183]

[0184] In Table 5, +support(cs) represents the number of supports for each line start symbol in each line, and +support(ce) represents the number of supports for each line end symbol in each line.

[0185] Referring to Table 5, the number of target segmented words in the first text line is 3, and the line start character is ' / ', so the support number of the line start character ' / ' in the first line is 3; the support number of the line start character ' / ' in each line is determined, and the support number in the fifth line is 3, and the support number in the sixth line is 0. Thus, the total support number of the line start character ' / ' is support(' / ')=3+3+0=6.

[0186] The total support number of each line start character is determined, and the total support number of the line start character '{' is obtained as support('{')=0+0=0; the support number of the line start character '*' is obtained as support('*')=0.

[0187] Step S10342, determine the total number of target text lines corresponding to each line start character.

[0188] Here, the target text behavior only includes text lines of noun participles.

[0189] For example, if the first line contains non-noun participles, then this line is not the target text line. All participles in the third line are nouns, so the third line is determined to be the target text line. From Table 5, the target text lines are the third, fourth, tenth, and eleventh lines. Among them, the third line is the target text line with the line start symbol '{', and the line start symbols of the fourth, tenth, and eleventh lines do not exist.

[0190] If the target text line of the line start character ' / ' does not exist, the total number of target text lines corresponding to the line start character ' / ' is 0. If the target text line of the line start character '{' is the 3rd line, the total number of target text lines corresponding to the line start character '{' is 1. If the target text line of the line start character '*' does not exist, the total number of target text lines corresponding to the line start character '*' is 0.

[0191] Step S10343, calculating the difference between the total support number of each line start character that is not a blank character and the corresponding total number of lines, and obtaining the start support number of each line start character that is not a blank character.

[0192] Subtract the total support number of each line start character from the corresponding total number of lines to obtain the start support number of each line start character that is not a blank character.

[0193] For example, the total support number of the line start character ' / ' is subtracted from the corresponding total number of lines, and we get the starting support number of the line start character ' / ' sup(' / ')=6-0=6; the starting support number of the line start character '{' sup('{')=0-1=-1; the starting support number of the line start character '*' sup('*')=0-0=0.

[0194] Step S10344, determine the line start symbol corresponding to the maximum start support number as the comment start marker.

[0195] Among the line start characters ' / ', '{' and '*', the line start character with the largest number of support is ' / ', and the comment start mark is determined to be ' / '.

[0196] In some embodiments, the above step S1035 "determining the annotation start mark based on the line start symbol of each text line and the number of target segmented words" can be implemented by the following steps:

[0197] Step S10351, based on the target number of word segments in each text line and the line terminators in each text line, determine the total support number of each line terminator that is not a blank character.

[0198] First, determine the support number of each line terminator in each text line, then add up the support numbers of the same line terminator in each text line to obtain the total support number of each line terminator. That is, the total support number of the line terminator is the sum of the number of target word segments included in each text line corresponding to the line terminator.

[0199] The support number of each line terminator in each line + support(ce) is shown in Table 5.

[0200] See Table 5, the number of target words in the first text line is 3, and its line terminator is NULL (i.e., null character). Determine the support number of the line terminator ' / ' in each line, and get the support number in the 5th line is 3, the support numbers in the 7th, 8th, and 9th lines are all 1, and the support numbers in the 10th, 11th, and 12th lines are all 0, so the total support number of the line terminator ' / ' is support(' / ')=3+1+1+1+0+0+0=6.

[0201] Determine the total support number for each line terminator, and obtain the total support number of the line terminator ')' support(')')=1; the support number of the line terminator ';' support(';')=0; the support number of the line terminator '}' support('}')=0; the support number of the line terminator '*' support('*')=0.

[0202] Step S10352, determine the total number of target text lines corresponding to each line ending character.

[0203] Here, the target text behavior only includes text lines of noun participles.

[0204] For example, if the first line contains non-noun participles, then this line is not the target text line. The part of speech of all the participles in the third line are nouns, so the third line is determined to be the target text line. From Table 5, the target text lines are the third, fourth, tenth, and eleventh lines. Among them, the third line is the target text line with the line ending symbol ';', the fourth line is the target text line with the line ending symbol '}', and the tenth and eleventh lines are the target text lines with the line ending symbol ' / '.

[0205] The total number of target text lines corresponding to the line terminator ' / ' is 2. The total number of target text lines corresponding to the line terminator ')' is 0. The total number of target text lines corresponding to the line terminator ';' is 1. The total number of target text lines corresponding to the line terminator '}' is 1. The total number of target text lines corresponding to the line terminator '*' is 0.

[0206] Step S10353, calculating the difference between the total support number of each line terminator that is not a blank character and the corresponding total number of lines, and obtaining the end support number of each line terminator that is not a blank character.

[0207] Subtract the total support count of each line terminator from the corresponding total number of lines to obtain the end support count of each line terminator that is not a blank character.

[0208] For example, the total support number of the line terminator ' / ' is subtracted from the corresponding total number of lines, and we get the end support number of the line terminator ' / ' sup(' / ')=6-2=4; the end support number of the line terminator ')' sup(')')=1-0=1; the end support number of the line terminator ';' sup(';')=0-1=-1; the end support number of the line terminator '}' sup('}')=0-1=-1; the end support number of the line start character '*' sup('*')=0-0=0.

[0209] Step S10354, determine the line terminator corresponding to the maximum end support number as the comment end marker.

[0210] Among the line terminators ' / ', ')', ';', '}' and '*', the line terminator with the largest number of end support is ' / ', and the comment end marker is determined to be ' / '.

[0211] In some embodiments, Figure 1 In the illustrated embodiment, step S104 “performing annotation recognition on the program code based on the annotation identifier to obtain a recognition result” can be implemented by the following steps:

[0212] Step S1041, adding the text line whose line start character is the comment start mark to the first text line set.

[0213] Add the text lines starting with ' / ' to the set WL1, and we get:

[0214] WL1={

[0215] * / <" / / this is a function",1>,

[0216] <" / *this is a single line comment* / ", 5>,

[0217] <“ / *”, 6>

[0218] }.

[0219] Step S1042, adding the text line whose line terminator is the comment end mark to the second text line set.

[0220] Add the text lines ending with ' / ' to the set WL2, and we get:

[0221] WL2={

[0222] <"this",7>,

[0223] <"is",8>,

[0224] <"a",9>,

[0225] <"multiline",10>,

[0226] <"comments", 11>,

[0227] <“* / ”,12>

[0228] }.

[0229] Step S1043: determine the union of the first text line set and the second text line set as the recognized comment line.

[0230] Here, the comment line is the comment recognition result obtained by performing comment recognition on the program code using the recognition method provided in the embodiment of the present application, and the comment recognition result is the comment included in the program code.

[0231] Get the union of WL1 and WL2, and get the annotated recognition result WL-C as:

[0232] WL-C={

[0233] <" / / this is a function",1>,

[0234] <" / *this is a single line comment* / ", 5>,

[0235] <“ / *”, 6>,

[0236] <"this",7>,

[0237] <"is",8>,

[0238] <"a",9>,

[0239] <"multiline",10>,

[0240] <"comments", 11>,

[0241] <“* / ”,12>

[0242] }.

[0243] In some embodiments, after the comment lines in the program code are identified, the text lines in the program code that are not comment lines can be determined as code lines in the program code. Based on this, after the above step S1043, the following may also be included:

[0244] Step S1044, determining the text lines in the program code other than the comment lines as the identified code lines.

[0245] Here, the code lines are also code recognition results obtained by performing annotation recognition on the program code using the recognition method provided in the embodiment of the present application, and the code recognition results are code lines included in the program code.

[0246] Get the text lines except WL-C in the program code, and get the code recognition result WL-P as follows:

[0247] WL-P={

[0248] <"int add(int a,int b)", 2>,

[0249] <"{int move=a+b;", 3>,

[0250] <"return move;}",4>

[0251] }.

[0252] The comment recognition method provided in the embodiment of the present application can recognize comments and codes in program codes under the premise that the specific programming language cannot be predicted. It is universal and can improve the accuracy of comment recognition for unpredictable specific programming languages.

[0253] Figure 3 Another implementation flow diagram of the annotation recognition method provided in the embodiment of the present application is as follows: Figure 3 As shown, the annotation recognition method described in the embodiment of the present application includes the following steps:

[0254] Step S301, obtaining the program code to be identified and a preset line end mark.

[0255] Here, the program code includes code and comments. The preset line end mark can be a line break character "\n".

[0256] Step S302: segment the program code according to the line end identifier to obtain a plurality of segmented lines.

[0257] Step S303, deleting blank lines from the multiple segmented lines to obtain at least one text line.

[0258] The blank line is a segmented line containing only blank characters.

[0259] Step S304, determining the line start character of the text line according to the first character of the text line.

[0260] In some embodiments, step S304 can be implemented as follows: starting from the first text line, extract the first non-blank character in each text line; when it is determined that the first non-blank character of the current text line is not an English character, determine the first non-blank character of the current text line as the line start character of the current text line; when it is determined that the first non-blank character of the current text line is an English character, determine the blank character as the line start character of the current text line.

[0261] Step S305, determining the line terminator of the text line according to the last character of the text line.

[0262] In some embodiments, step S305 can be implemented as follows: starting from the last text line, extract the last non-blank character in each text line in reverse order; when it is determined that the last non-blank character of the current text line is not an English character and is not a Chinese character, determine the last non-blank character of the current text line as the line terminator of the current text line; when it is determined that the last non-blank character of the current text line is an English character or a Chinese character, and there is a line start character in the current text line, determine the blank character as the line terminator of the current text line; when it is determined that the last non-blank character of the current text line is an English character or a Chinese character, and there is no line start character in the current text line, determine the line terminator of the next text line after the current text line as the line terminator of the current text line.

[0263] Step S306, performing word segmentation processing on the characters included in the current text line according to the preset segmentation rule to obtain each word segment of the current text line.

[0264] Step S307, obtaining the part of speech of each word segment.

[0265] Step S308: Determine the number of target word segments included in the text line based on the characters included in the text line.

[0266] The part of speech of the target word is not a noun.

[0267] Step S309, determining the annotation start marker based on the line start symbol of each text line and the number of target segmented words.

[0268] In some embodiments, step S309 can be implemented as follows: based on the target number of word segments of each text line and the line start symbol of each text line, determine the total support number of each line start symbol that is not a blank character, the total support number of the line start symbol is the sum of the target number of word segments included in each text line corresponding to the line start symbol; determine the total number of target text lines corresponding to each line start symbol, the target text line is a text line that only includes noun participles; calculate the difference between the total support number of each line start symbol that is not a blank character and the corresponding total number of lines, and obtain the start support number of each line start symbol that is not a blank character; determine the line start symbol corresponding to the maximum start support number as the comment start marker.

[0269] Step S310, determining the comment end marker based on the line terminators of each text line and the number of target segmented words.

[0270] In some embodiments, step S310 can be implemented as follows: based on the target number of word segments in each text line and the line terminators of each text line, determine the total support number of each line terminator that is not a blank character, the total support number of the line terminator being the sum of the target number of word segments included in each text line corresponding to the line terminator; determine the total number of target text lines corresponding to each line terminator, the target text line being a text line that only includes noun segment segments; calculate the difference between the total support number of each line terminator that is not a blank character and the corresponding total number of lines, and obtain the end support number of each line terminator that is not a blank character; and determine the line terminator corresponding to the maximum end support number as the comment end marker.

[0271] Step S311: determine the annotation start marker and the annotation end marker as annotation markers.

[0272] Step S312, adding the text line whose line start character is the comment start mark to the first text line set.

[0273] Step S313, adding the text line whose line terminator is the comment end mark to the second text line set.

[0274] Step S314: determine the union of the first text line set and the second text line set as the recognized comment line.

[0275] Here, the comment line is the comment recognition result obtained by performing comment recognition on the program code using the recognition method provided in the embodiment of the present application, and the comment recognition result is the comment included in the program code.

[0276] Step S315, determining the text lines in the program code other than the comment lines as the recognized code lines.

[0277] Here, the code lines are also code recognition results obtained by performing annotation recognition on the program code using the recognition method provided in the embodiment of the present application, and the code recognition results are code lines included in the program code.

[0278] In some embodiments, when only the comments in the program need to be obtained, the process can end at step S314; when the code in the program needs to be obtained, step S315 is executed.

[0279] The comment recognition method provided in the embodiment of the present application can recognize comments in program code without knowing the specific programming language in advance. It is independent of the specific programming language, has universality, and can improve the accuracy of comment recognition for unpredictable specific programming languages.

[0280] The following is an explanation of an exemplary application of the embodiments of the present application in a practical application scenario.

[0281] Software code usually consists of two parts: program code and program comments. Program code is a string that conforms to the special syntax specifications of the programming language. It can be converted by tools such as compilation and interpretation and executed on the computer. It expresses the process of how the business logic of the software is implemented. Program comments are strings that conform to the grammar of human natural language. They generally exist in the header of the code file, the header of the function, and inside the program block. They are used to explain the ideas and reasons for the implementation of business logic, but they do not work during the execution of the program. However, the extraction of program comments is of great value for analyzing the quality of the software development process, identifying the inconsistency between program comments and program implementation, and analyzing the relationship between the same topic in program comments and multiple program codes. There are many studies in academic research and engineering management. Existing program comment recognition technologies mainly include the following two solutions.

[0282] Programming language-related program comment recognition solution: Under the premise of knowing the programming language used by the software code to be processed, program comments are recognized according to the grammatical specifications of the programming language. The advantage of this solution is that the accuracy rate can reach 100%; the disadvantage is that different solutions need to be designed for different programming languages, and it does not have the processing capability for newly emerging programming languages. Therefore, it is insufficient to manage software projects that are developed in a large number of different programming languages ​​and may be dynamically upgraded and changed.

[0283] Recognition scheme based on program comment character features: In order to design a program comment recognition technology with general capabilities, especially to distinguish program code and program comments in the content of email communications between developers, and to support the recognition of program comments without programming development software, many people have proposed to design a variety of regular expressions based on the symbolic features of program comments to recognize single-line comments, the beginning of multi-line comments, and the end of multi-line comments. Its main technical disadvantages are: it can only process programming languages ​​with similar comment syntax (such as Java and C comments are similar); the technical versatility is also limited.

[0284] In the related art, the shortcomings of the existing technical solutions are mainly summarized as follows:

[0285] 1) Programming language-related program comment recognition schemes implement the recognition of program comments based on the grammatical features of a single programming language and can only process program comments corresponding to a single programming language.

[0286] 2) A recognition scheme based on the character features of program comments. A regular expression is designed according to the character features of program comments. However, it can only process program comments of a few programming languages ​​with similar program comment syntax, and may misjudge comments that are not written in a standardized manner.

[0287] In view of the shortcomings of the existing technical solutions, the embodiment of the present application proposes a technical solution for program comment recognition that does not rely on a specific programming language. Without the need to know the programming language in advance, program comments in software codes are recognized to support the extraction of program comments. The main problems to be solved are as follows:

[0288] 1) To address the problem of different comment syntaxes in different programming languages, natural language understanding technology is used to automatically determine the start and end symbols of program comments.

[0289] 2) Based on the start symbol and end symbol of program comments, the problem of automatically extracting single-line program comments and multi-line program comments is solved.

[0290] A general method for identifying program comments proposed in an embodiment of the present application has the following core idea: dividing a program code file into numbered text lines; performing natural language analysis on each text line and identifying the text lines containing natural language sentences; determining the start and end symbols of program comments based on the text lines containing natural language; and identifying whether all text lines are program comments.

[0291] The following explains the relevant terms in the embodiments of the present application:

[0292] Displayable characters: Characters that can be displayed as symbols in the ASCII table, that is, from character number 32 (space) to character number 126 ('~').

[0293] Text line: A line of string consisting of displayable characters between two line breaks in the program code.

[0294] English letters: a..z and A..Z.

[0295] Blank line: A line of text that contains no displayable characters except blank characters.

[0296] Start-of-line symbol (corresponding to the start-of-line symbol mentioned above): the first non-blank character of a text line. The start-of-line symbol of a text line w is denoted as sc(w).

[0297] End of line symbol (corresponding to the end of line symbol mentioned above): the last non-blank character of a text line. The end of line symbol of text line w is denoted as ec(w).

[0298] Line comment start symbol (corresponding to the comment start mark above): the start symbol of the comment mark, used to mark the text line as a comment. The line comment start symbol of text line w is denoted as cs(w).

[0299] Line comment end symbol (corresponding to the comment end mark above): the end symbol of the comment mark, used to mark the text line as a comment. The line comment end symbol of text line w is denoted as ce(w).

[0300] Figure 4 A schematic diagram of another implementation flow of the annotation recognition method provided in the embodiment of the present application is as follows: Figure 4 As shown, the annotation recognition method provided in the embodiment of the present application includes the following steps.

[0301] Step S401, dividing text lines of program code.

[0302] Program code files are all text files. The end of a single line of text is determined by the ASCII character '\n', and the line number of each text line is tracked starting from number 1. Output all the text line data contained in the code file to form an ordered list WL=(<wl-1,ln(wl-1)> , …,<wl-N,ln(wl-N)> ), where N is the number of lines in the file, an element of the list WL<wl-i,ln(wl-i)> The text of the "wl-i"th line is stored in the variable "wl-i" and the line number is stored in ln(wl-i). Delete blank lines (a line that does not contain any characters after the delete symbol is a blank line).

[0303] Step S402, natural language text line screening.

[0304] In the embodiment of the present application, step S402 can be implemented by the following steps:

[0305] Step S4021, for each element of the list WL<wl-i,ln(wl-i)> The line "wl-i" is segmented into Chinese and English words, and the result is POS(wl-i) = {<w1,pos(w1)> , …,<wk,pos(wk)>}, where wi is a (Chinese / English) word and pos(wi) is the corresponding part of speech (noun, verb, adjective, adverb, pronoun, etc.).

[0306] Step S4022, extract the start symbol of the text line.

[0307] Starting from i=1, for each line of text<wl-i,ln(wl-i)> , the line comment start symbol of wl-i is recorded as cs(wl-i); calculate cs(wl-i) according to the following steps 1) and 2).

[0308] 1) cs(wl-i) = NULL, extract the first ASCII displayable character in the line "wl-i". If this character is a non-whitespace symbol (i.e., non-space, non-tab\t) and non-English letter, use it as the first character of the line cs(wl-i).

[0309] 2) Initialize the support of the line comment start symbol of cs(wl-i) (corresponding to the total support number in the above text) to support(cs(wl-i)) which is 0.

[0310] Step S4023, extract the end symbol of the text line.

[0311] In reverse order (i.e. i from large to small), examine wl-i in list WL. For each text line<wl-i,ln(wl-i)> , initialize ce(wl-i) = NULL; calculate ce(wl-i) according to the following steps 1), 2) and 3).

[0312] 1) Extract the non-blank symbol (i.e., non-space, non-\t) and non-English letter at the end of the variable "wl-i" as the line ending symbol ce(wl-i) of the line.

[0313] 2) If the end symbol ce(wl-i) = NULL and the start symbol cs(wl-i) ≠ NULL, then keep ce(wl-i) = NULL and go to 3); otherwise t = i+1, if ce(wl-t) ≠ NULL, then ce(wl-i) = ce(wl-t).

[0314] 3) Initialize the support of the line comment end symbol of ce(wl-i) to support(ce(wl-i))=0.

[0315] Step S4024, loop to examine POS(wl-i) corresponding to WL = {<w1,pos(w1)> , …,<wk,pos(wk)>}, if the part-of-speech value of pos(wj) in POS(wl-i) is not "noun" or "symbol", then update the support:

[0316] support(cs(wl-i))=support(cs(wl-i))+1;

[0317] support(ce(wl-i))=support(ce(wl-i))+1.

[0318] Step S4025, loop to examine POS(wl-i) corresponding to WL = {<w1,pos(w1)> , …,<wk,pos(wk)>}, if the part-of-speech values ​​of all pos(wj) in POS(wl-i) are "noun" or "symbol", then update the support:

[0319] support(cs(wl-i))=support(cs(wl-i))–1;

[0320] support(ce(wl-i))=support(ce(wl-i))–1.

[0321] Step S403: the program annotation symbol (corresponding to the annotation mark mentioned above) is determined.

[0322] In the embodiment of the present application, step S403 can be implemented by the following steps:

[0323] Step S4031, initialization: program comment start symbol set CS = {}; program comment end symbol set CE = {}.

[0324] Step S4032: If the row start symbol x has the maximum positive support support(x) among all row start symbols, then x is added to CS.

[0325] Step S4033: If the row end symbol y has the maximum positive support support(y), then add y to CE.

[0326] Step S404: program comment recognition.

[0327] In the embodiment of the present application, step S404 can be implemented by the following steps:

[0328] Step S4041, initialize the comment line set WL-C to an empty set: WL-C = {}.

[0329] Step S4042, scan each line wl in the input code file from front to back, if cs(wl) determined in step S402 belongs to CS or ce(wl) belongs to CE, then add the text of wl to WL-C.

[0330] Step S4043, output WL-C as all comment lines in the code.

[0331] Combine the following Figure 4 The embodiments of the present application are further described in detail with reference to the following specific examples.

[0332] Before use, you need to have a completed domain knowledge graph KG and a domain action model set AG, text segmentation software and text part-of-speech tagging software with verified accuracy, and a synonym dictionary.

[0333] In order to better understand the present invention, the following is a specific embodiment, in which the natural language understanding word segmentation and part-of-speech tagging tool adopts Stanford NLP.

[0334] The software code of the example is as follows, with line numbers on the left and source code on the right:

[0335]

[0336]

[0337] In step S401, the text lines of the program code are segmented to obtain:

[0338] WL={

[0339] <" / / this is a function",1>,

[0340] <"int add(int a,int b)", 2>,

[0341] <"{int move=a+b;", 3>,

[0342] <"return move;}",4>,

[0343] <" / *this is a single line comment* / ", 5>,

[0344] <“ / *”, 6>,

[0345] <"this",7>,

[0346] <"is",8>,

[0347] <"a",9>,

[0348] <"multiline",10>,

[0349] <"comments", 11>,

[0350] <“* / ”,12>

[0351] }.

[0352] For ease of understanding, WL is presented in a table, and the table WL is shown in Table 6:

[0353] Table 6 Storage list of text lines WL

[0354]

[0355]

[0356] In step S402, natural language text lines are screened.

[0357] The part of speech of each word in each text line is obtained through step S4021, as shown in the POS column of Table 7 below (the part of speech tagging results are based on the open source natural language processing tool implemented by Stanford University https: / / github.com / stanfordnlp / stanza / ).

[0358] Table 7 Each word in each text line and the part of speech of each word

[0359]

[0360] After step S4022, the row start symbol of each row is obtained, and the results are the column "cs" and the column "support(cs)" shown in Table 8 below.

[0361] Table 8 Line start symbol support (cs) for each text line

[0362]

[0363]

[0364] After step S4023, the end symbol of each row is obtained, as shown in Table 9 below, with new columns ce and support(ce).

[0365] Table 9 The line start symbol support (cs) and line end symbol support (ce) of each text line

[0366]

[0367]

[0368] After step S4024, the support value is updated, and the update result is shown in Table 10.

[0369] Table 10 Support of each row start symbol and each row end symbol in each row

[0370]

[0371]

[0372] Get the support of the symbols that start each line:

[0373] The support of ' / ' is support(' / ')=3+3+0=6;

[0374] The support of '{' support('{') = 0;

[0375] The support of '*' support('*')=0.

[0376] Get the support of each line ending symbol:

[0377] The support of ')' support(')') = 1;

[0378] The support of ';' support(';')=0;

[0379] '}' support(';')=0;

[0380] The support of ' / ' support(' / ') = 3+1+1+1+0+0+0 = 6;

[0381] The support degree of '*' is support('*')=0.

[0382] After step S4025, the support of the line start symbol and the line end symbol is updated using the support reduction rule.

[0383] Reduce the support of candidate line start symbols:

[0384] There is no change in the support of ' / ' as the start-of-line symbol;

[0385] According to line 3, this line reduces the support of the symbol '}':

[0386] support('}')=0-1=-1;

[0387] The support of '*' support('*') = 0, no change.

[0388] Reduce the support of candidate line ending symbols:

[0389] According to rows 10 and 11, the support of ' / ' as a candidate line ending symbol is reduced to support(' / ')=6-1-1=4;

[0390] The support of the candidate end character ')' is support(')') = 1, no change;

[0391] According to row 3, reduce the support of the candidate end character ';' support(';') = 0-1 = -1;

[0392] According to row 4, the support of '}' is reduced to support('}')=0-1=-1.

[0393] According to step S4032, ' / ' is the symbol with the maximum support among all candidate row start symbols, and thus the row start symbol of the entire code is obtained as CS={' / '}.

[0394] After step S4033, CE = {' / '} is obtained.

[0395] After step S4042, all comment lines of the code are obtained, such as WL-C:

[0396] WL-C={

[0397] <" / / this is a function",1>,

[0398] <" / *this is a single line comment* / ", 5>,

[0399] <“ / *”, 6>,

[0400] <"this",7>,

[0401] <"is",8>,

[0402] <"a",9>,

[0403] <"multiline",10>,

[0404] <"comments", 11>,

[0405] <“* / ”,12>

[0406] }.

[0407] The comment recognition method provided in the embodiment of the present application can realize the recognition of program comments without knowing the programming language in advance. A method for evaluating the possibility that the start symbol of a line of text in the software code is the start symbol of the program comment based on the number of natural language parts of speech of each word in the line of text in the software code. A method for evaluating the possibility that the end symbol of a line of text is the end symbol of the program comment based on the number of natural language parts of speech of each word in the line of text in the software code. A strategy for reducing the possibility that the start symbol and end symbol of a line of text can become the start symbol and end symbol of the comment line based on the fact that a line of text contains all words that are symbols or nouns. A method for determining the start symbol and end symbol of a program comment through natural language analysis technology.

[0408] Compared with the existing technical solutions, this method has the following advantages: the existing recognition scheme based on program annotation character features recognizes program annotations according to the pattern features of characters. In contrast, the method proposed in this application recognizes program annotations according to the grammatical features of words, and can better utilize the grammatical features of human language in program annotations, thereby improving the recognition accuracy.

[0409] Based on the foregoing embodiments, the embodiments of the present application provide an annotation recognition device, and the modules included in the device, as well as the units included in the modules, can be implemented by a processor in a computer device; of course, they can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU, Central Processing Unit), a microprocessor (MPU, Microprocessor Unit), a digital signal processor (DSP, Digital Signal Processing) or a field programmable gate array (FPGA, Field Programmable Gate Array), etc.

[0410] The present application embodiment further provides an annotation recognition device, Figure 5 A schematic diagram of the structure of the annotation recognition device provided in the embodiment of the present application is shown in FIG. Figure 5 As shown, the annotation recognition device 500 includes:

[0411] The segmentation module 501 is used to segment the acquired program code to be identified to obtain at least one text line, wherein the program code includes code and comments;

[0412] A first determination module 502, configured to determine a start character of the text line according to a first character of the text line, and determine a terminator of the text line according to a last character of the text line;

[0413] A second determination module 503, configured to determine a comment mark in the program code based on the line start character and the line end character;

[0414] The recognition module 504 is used to perform annotation recognition on the program code based on the annotation identifier to obtain a recognition result.

[0415] In some embodiments, the segmentation module 501 may further include:

[0416] A first acquisition submodule, used to acquire the program code to be identified and a preset line end mark;

[0417] A segmentation submodule, used for segmenting the program code according to the line end mark to obtain a plurality of segmented lines;

[0418] The deletion submodule is used to delete blank lines from the multiple segmentation lines to obtain at least one text line, wherein the blank line is a segmentation line containing only blank characters.

[0419] In some embodiments, the first determining module 502 may further include:

[0420] A first extraction submodule, used to extract the first non-blank character in each text line;

[0421] A first determination submodule is used to determine the first non-blank character of the current text line as the line start character of the current text line when it is determined that the first non-blank character of the current text line is not an English character;

[0422] The second determination submodule is used to determine the blank character as the line start character of the current text line when it is determined that the first non-blank character of the current text line is an English character.

[0423] In some embodiments, the first determining module 502 may further include:

[0424] The second extraction submodule is used to extract the last non-blank character in each text line;

[0425] A third determination submodule is used to determine the last non-blank character of the current text line as the line terminator of the current text line when it is determined that the last non-blank character of the current text line is neither an English character nor a Chinese character;

[0426] A fourth determination submodule is used to determine a blank character as a line terminator of the current text line when it is determined that the last non-blank character of the current text line is an English character or a Chinese character and there is a line start character in the current text line;

[0427] The fifth determination submodule is used to determine the line terminator of the next text line of the current text line as the line terminator of the current text line when it is determined that the last non-blank character of the current text line is an English character or a Chinese character and there is no line start character in the current text line.

[0428] In some embodiments, the second determining module 503 may further include:

[0429] A sixth determination submodule, configured to determine the number of target segmented words included in the text line based on the characters included in the text line, wherein the part of speech of the target segmented words is not a noun;

[0430] A seventh determination submodule, for determining a comment start marker based on the line start symbol of each text line and the number of target segmented words, and determining a comment end marker based on the line end symbol of each text line and the number of target segmented words;

[0431] An eighth determining submodule is used to determine the annotation start marker and the annotation end marker as annotation markers.

[0432] In some embodiments, the second determining module 503 may further include:

[0433] The word segmentation submodule is used to perform word segmentation processing on the characters included in the current text line according to the preset segmentation rules to obtain each word segmentation of the current text line;

[0434] The second acquisition submodule is used to acquire the part of speech of each word segment.

[0435] In some embodiments, the seventh determining submodule may further include:

[0436] A first determining unit is used to determine the total support number of each line start symbol that is not a blank character based on the target number of word segments of each text line and the line start symbol of each text line, wherein the total support number of the line start symbol is the sum of the target number of word segments included in each text line corresponding to the line start symbol;

[0437] A second determining unit is used to determine the total number of target text lines corresponding to each line start symbol, wherein the target text lines only include text lines of noun participles;

[0438] A first calculation unit is used to calculate the difference between the total support number of each line start character that is not a blank character and the corresponding total number of lines, so as to obtain the start support number of each line start character that is not a blank character;

[0439] The third determining unit is used to determine the line start symbol corresponding to the maximum start support number as the comment start marker.

[0440] In some embodiments, the seventh determining submodule may further include:

[0441] A fourth determining unit is used to determine the total support number of each line terminator that is not a blank character based on the target number of segmented words in each text line and the line terminator of each text line, wherein the total support number of the line terminator is the sum of the target number of segmented words included in each text line corresponding to the line terminator;

[0442] A fifth determining unit, configured to determine the total number of target text lines corresponding to each line ending symbol, wherein the target text lines only include text lines of noun participles;

[0443] A second calculation unit is used to calculate the difference between the total support number of each line terminator that is not a blank character and the corresponding total number of lines to obtain the end support number of each line terminator that is not a blank character;

[0444] The sixth determining unit is used to determine the line terminator corresponding to the maximum end support number as the comment end marker.

[0445] In some embodiments, the identification module 504 may further include:

[0446] A first adding submodule, used for adding a text line whose line start character is the comment start mark to the first text line set;

[0447] A second adding submodule, used for adding a text line whose line terminator is the comment end mark to a second text line set;

[0448] A ninth determination submodule is used to determine a union of the first text line set and the second text line set as the recognized comment line.

[0449] In some embodiments, the identification module 504 may further include:

[0450] The tenth determining submodule is used to determine the text lines in the program code other than the comment lines as the identified code lines.

[0451] It should be noted that the description of the above annotation recognition device embodiment is similar to the above method description and has the same beneficial effects as the method embodiment. For technical details not disclosed in the annotation recognition device embodiment of this application, those skilled in the art should refer to the description of the method embodiment of this application for understanding.

[0452] It should be noted that in the embodiment of the present application, if the above-mentioned annotation recognition method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM, ReadOnly Memory), a disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.

[0453] Accordingly, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the annotation recognition method provided in the above embodiment are implemented.

[0454] The present application embodiment provides an annotation recognition device, Figure 6 A schematic diagram of the composition structure of the annotation recognition device provided in the embodiment of the present application, according to Figure 6The exemplary structure of the annotation recognition device 600 shown can foresee other exemplary structures of the annotation recognition device 600, so the structure described here should not be regarded as limiting. For example, some components described below can be omitted, or components not described below can be added to meet the special needs of certain applications.

[0455] Figure 6 The annotation recognition device 600 shown includes: a processor 601, at least one communication bus 602, a user interface 603, at least one external communication interface 604 and a memory 605. The communication bus 602 is configured to realize the connection and communication between these components. The user interface 603 may include a display screen, and the external communication interface 604 may include a standard wired interface and a wireless interface. The processor 601 is configured to execute the program of the annotation recognition method stored in the memory to implement the steps in the annotation recognition method provided in the above embodiment.

[0456] The description of the above annotation recognition device and storage medium embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the annotation recognition device and storage medium embodiments of this application, please refer to the description of the method embodiments of this application for understanding.

[0457] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned sequence numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.

[0458] It should be noted that, in this article, the terms "include", "comprises" or any other variations 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, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0459] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0460] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0461] In addition, all functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may be a separate unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0462] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks or optical disks.

[0463] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can essentially or in other words, the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for an AC to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks or optical disks.

[0464] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for annotation recognition, characterized in that: The method comprises: Segmenting the acquired program code to be identified to obtain at least one text line, wherein the program code includes code and comments; Determine the start character of the text line according to the first character of the text line, and determine the end character of the text line according to the last character of the text line; Determining a comment mark in the program code based on the line start character and the line end character; Perform annotation recognition on the program code based on the annotation identifier to obtain a recognition result; The step of determining the start character of the text line according to the first character of the text line includes: Extract the first non-blank character in each line of text; When it is determined that the first non-blank character of the current text line is not an English character, the first non-blank character of the current text line is determined as the line start character of the current text line; When it is determined that the first non-blank character of the current text line is an English character, the blank character is determined as the line start character of the current text line; The step of determining the line terminator of the text line according to the line end character of the text line comprises: Extract the last non-blank character in each line of text; When it is determined that the last non-blank character of the current text line is neither an English character nor a Chinese character, the last non-blank character of the current text line is determined as the line terminator of the current text line; When it is determined that the last non-blank character of the current text line is an English character or a Chinese character, and there is a line start character in the current text line, a blank character is determined as the line end character of the current text line; When it is determined that the last non-blank character of the current text line is an English character or a Chinese character, and there is no line start character in the current text line, the line end character of the next text line of the current text line is determined as the line end character of the current text line; The step of determining the comment mark in the program code based on the line start character and the line end character includes: Based on the characters included in the text line, determining the number of target segmented words included in the text line, wherein the part of speech of the target segmented words is not a noun; Determine the comment start mark based on the line start mark of each text line and the number of target segmented words, and determine the comment end mark based on the line end mark of each text line and the number of target segmented words; Determine the annotation start mark and the annotation end mark as annotation marks; The step of determining the annotation start mark based on the line start symbol of each text line and the number of target segmented words includes: Based on the target number of segmented words in each text line and the line start symbol of each text line, determine the total support number of each line start symbol that is not a blank character, the total support number of the line start symbol being the sum of the target number of segmented words included in each text line corresponding to the line start symbol; Determine the total number of target text lines corresponding to each line start symbol, wherein the target text lines only include text lines of noun participles; Calculate the difference between the total support number of each line start character that is not a blank character and the corresponding total number of lines to obtain the start support number of each line start character that is not a blank character; The line start character corresponding to the maximum start support number is determined as the comment start mark; The step of determining the end mark of the annotation based on the line terminator of each text line and the number of target segmented words includes: Based on the target number of segmented words in each text line and the line terminator of each text line, determine the total support number of each line terminator that is not a blank character, the total support number of the line terminator being the sum of the target number of segmented words included in each text line corresponding to the line terminator; Determine the total number of target text lines corresponding to each line ending character, wherein the target text lines only include text lines of noun participles; Calculate the difference between the total support number of each line terminator that is not a blank character and the corresponding total number of lines to obtain the end support number of each line terminator that is not a blank character; The line terminator corresponding to the maximum end support number is determined as the comment end marker.

2. The method according to claim 1, characterized in that The obtained program code to be identified is segmented to obtain at least one text line, including: Obtaining the program code to be identified and a preset line ending mark; Segment the program code according to the line end identifier to obtain a plurality of segmented lines; Blank lines are deleted from the multiple segmented lines to obtain at least one text line.

3. The method according to claim 1, characterized in that Before determining the number of target segmented words included in the text line based on the characters included in the text line, the method further includes: Perform word segmentation on the characters included in the current text line according to the preset segmentation rules to obtain each word segment of the current text line; The part of speech of each word segment is obtained.

4. The method according to claim 1, characterized in that The step of performing annotation recognition on the program code based on the annotation identifier to obtain a recognition result includes: Adding a text line whose line start character is the comment start mark to the first text line set; Adding a text line whose line terminator is the comment end mark to the second text line set; A union of the first text line set and the second text line set is determined as the recognized comment line.

5. The method according to claim 4, characterized in that After determining the union of the first text line set and the second text line set as the recognized comment line, the method further includes: The text lines in the program code other than the comment lines are determined as the identified code lines.

6. An annotation recognition device, characterized in that: The device comprises: A segmentation module, used for segmenting the acquired program code to be identified to obtain at least one text line, wherein the program code includes code and comments; A first determination module, used to determine the start character of the text line according to the first character of the text line, and to determine the end character of the text line according to the last character of the text line; A second determination module, configured to determine a comment mark in the program code based on the line start character and the line end character; An identification module, used for performing annotation identification on the program code based on the annotation identifier to obtain an identification result; The first determining module may further include: A first extraction submodule, used to extract the first non-blank character in each text line; A first determination submodule is used to determine the first non-blank character of the current text line as the line start character of the current text line when it is determined that the first non-blank character of the current text line is not an English character; The second determination submodule is used to determine the blank character as the line start character of the current text line when it is determined that the first non-blank character of the current text line is an English character; The first determining module may further include: The second extraction submodule is used to extract the last non-blank character in each text line; A third determination submodule is used to determine the last non-blank character of the current text line as the line terminator of the current text line when it is determined that the last non-blank character of the current text line is neither an English character nor a Chinese character; A fourth determination submodule is used to determine a blank character as a line terminator of the current text line when it is determined that the last non-blank character of the current text line is an English character or a Chinese character and there is a line start character in the current text line; A fifth determination submodule is used to determine the line ending character of the next text line of the current text line as the line ending character of the current text line when it is determined that the last non-blank character of the current text line is an English character or a Chinese character and there is no line beginning character in the current text line; The second determining module may further include: A sixth determination submodule, configured to determine the number of target segmented words included in the text line based on the characters included in the text line, wherein the part of speech of the target segmented words is not a noun; A seventh determination submodule, for determining a comment start marker based on the line start symbol of each text line and the number of target segmented words, and determining a comment end marker based on the line end symbol of each text line and the number of target segmented words; An eighth determination submodule, used to determine the annotation start marker and the annotation end marker as annotation markers; The seventh determining submodule may further include: A first determining unit is used to determine the total support number of each line start symbol that is not a blank character based on the target number of word segments of each text line and the line start symbol of each text line, wherein the total support number of the line start symbol is the sum of the target number of word segments included in each text line corresponding to the line start symbol; A second determining unit is used to determine the total number of target text lines corresponding to each line start symbol, wherein the target text lines only include text lines of noun participles; A first calculation unit is used to calculate the difference between the total support number of each line start character that is not a blank character and the corresponding total number of lines, so as to obtain the start support number of each line start character that is not a blank character; A third determining unit is used to determine the line start symbol corresponding to the maximum start support number as a comment start marker; The seventh determining submodule may further include: A fourth determining unit is used to determine the total support number of each line terminator that is not a blank character based on the target number of segmented words in each text line and the line terminator of each text line, wherein the total support number of the line terminator is the sum of the target number of segmented words included in each text line corresponding to the line terminator; The fifth determination unit is used to determine the total number of target text lines corresponding to each line ending character, wherein the target text line only includes text lines of noun participles; the second calculation unit is used to calculate the difference between the total support number of each line ending character that is not a blank character and the corresponding total number of lines, and obtain the end support number of each line ending character that is not a blank character; The sixth determining unit is used to determine the line terminator corresponding to the maximum end support number as the comment end marker.

7. An annotation recognition device, characterized in that: The device comprises: Processor; and a memory for storing a computer program executable on the processor; Wherein, when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

8. A computer-readable storage medium, characterized in that: Computer executable instructions are stored, and the computer executable instructions are configured to execute the steps of the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Insurance product development script generation method and terminal device

    CN109189372A

  • Method and device for automatically identifying annotations in JSON codes

    CN110727703A