CN104123273B - A kind of annotation quality evaluation of object-oriented program and annotation suggesting method - Google Patents

A kind of annotation quality evaluation of object-oriented program and annotation suggesting method Download PDF

Info

Publication number
CN104123273B
CN104123273B CN201410355299.2A CN201410355299A CN104123273B CN 104123273 B CN104123273 B CN 104123273B CN 201410355299 A CN201410355299 A CN 201410355299A CN 104123273 B CN104123273 B CN 104123273B
Authority
CN
China
Prior art keywords
annotation
suggestion
annotated
file
threshold value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201410355299.2A
Other languages
Chinese (zh)
Other versions
CN104123273A (en
Inventor
孙小兵
耿强
李云
朱俊武
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Yangzhou University
Original Assignee
Yangzhou University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Yangzhou University filed Critical Yangzhou University
Priority to CN201410355299.2A priority Critical patent/CN104123273B/en
Publication of CN104123273A publication Critical patent/CN104123273A/en
Application granted granted Critical
Publication of CN104123273B publication Critical patent/CN104123273B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

Annotation quality evaluation and annotation suggesting method the invention discloses a kind of object-oriented program in field of software engineering, comprise the following steps:1)Traversal object code file, extracts the annotation and its class name, the annotation of method and its method name for being annotated for being annotated, step 21 of main classes in code file):Quality analysis is carried out to the comment section in main classes file and class name according to the analysis rule annotated on main classes, and annotation to being unsatisfactory for analysis rule provides corresponding suggestion;Step 22):Comment section in the analysis rule other side's method file annotated on method and method name carry out quality analysis, and annotation to being unsatisfactory for analysis rule provides corresponding suggestion;Step 3):Quantity according to above-mentioned suggestion provides overall quality evaluation, the present invention provides the suggestion annotated on head annotation and method according to the result for being calculated, the quality of code annotation is improved, in being conducive to the Maintenance Development for can be used for software to the perfect of software code quality.

Description

