/* The following comment was added by Kari Laitinen on 15.3.2005 This is one of the Prolog programs of which an experimental software maintenance tool called InName is made. InName is a disabbreviation tool with which it is possible convert abbreviated names of C/C++ programs to more understandable, natural names. The Prolog source programs of the InName tool are now declared "Open Source" programs. People who have contributed to the original development of these programs include Kari Laitinen http://www.naturalprogramming.com Neil Rowe U.S. Naval Postgraduate School Markku Heikkila Currently works at Nokia. Jorma Taramaa Currently works at Nokia. The InName tool was developed at VTT Electronics, a division of the Technical Reseach Centre of Finland. The work was funded by VTT Electronics and the EU. It is the wish of the original developers that the above names will be mentioned if these programs are exploited in the development of other disabbreviation tools. A description about the InName tool and theoretical discussion related to it can be found at Laitinen, K., Taramaa, J., Heikkila, M., and Rowe, N. C.. Enhancing Maintainability of Source Programs through Disabbreviation. The Journal of Systems and Software, Vol. 37, No. 2, 1997, pp. 117 - 128. The text of the original file begins below. */ /*------------------------------------------------------------------------ VTT Electronics Quintus Prolog source program Embedded Software AMES / InName - project Kari Laitinen File: inname_comments.pro Version: 0.1 Status: draft Accepted: File history: 7.9.1994 v0.0 File created Kari Laitinen 28.10.1994 v0.1 Last Modification Kari Laitinen ---------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------- A B S T R A C T ----------------------------------------------------------------------------- This file contains prolog programs to "parse" the comments which are found in the existing source programs. Comment based potential names are made as follows: A grammar is used to parse comments into lists of comment words. Every comment is split to these lists according to punctuation characters and two or one letter words. Then, a separate routine generates the comment based potential names. This routine excludes the generation of those potential names which contain words which are typically nonexistent in natural names. ----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------- P R O L O G E N V I R O N M E N T ---------------------------------------------------------------------------*/ :- no_style_check(single_var). :- ensure_loaded(library(caseconv)). :- ensure_loaded(library(basics)). :- ensure_loaded(library(lists)). :- ensure_loaded('inname_utilities.pro.qof'). :- ensure_loaded('inname_first_pass.pro.qof'). /*--------------------------------------------------------------------------- D A T A B A S E - R E L A T E D D E F I N I T I O N S ---------------------------------------------------------------------------*/ :- multifile potential_name/1, potential_substitution/2, last_found_name_like_string/1. :- dynamic potential_name/1, potential_substitution/2, last_found_name_like_string/1. :- multifile reserved_word/1. /* This is a static fact. */ /*--------------------------------------------------------------------------- F A C T S F O R T H E D A T A B A S E ---------------------------------------------------------------------------*/ /* Two or one letter words need not be here, since they have been filtered out earlier in the grammar. */ not_typical_word_in_a_name(about). not_typical_word_in_a_name(already). not_typical_word_in_a_name(and). not_typical_word_in_a_name(because). not_typical_word_in_a_name(can). not_typical_word_in_a_name(cannot). not_typical_word_in_a_name(could). not_typical_word_in_a_name(for). not_typical_word_in_a_name(from). not_typical_word_in_a_name(had). not_typical_word_in_a_name(has). not_typical_word_in_a_name(have). not_typical_word_in_a_name(how). not_typical_word_in_a_name(into). not_typical_word_in_a_name(since). not_typical_word_in_a_name(the). not_typical_word_in_a_name(what). not_typical_word_in_a_name(when). not_typical_word_in_a_name(where). not_typical_word_in_a_name(which). not_typical_word_in_a_name(who). not_typical_word_in_a_name(why). not_typical_word_in_a_name(with). /*--------------------------------------------------------------------------- P R O L O G P R O G R A M S ( "RULES" ) ---------------------------------------------------------------------------*/ clean_comment_characters( List_of_characters, Cleaned_list_of_characters ) :- get_rid_of_special_characters( List_of_characters, List_in_which_special_characters_are_replaced_with_spaces ), !, get_rid_of_unnecessary_spaces( List_in_which_special_characters_are_replaced_with_spaces, List_without_unnecessary_spaces ), !, lower( List_without_unnecessary_spaces, Cleaned_list_of_characters ), !. convert_oneline_comment_to_list_of_words( Cleaned_list_of_characters, List_of_words ) :- phrase( list_of_oneline_comment_words( List_of_words ), Cleaned_list_of_characters ), !. /* When this rule does not succeed the potential substitution will not be generated. */ /****************** convert_cleaned_list_of_characters_to_name( List_of_characters, Name_as_string ) :- replace_spaces_with_underscores_in_list( List_of_characters, Underscored_list_of_characters ), shorten_a_name_character_list_if_necessary( 45, Underscored_list_of_characters, Shortened_list_of_characters ), name( Name_as_string, Shortened_list_of_characters ), !. *********************/ generate_potential_names_and_substitutions( List_of_comment_characters ) :- clean_comment_characters( List_of_comment_characters, Cleaned_list_of_characters ), phrase( useful_comment( Lists_of_useful_comment_words ), Cleaned_list_of_characters ), generate_potential_names( Lists_of_useful_comment_words ), (( \+ member( 10, List_of_comment_characters ), generate_potential_substitution_from_oneline_comment( Cleaned_list_of_characters ) ) ; ( true ) ), !. generate_potential_names_and_substitutions( _ ) :- !. generate_potential_names( [ First_list_of_words | Other_lists_of_words ] ) :- generate_potential_names__process_one_list( First_list_of_words ), !, generate_potential_names( Other_lists_of_words ), !. generate_potential_names( [] ) :- !. generate_potential_names__process_one_list( List_of_comment_words ) :- nextto( First_word, Second_word, List_of_comment_words ), \+ not_typical_word_in_a_name( First_word ), \+ not_typical_word_in_a_name( Second_word ), \+ potential_name( [ First_word, Second_word ] ), assertz( potential_name( [ First_word, Second_word ] ) ), fail. generate_potential_names__process_one_list( List_of_comment_words ) :- nextto( First_word, Second_word, List_of_comment_words ), nextto( Second_word, Third_word, List_of_comment_words ), \+ not_typical_word_in_a_name( First_word ), \+ not_typical_word_in_a_name( Second_word ), \+ not_typical_word_in_a_name( Third_word ), \+ potential_name( [ First_word, Second_word, Third_word ] ), assertz( potential_name( [ First_word, Second_word, Third_word ] ) ), fail. generate_potential_names__process_one_list( _ ) :- !. generate_potential_substitution_from_oneline_comment( Cleaned_list_of_comment_characters ) :- last_found_name_like_string( Possible_unknown_name ), \+ reserved_word( Possible_unknown_name ), convert_oneline_comment_to_list_of_words( Cleaned_list_of_comment_characters, Potential_name_as_list_of_words ), /* In theory there could be a potential substitution for this Possible_unknown_name in the database. However, it is very unlikely. */ assertz( potential_substitution( Possible_unknown_name, Potential_name_as_list_of_words ) ), !. generate_potential_substitution_from_oneline_comment( _ ) :- !. get_rid_of_special_characters( List_of_characters, List_without_special_characters ) :- append( First_part_of_list, [ Some_character | Rest_of_list ], List_of_characters ), ( ( Some_character =:= 10 ) ; /* newline */ ( Some_character =:= 42 ) ; /* * */ ( Some_character =:= 95 ) ; /* _ */ ( Some_character =:= 61 ) ; /* = */ ( Some_character =:= 45 ) /* - */ ), append( First_part_of_list, [ 32 | Rest_of_list ], List_with_one_special_character_less ), !, get_rid_of_special_characters( List_with_one_special_character_less, List_without_special_characters ), !. get_rid_of_special_characters( List_without_special_characters, List_without_special_characters ) :- !. process_comment_information( List_of_characters ) :- length( List_of_characters, Number_of_characters_in_this_comment ), Number_of_characters_in_this_comment < 300, Number_of_characters_in_this_comment > 7, member( Some_character, List_of_characters ), character_is_a_letter( Some_character ), generate_potential_names_and_substitutions( List_of_characters ), !. process_comment_information( List_of_characters ) :- !. shorten_a_name_character_list_if_necessary( Maximum_length, Name_character_list, Shortened_name_character_list ) :- length( Name_character_list, Length_of_name_character_list ), Length_of_name_character_list =< Maximum_length, Shortened_name_character_list = Name_character_list, !. shorten_a_name_character_list_if_necessary( Maximum_length, Name_character_list, Shortened_name_character_list ) :- rev( Name_character_list, Reversed_name_character_list ), append( Characters_to_be_left_out, [95| First_part_of_character_list ], Reversed_name_character_list ), length( First_part_of_character_list, Length_of_shortened_name ), Length_of_shortened_name =< Maximum_length, rev( First_part_of_character_list, Shortened_name_character_list ), !. shorten_a_name_character_list_if_necessary( Maximum_length, Name_character_list, Shortened_name_character_list ) :- /* In this case we could not split the name from an underscore. */ append( Shortened_name_character_list, Characters_to_be_left_out, Name_character_list ), length( Shortened_name_character_list, Maximum_length ), !. test_comment( List_of_comment_characters ) :- assertz( last_found_name_like_string(kukkuu)), process_comment_information( List_of_comment_characters ), write_potential_names, nl, write_potential_substitutions, retractall( potential_substitution( _, _ ) ), retractall( potential_name( _ ) ), retractall( last_found_name_like_string( _ ) ), !. write_potential_names :- nl, write( 'P O T E N T I A L N A M E S' ), nl, potential_name( Some_potential_name ), write( Some_potential_name ), nl, fail. write_potential_names :- !. write_potential_substitutions :- nl, write( 'P O T E N T I A L S U B S T I T U T I O N S' ), nl, potential_substitution( Unknown_name, Substitution ), write( Unknown_name ), write( ' ' ), write( Substitution ), nl, fail. write_potential_substitutions :- !. /*--------------------------------------------------------------------------- The "grammar" of comments. -----------------------------------------------------------------------------*/ useful_comment( Lists_of_useful_comment_words ) --> lists_of_useful_comment_words( Lists_of_useful_comment_words ) ; lists_of_useful_comment_words( Lists_of_useful_comment_words ), punctuation_and_spaces ; lists_of_useful_comment_words( Lists_of_useful_comment_words ), " ", not_useful_comment_words ; lists_of_useful_comment_words( Lists_of_useful_comment_words ), " ", not_useful_comment_words, punctuation_and_spaces ; not_useful_comment_words, " ", lists_of_useful_comment_words( Lists_of_useful_comment_words ) ; not_useful_comment_words, " ", lists_of_useful_comment_words( Lists_of_useful_comment_words ), punctuation_and_spaces ; not_useful_comment_words, " ", lists_of_useful_comment_words( Lists_of_useful_comment_words ), " ", not_useful_comment_words ; not_useful_comment_words, " ", lists_of_useful_comment_words( Lists_of_useful_comment_words ), " ", not_useful_comment_words, punctuation_and_spaces. lists_of_useful_comment_words( Lists_of_useful_comment_words ) --> list_of_useful_comment_words( List_of_useful_comment_words ), { Lists_of_useful_comment_words = [ List_of_useful_comment_words ] }. lists_of_useful_comment_words( Lists_of_useful_comment_words ) --> list_of_useful_comment_words( List_of_useful_comment_words ), punctuation_and_spaces_and_not_useful_comment_words, lists_of_useful_comment_words( Other_lists_of_useful_comment_words ), { append( [ List_of_useful_comment_words ], Other_lists_of_useful_comment_words, Lists_of_useful_comment_words ) }. punctuation_and_spaces_and_not_useful_comment_words --> punctuation_and_spaces ; " ", not_useful_comment_words, " " ; punctuation_and_spaces, not_useful_comment_words, " " ; " ", not_useful_comment_words, punctuation_and_spaces ; " ", not_useful_comment_words, punctuation_and_spaces, not_useful_comment_words, " " . punctuation_and_spaces --> punctuation_symbol | punctuation_symbol, " " | " ", punctuation_symbol | " ", punctuation_symbol, " ". punctuation_symbol --> "." ; "," ; ";" ; ":" ; "!" ; "?" . not_useful_comment_words --> not_useful_comment_word ; not_useful_comment_word, " ", not_useful_comment_word. list_of_useful_comment_words( List_of_useful_comment_words ) --> useful_comment_word( Useful_comment_word ), { List_of_useful_comment_words = [ Useful_comment_word ] }. list_of_useful_comment_words( List_of_useful_comment_words ) --> useful_comment_word( Useful_comment_word ), " ", list_of_useful_comment_words( Other_useful_comment_words ), { append( [ Useful_comment_word ], Other_useful_comment_words, List_of_useful_comment_words ) }. not_useful_comment_word --> lowercase_letter( Only_one_letter ) ; lowercase_letter( First_letter ), lowercase_letter( Second_letter ). /****** "from" ; "with" ; "already" ; "because" ; "who" ; "when" ; "the" ; "which" ; "what" ; "why" ; "since" ; "and". *********************/ useful_comment_word( Word_as_string ) --> lowercase_letter( First_letter ), lowercase_letter( Second_letter ), nonempty_list_of_lowercase_letters( Other_letters ), { append( [ First_letter ], [ Second_letter ], First_two_letters ), append( First_two_letters, Other_letters, Word_as_list ), name( Word_as_string, Word_as_list ) }. /************ \+ member( Word_as_string, [from, with, already, because, who, when, the, which, what, why, since, and ] ) }. ******************/ nonempty_list_of_lowercase_letters( List_of_letters ) --> lowercase_letter( One_letter ), { List_of_letters = [ One_letter ] }. nonempty_list_of_lowercase_letters( List_of_letters ) --> lowercase_letter( One_letter ), nonempty_list_of_lowercase_letters( Rest_of_letters ), { append( [ One_letter ], Rest_of_letters, List_of_letters ) }. /*------------------------------------------------------------------------ The "grammar" for oneline comments. -------------------------------------------------------------------------*/ list_of_oneline_comment_words( [ Word_as_string ] ) --> list_of_letters_or_numbers( Word_as_list ), { name( Word_as_string, Word_as_list ) }. list_of_oneline_comment_words( List_of_words ) --> list_of_letters_or_numbers( Word_as_list ), list_of_not_letters_or_numbers, list_of_oneline_comment_words( List_of_subsequent_words ), { name( Word_as_string, Word_as_list ), append( [ Word_as_string ], List_of_subsequent_words, List_of_words ) }. list_of_letters_or_numbers( [ One_letter_or_number ] ) --> letter_or_number( One_letter_or_number ). list_of_letters_or_numbers( List_of_letters_or_numbers ) --> letter_or_number( One_letter_or_number ), list_of_letters_or_numbers( Subsequent_letters_or_numbers ), { append( [ One_letter_or_number ], Subsequent_letters_or_numbers, List_of_letters_or_numbers ) }. list_of_not_letters_or_numbers --> not_letter_or_number. list_of_not_letters_or_numbers --> not_letter_or_number, list_of_not_letters_or_numbers. letter_or_number( Letter_or_number ) --> [ Letter_or_number ], { character_is_a_letter_or_number( Letter_or_number ) }. not_letter_or_number --> [ Not_letter_or_number ], { character_is_not_a_letter_or_number( Not_letter_or_number ) }. not_letter_or_number( Not_letter_or_number ) --> [ Not_letter_or_number ], { character_is_not_a_letter_or_number( Not_letter_or_number ) }.