A kind of annotation quality evaluation of object-oriented program and annotation suggesting method
Technical field
The present invention relates to a kind of software evaluation method, more particularly to a kind of software annotation quality evaluation and suggesting method, category In field of software engineering.
Background technology
In a code file, not only only code, and also have and annotate.Now there are some researches show annotated generation Code is not than having annotated code to be easier to understand.And annotation is to be only second to code being conducive in itself the second of code understanding to have Use document.Additionally, source code file is important in software maintenance, for whole code file, check in source code text The renewal of annotation in part for developer to document and code is an eaily method.And developer recognizes For the quality of a code file has had a strong impact on maintenance and evolution of the developer to this software, so they think generation Code document quality is critically important.And a quality for code file not only includes the quality of code, but also including being noted in code The quality released, while the quality of annotation not only includes annotated quality, also can shadow to but need annotation without annotation Ring the quality of code file.Evaluation to annotation quality has it to act in software development process and maintenance process.In exploitation During, administrative staff can go to judge the code quality and intelligibility of each developer by annotation quality, and annotation quality is good Code be capable of the testability and maintainability of effective auxiliary code;In Software maintenance process, attendant can be by note Release quality to judge the modifiability of present procedure, the good code of annotation quality can effectively help attendant to change dimension Protect this program.So the present invention is analyzed come whole by two aspects for having annotated and to but needing annotation without annotation The quality for analyzing this code file annotation of body.
The analysis of existing annotation quality is all often that, to annotated analysis, have ignored to but needing note without annotation The analysis released, and for there is an annotation, is all the ratio for calculating annotation in this code file, or code annotation word Number etc., and the present invention is to use information retrieval, and the extraction with the code being annotated is annotated to code file, by pretreatment, Then the correlation between it is calculated.It is annotated for not having, the method name of each code file is extracted, and in the same of pretreatment When calculate and the lines of code of its method and call the number of times of other functions, judge whether to need annotation by analyzing 3 conditions. The present invention makes full use of information retrieval technique, and its correlation is calculated by retrieval coding and comment section, and whether it needs Annotate to provide the evaluation on annotation quality, and provide the suggestion of annotation.
The content of the invention
Annotation quality evaluation and annotation suggesting method it is an object of the invention to provide a kind of object-oriented program, according to institute The result of calculating provides the suggestion on head annotation and method annotation, improves the quality of code annotation, is conducive to software code Quality it is perfect.
The object of the present invention is achieved like this:A kind of annotation quality evaluation of object-oriented program and annotation suggestion side Method, comprises the following steps:
Step 1)Traversal object code file, extracts the annotation and its class name, method for being annotated of main classes in code file Annotation and its method name for being annotated, the annotation of main classes and its class name for being annotated are stored in main classes file, by method In annotation and its method name store method file for being annotated;
Step 2-1):Matter is carried out to the comment section in main classes file and class name according to the analysis rule annotated on main classes Amount analysis, and annotation to being unsatisfactory for analysis rule provides corresponding suggestion;
Step 2-2):Comment section in the analysis rule other side's method file annotated on method is carried out with method name Quality analysis, and annotation to being unsatisfactory for analysis rule provides corresponding suggestion;
Step 3):Quantity according to above-mentioned suggestion provides overall quality evaluation.
As further restriction of the invention, the step 2-1)Mass analysis method it is as follows:
A) comment section in traversal main classes file, retrieves the comment section with the presence or absence of " author ", if it does not, Then provide the suggestion of addition author;
B) comment section is checked with the presence or absence of the description to main classes, if it does not exist, then the suggestion of addition description is given, If there is the description to main classes, then its correlation is analyzed;
C) analysed for relevance, the correlation of annotation and main classes is calculated using formula L=N/M*100%, and wherein M is represented to class Name carries out the total words that are partitioned into after camel formula nomenclature, and N represents the number of word related to class name in annotation, and by L Compare with threshold value set in advance, if greater than threshold value, illustrate that correlation is higher, if being less than threshold value, illustrate correlation Property is relatively low, and provides the suggestion for adding more descriptions.
As further restriction of the invention, the step 2-2)Mass analysis method it is as follows:
a)Comment section and method name in traversal method file, count annotated method name and do not have annotated method Name, and annotated method name is calculated using formula X=Y/Z*100%, Y represents the number of annotated method, Z method for expressing text The sum of method in part, and X is compared with threshold value set in advance, if being less than threshold value, provide the more annotations of addition Suggestion;
b)Annotated method name carries out correlation analysis in other side's method file, according to camel formula nomenclature come the side of being partitioned into Word in religious name, word number scale Q, then the annotation in file, the list contained in annotation are traveled through to the word being partitioned into successively Word number scale P, using formula O=P/Q*100%, O is compared with threshold value set in advance, if less than set threshold value, Then provide the suggestion for adding more annotations, if above set threshold value, illustrate this section annotation description with the code file in Main classes correlation is higher;
c)Do not have annotated method name to be analyzed in other side's method file, using the word of wordnet tool analysis method names Property composition;
If the composition of the part of speech of party's religious name is not verb plus noun or if not being title plus verb, the party is illustrated Method needs addition annotation, provides the suggestion of addition annotation;
If verb adds noun or title plus verb then to analyze its lines of code, if its lines of code is more than institute Gating threshold value, then need to add understanding of some annotations to be conducive to code, provides the suggestion of addition annotation;
If lines of code is less than threshold value, its number of times for quoting other method is analyzed, if number of times is more than threshold value, Then need to add understanding of some annotations to be conducive to code, provide the suggestion of addition annotation, if word number is less than threshold value, Can not be annotated.
As further restriction of the invention, the step 3)Quality evaluating method it is as follows:By counting above-mentioned quality The given suggestion of analysis, then calculates suggestion rate, using formula , wherein,Suggestion rate is represented,Represent and main classes annotation is built The sum of view, 3 expressions in bracket analyze one and have three kinds to the annotation of main classes,Represent to annotated method Suggestion sum,Annotated method sum is represented,Expression does not have the suggestion of annotated method total Number,Expression does not have annotated method sum,The proportion accounted for main classes annotation suggestion is represented,The proportion accounted for the suggestion of annotated method is represented,Represent to not having annotated method suggestion to account for Proportion, suggestion rate is compared with threshold value set in advance, if greater than threshold value, illustrates the matter of code file annotation Amount is bad, it is necessary to improve carefully, it is proposed that developer is according to suggestion modification annotation, it is proposed that rate is less than 0.5, illustrates the code file Quality it is higher;If all methods have annotation, i.e.,, then
Compared with prior art, the beneficial effects of the present invention are the inventive method is a kind of commenting for code annotation quality Valency and suggestion, are annotated by the head to code file(That is the annotation of main classes)The analysis for carrying out quality is annotated with method, according to institute The analysis rule of regulation, provides the analysis on the annotation quality, if quality is relatively low, provides corresponding suggestion, additionally, this Invention annotates for needs but developer is to annotation, by dividing for not having annotated method to be also carried out analyzing Analysis, this section of code needs annotation, it is proposed that developer's addition annotation, and finally, developer can be according to suggestion modification oneself Annotation, so as to improve the quality of code annotation, is conducive to improving the quality of software.The present invention can be used for the Maintenance Development of software In.
Brief description of the drawings
Fig. 1 is operational flowchart of the invention.
Fig. 2 is that the present invention annotates analysis process figure to the head of Data.java files.
Fig. 3 is the head annotation result of extraction Data.java files in the present invention.
Fig. 4 is analysis result of the present invention to the head annotation of Data.java files.
Fig. 5 is that the present invention annotates analysis process figure to the method for Data.java files.
Specific embodiment
The present invention is described further with reference to specific embodiment.
Here from Data.java as code file.
A kind of annotation quality evaluation of object-oriented program as shown in Figure 1 and annotation suggesting method, comprise the following steps:
1)As shown in Fig. 2 traversal Data.java files, extract the Header Comments in code file(That is main classes Annotation)The class name annotated with it, annotates as shown in figure 3, being then stored in the form of Fig. 3 In ProcessForHeaderComments files, this file is processed.
1-1)Whether there is@author in retrieval ProcessForHeaderComments(Whether there is author), generation Do not exist@author in code section Data.java, so providing suggestion as shown in Figure 4:
@ Suggestion: You should add author to this document。
1-2)Either with or without other retouching on class in addition to@author in retrieval ProcessForHeaderComments State, by retrieving with the presence or absence of the annotation not started with@in Header Comments because exist in Data.java its on The description of class, so herein without providing suggestion, after detection is present, by the treatment to code section, extracting Header Comments related class name Data, 1 word is partitioned into using camel formula nomenclature by class name, then travels through file Header Comments, in obtaining word that class name is partitioned into the presence of 1 word Header Comments, using formula L= 1/1*100%=100%, more than threshold value 50%, so the annotation is high with the correlation of code, it is not necessary to provide suggestion;
@Suggestion:You should add more Description about this class to this document。
2)As shown in figure 3, traversal Data.java files, extract the Member Comments in code file(That is method Annotation)The method name annotated with it, extracting annotation and while method name, count annotated method number with it is total Method number, while when single method is extracted, counting the lines of code of its method body, calls the number of times of other method, one And be stored in ProcessForMemberComments files, then this file is processed.
2-1)Annotated side operator 14 in Data.java files is counted, total side operator 14, annotation rate is 100%, noted Rate is released more than threshold value(50%), it is not necessary to advise, and carry out correlation analysis;
2-2)For annotated method, the method name of code section in ProcessForMemberComments is extracted Afterwards, first according to camel nomenclature come processing method name, O=P/Q*100% is then calculated, in Data.java files, 14 have note The O values of the method released are respectively 1,1,1,0.5,0,0,0,0,0,0,0,1,1,0 and then compare with threshold value 0.5, and O values are less than 0.5, therefore provide suggestion:
@Suggestion: You should add some comments about function。
2-3)For not having annotated method, first extracting method name is carried out processing method name and is extracted further according to camel nomenclature Keyword, recalls wordnet tool detections its part of speech composition, sees whether its part of speech composition is to meet verb+noun or name Word+verb(If method name names the composition that is directly designated as lack of standardization not meet), for incongruent, suggestion is provided, for symbol The further analysis closed:
@Suggestion:You should add some comments about this function.
2-4)Extraction meets the method body lines of code that part of speech constitutes conditions method, and and threshold value(50)Compare, if More than 50, then suggestion is provided, if less than further analyzing:
@Suggestion:You should add some comments about this function.
2-5)Extract the number of times that calls other method body of the threshold value less than 50 methods, and and threshold value(3)Compare, if More than 3, then suggestion is provided, need not be annotated really if less than then explanation the method:
@Suggestion:You should add some comments about this function.
3)By counting above-mentioned two to the suggestion given by the analysis of different annotations, suggestion rate is then calculated, due to All methods have annotation herein, therefore select formula, it is less than 0.5, illustrate that the annotation quality of Data.java code files is pretty good, but it is also possible to the annotation of oneself is changed according to suggestion and enters one Step improves annotation quality.
The invention is not limited in above-described embodiment, on the basis of technical scheme disclosed by the invention, the skill of this area Art personnel are according to disclosed technology contents, it is not necessary to which performing creative labour just can make one to some of which technical characteristic A little to replace and deform, these are replaced and deform within the scope of the present invention.

Claims (3)

1. a kind of object-oriented program annotation quality evaluation and annotation suggesting method, it is characterised in that comprise the following steps:
Step 1) traversal object code file, extracts the annotation and its class name, note of method for being annotated of main classes in code file The method name annotated with it is released, the annotation of main classes and its class name for being annotated is stored in main classes file, by the annotation of method In the method name store method file annotated with it;
Step 2-1):Quality point is carried out to the comment section in main classes file and class name according to the analysis rule annotated on main classes Analysis, and annotation to being unsatisfactory for analysis rule provides corresponding suggestion, the step 2-1) mass analysis method it is as follows:
A) comment section in traversal main classes file, retrieves the comment section with the presence or absence of " author ", if it does not exist, then providing Add the suggestion of author;
B) comment section is checked with the presence or absence of the description to main classes, if it does not exist, then the suggestion of addition description is given, if In the presence of the description to main classes, then its correlation is analyzed;
C) analysed for relevance, the correlation of annotation and main classes is calculated using formula L=N/M*100%, and wherein M is represented to class name Carry out the total words being partitioned into after camel formula nomenclature, N represents the number of word related to class name in annotation, and by L and Threshold value set in advance compares, and if greater than threshold value, illustrates that correlation is higher, if being less than threshold value, illustrates correlation It is relatively low, and provide the suggestion for adding more descriptions;
Step 2-2):Comment section in the analysis rule other side's method file annotated on method carries out quality with method name Analysis, and annotation to being unsatisfactory for analysis rule provides corresponding suggestion;
Step 3):Quantity according to above-mentioned suggestion provides overall quality evaluation.
2. a kind of object-oriented program according to claim 1 annotation quality evaluation and annotation suggesting method, the step Rapid 2-2) mass analysis method it is as follows:
A) comment section and method name in traversal method file, counts annotated method name and does not have annotated method name, And annotated method name is calculated using formula X=Y/Z*100%, Y represents the number of annotated method, Z method for expressing text The sum of method in part, and X is compared with threshold value set in advance, if being less than threshold value, provide the more annotations of addition Suggestion;
B) annotated method name carries out correlation analysis in other side's method file, and method name is partitioned into according to camel formula nomenclature In word, word number scale Q, then travel through the annotation in file, the word number contained in annotation to the word being partitioned into successively Note P, using formula O=P/Q*100%, O is compared with threshold value set in advance, if less than set threshold value, The suggestion for adding more annotations is given, if above set threshold value, illustrates that the annotation is related to the main classes in the code file Property is higher;C) annotated method name is not had to be analyzed in other side's method file, using the part of speech of wordnet tool analysis method names Composition;
If the composition of the part of speech of party's religious name is not verb plus noun or if not being title plus verb, illustrate that the method is needed Annotation is added, the suggestion of addition annotation is given;
If verb adds noun or title plus verb then to analyze its lines of code, if its lines of code is more than institute's gating Threshold value, then need to add understanding of some annotations to be conducive to code, provides the suggestion of addition annotation;
If lines of code is less than threshold value, analysis the method quotes the number of times of other method, if number of times is more than threshold value, Then need to add understanding of some annotations to be conducive to code, provide the suggestion of addition annotation, if number of times is less than threshold value, It is not annotated.
3. a kind of object-oriented program according to claim 1 annotation quality evaluation and annotation suggesting method, the step Rapid quality evaluating method 3) is as follows:By counting the suggestion given by above-mentioned quality analysis, suggestion rate is then calculated, utilized FormulaWherein, Suggestion- Rate represents suggestion rate,The sum to main classes annotation suggestion is represented, annotation point of 3 expressions in bracket to main classes Analysis one has three kinds,Represent and sum advised to annotated method,Represent annotated method Sum,Expression does not have the suggestion sum of annotated method,Expression does not have annotated method total Number,The proportion accounted for main classes annotation suggestion is represented,The proportion accounted for the suggestion of annotated method is represented,The proportion to not having annotated method suggestion to account for is represented, suggestion rate is compared with threshold value set in advance, If greater than threshold value, illustrate the poor quality of code file annotation, it is necessary to improve carefully, it is proposed that developer is according to suggestion Modification annotation, it is proposed that rate is less than 0.5, illustrates that the quality of the code file is higher;If all methods have annotation, i.e.,Then
CN201410355299.2A 2014-07-24 2014-07-24 A kind of annotation quality evaluation of object-oriented program and annotation suggesting method Active CN104123273B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410355299.2A CN104123273B (en) 2014-07-24 2014-07-24 A kind of annotation quality evaluation of object-oriented program and annotation suggesting method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410355299.2A CN104123273B (en) 2014-07-24 2014-07-24 A kind of annotation quality evaluation of object-oriented program and annotation suggesting method

Publications (2)

Publication Number Publication Date
CN104123273A CN104123273A (en) 2014-10-29
CN104123273B true CN104123273B (en) 2017-06-06

Family

ID=51768687

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410355299.2A Active CN104123273B (en) 2014-07-24 2014-07-24 A kind of annotation quality evaluation of object-oriented program and annotation suggesting method

Country Status (1)

Country Link
CN (1) CN104123273B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106021410A (en) * 2016-05-12 2016-10-12 中国科学院软件研究所 Source code annotation quality evaluation method based on machine learning
US10846082B2 (en) 2016-09-08 2020-11-24 Microsoft Technology Licensing, Llc Systems and methods for determining and enforcing the optimal amount of source code comments
CN107506621A (en) * 2017-07-28 2017-12-22 阿里巴巴集团控股有限公司 Identification characteristics, the method and device of identification feature and electronic equipment
US11262985B2 (en) 2020-03-10 2022-03-01 International Business Machines Corporation Pretraining utilizing software dependencies
CN111984243A (en) * 2020-08-31 2020-11-24 上海玳鸽信息技术有限公司 General security check and function extension method and device based on annotation

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1395171A (en) * 2001-07-06 2003-02-05 华为技术有限公司 Code statistical tool of computer software program and its implementing method
JP2011258076A (en) * 2010-06-10 2011-12-22 Exa Corp Java source code check program

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1395171A (en) * 2001-07-06 2003-02-05 华为技术有限公司 Code statistical tool of computer software program and its implementing method
JP2011258076A (en) * 2010-06-10 2011-12-22 Exa Corp Java source code check program

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
【原创】项目管理杂谈(1):代码评审这点事,元芳你怎么看;Jack Jiang;《http://www.cnblogs.com/jb2011/archive/2012/10/31/2748047.html》;20121031;第1-2页 *
Quality Analysis of Source Code Comments;Daniela Steidl 等;《2013 21st International Conference on Program Comprehension(ICPC)》;20130520;第83-92页 *

Also Published As

Publication number Publication date
CN104123273A (en) 2014-10-29

Similar Documents

Publication Publication Date Title
CN104123273B (en) A kind of annotation quality evaluation of object-oriented program and annotation suggesting method
CN106682411B (en) A method of disease label is converted by physical examination diagnostic data
US10831793B2 (en) Learning thematic similarity metric from article text units
CN100520782C (en) News keyword abstraction method based on word frequency and multi-component grammar
CN102693279B (en) Method, device and system for fast calculating comment similarity
CN106649597A (en) Method for automatically establishing back-of-book indexes of book based on book contents
CN103336766A (en) Short text garbage identification and modeling method and device
CN103440235A (en) Method and device for identifying text emotion types based on cognitive structure model
CN104462399B (en) The processing method and processing device of search result
CN105068990B (en) A kind of English long sentence dividing method of more strategies of Machine oriented translation
CN108345468A (en) Programming language code duplicate checking method based on tree and sequence similarity
CN103106211B (en) Emotion recognition method and emotion recognition device for customer consultation texts
Schadd et al. Maasmatch results for oaei 2011
CN105205163B (en) A kind of multi-level two sorting technique of the incremental learning of science and technology news
Krug et al. Rule-based coreference resolution in German historic novels
CN106503256B (en) A kind of hot information method for digging based on social networks document
CN106339313B (en) A kind of abnormal inconsistent automatic testing method of description with document of Java api routines
CN107145476A (en) One kind is based on improvement TF IDF keyword extraction algorithms
CN106649557A (en) Semantic association mining method for defect report and mail list
Rawat et al. Automatic detection of online abuse and analysis of problematic users in wikipedia
CN106598997A (en) Method and device for computing membership degree of text subject
Xia et al. Combining MetaMap and cTAKES in Disorder Recognition: THCIB at CLEF eHealth Lab 2013 Task 1.
CN106156035B (en) A kind of generic text method for digging and system
CN104104659B (en) Communication fingerprint extraction method and device
CN108959375A (en) A kind of rule-based Knowledge Extraction Method with deep learning

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant