/* 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 - project Kari Laitinen File: inname_statistics.pro Version: 0.1 Status: draft Accepted: File history: 20.7.94 v0.0 File Created Kari Laitinen 5.5.95 v0.1 Last Modification Kari Laitinen ---------------------------------------------------------------------------*/ :- no_style_check(single_var). :- ensure_loaded( library( caseconv ) ). :- ensure_loaded('inname_utilities.pro.qof'). :- ensure_loaded('inname_first_pass.pro.qof'). /*-------------------------------------------------------------------------- D A T A D E F I N I T I O N S ---------------------------------------------------------------------------*/ :- multifile found_name/2, found_word/2, found_string/2, general_counters/2. :- dynamic found_name/2, found_word/2, found_string/2, general_counters/2. /*-------------------------------------------------------------------------- STORING SUBSTITUTIONS TO A FILE ---------------------------------------------------------------------------*/ store_name_substitutions_to_file( Program_file_name ) :- name( Program_file_name, Program_file_name_as_list ), append( Program_file_name_as_list, ".substitutions", Substitutions_file_name_as_list ), name( Substitutions_file_name, Substitutions_file_name_as_list ), tell( Substitutions_file_name ), write( 'Name substitution statistic for file ' ), write( Program_file_name ), write( ' are the following:' ), nl, nl, write_all_counters, nl, nl, write( 'Name substitutions in file ' ), write( Program_file_name ), write( ' are the following:' ), nl, nl, write( 'OLD NAMES: NAME SUBSTITUTIONS: ' ), write( 'LINE NUMBERS: ' ), nl, write( '---------- --------------------' ), write( '-------------' ), nl,nl, findall( Unknown_name, name_substitution( Unknown_name, _, _ ), List_of_unknown_names ), sort( List_of_unknown_names, Sorted_list_of_unknown_names ), store_name_substitutions_to_file__process_sorted_list( Sorted_list_of_unknown_names ), told, !. store_name_substitutions_to_file__process_sorted_list( [ Unknown_name | Rest_of_unknown_names_in_order ] ) :- name_substitution( Unknown_name, Substitution_as_list_of_words, List_of_line_numbers ), store_name_substitutions_to_file__write_one_line( Unknown_name, Substitution_as_list_of_words, List_of_line_numbers ), !, store_name_substitutions_to_file__process_sorted_list( Rest_of_unknown_names_in_order ), !. store_name_substitutions_to_file__process_sorted_list( [] ) :- !. store_name_substitutions_to_file__write_one_line( Unknown_name, Substitution_as_list_of_words, List_of_line_numbers ) :- add_trailing_spaces_to_string( Unknown_name, 17, Unknown_name_with_trailing_spaces ), write( Unknown_name_with_trailing_spaces ), convert_list_of_words_to_underscored_string( Substitution_as_list_of_words, Substitution_as_string ), add_trailing_spaces_to_string( Substitution_as_string, 35, Substitution_with_trailing_spaces ), write( Substitution_with_trailing_spaces ), write_numeric_list_and_truncate_it_if_necessary( List_of_line_numbers, 5 ), nl, !. /*-------------------------------------------------------------------------- N A M E A N D W O R D S T A T I S T I C S ---------------------------------------------------------------------------*/ process_data_of_one_statistics_file([ Empty_line, Summary_text_line, Summary_data_line, Summary_percentage_line | [] ] ) :- !. process_data_of_one_statistics_file( [ First_statistics_data_line | Rest_of_statistics_data_lines ] ) :- lower( First_statistics_data_line, Lowercase_statistics_data_line ), atom_chars( Lowercase_statistics_data_line, Statistics_data_as_list ), append( Occurrence_count_as_list, [32,32,32 | Word_or_name_as_list ], Statistics_data_as_list ), number_chars( Occurrence_count, Occurrence_count_as_list ), name( Word_or_name, Word_or_name_as_list ), write( Occurrence_count ), write( ' ' ), write( Word_or_name ), nl, update_database_with_string_occurrence_data( Word_or_name, Occurrence_count ), !, process_data_of_one_statistics_file( Rest_of_statistics_data_lines ). process_individual_statistics_files( [ First_file | Rest_of_files ] ) :- see( First_file ), read_lines_from_currently_open_file( List_of_statistics_data ), process_data_of_one_statistics_file( List_of_statistics_data ), seen, !, process_individual_statistics_files( Rest_of_files ). process_individual_statistics_files( [] ) :- !. produce_multifile_statistics( File_containing_file_names ) :- retractall( general_counters( _, _ ) ), retractall( found_string( _, _ ) ), see( File_containing_file_names ), read_lines_from_currently_open_file( List_of_file_names_read_from_file ), seen, remove_empty_strings_from_string_list( List_of_file_names_read_from_file, List_of_file_names ), write( 'List_of_file_names: ' ), write( List_of_file_names ), nl, first( Combined_statistics_file_name, List_of_file_names ), append( [ Combined_statistics_file_name ], List_of_individual_statistics_files, List_of_file_names ), process_individual_statistics_files( List_of_individual_statistics_files ), store_combined_statistics( Combined_statistics_file_name ), !. store_combined_statistics( Combined_statistics_file_name ) :- bagof( Occurrence_count-String_as_string, found_string( String_as_string, Occurrence_count ), List_of_count_and_string_pairs ), keysort( List_of_count_and_string_pairs, Ascending_list_of_count_and_string_pairs ), rev( Ascending_list_of_count_and_string_pairs, Descending_list_of_count_and_string_pairs ), tell( Combined_statistics_file_name ), store_combined_statistics__write_data_lines( Descending_list_of_count_and_string_pairs ), store_combined_statistics__write_summary_lines, told, !. store_combined_statistics__write_data_lines( [ First_occurrence_count-First_string | Rest_of_count_and_string_pairs ] ) :- write( First_occurrence_count ), write( ' ' ), write( First_string ), nl, update_string_occurrence_counters( First_occurrence_count ), !, store_combined_statistics__write_data_lines( Rest_of_count_and_string_pairs ). store_combined_statistics__write_data_lines( [] ) :- !. store_combined_statistics__write_summary_lines :- nl, write( 'Total 1_to_2 3_to_4 5_to_9 10_or_more' ), nl, read_counter( total_number_of_strings, Total_number_of_strings ), write( Total_number_of_strings ), write( ' ' ), read_counter( number_of_1_to_2_times_occurring_strings, Number_of_1_to_2_times_occurring_strings ), write( Number_of_1_to_2_times_occurring_strings ), write( ' ' ), read_counter( number_of_3_to_4_times_occurring_strings, Number_of_3_to_4_times_occurring_strings ), write( Number_of_3_to_4_times_occurring_strings ), write( ' ' ), read_counter( number_of_5_to_9_times_occurring_strings, Number_of_5_to_9_times_occurring_strings ), write( Number_of_5_to_9_times_occurring_strings ), write( ' ' ), read_counter( number_of_10_or_more_times_occurring_strings, Number_of_10_or_more_times_occurring_strings ), write( Number_of_10_or_more_times_occurring_strings ), write( ' ' ), nl, write('100% ' ), Percentage_of_1_to_2_times_occurring_strings is ( Number_of_1_to_2_times_occurring_strings * 100 ) // Total_number_of_strings, write( Percentage_of_1_to_2_times_occurring_strings ), write( '% ' ), Percentage_of_3_to_4_times_occurring_strings is ( Number_of_3_to_4_times_occurring_strings * 100 ) // Total_number_of_strings, write( Percentage_of_3_to_4_times_occurring_strings ), write( '% ' ), Percentage_of_5_to_9_times_occurring_strings is ( Number_of_5_to_9_times_occurring_strings * 100 ) // Total_number_of_strings, write( Percentage_of_5_to_9_times_occurring_strings ), write( '% ' ), Percentage_of_10_or_more_times_occurring_strings is ( Number_of_10_or_more_times_occurring_strings * 100 ) // Total_number_of_strings, write( Percentage_of_10_or_more_times_occurring_strings ), write( '% ' ), nl, reset_counter( number_of_1_to_2_times_occurring_strings ), reset_counter( number_of_3_to_4_times_occurring_strings ), reset_counter( number_of_5_to_9_times_occurring_strings ), reset_counter( number_of_10_or_more_times_occurring_strings ), !. store_name_statistics( Program_file_name ) :- name( Program_file_name, Program_file_name_as_list ), (( append( File_name_body, ".c", Program_file_name_as_list ), append( File_name_body, ".names", Name_statistics_file_name_as_list ) ); ( /* This code is for the case that Program_file_name is not ended by ".c" */ append( Program_file_name_as_list, ".names", Name_statistics_file_name_as_list ) ) ), !, name( Name_statistics_file_name, Name_statistics_file_name_as_list ), bagof( Occurrence_count-Name_as_string, found_name( Name_as_string, Occurrence_count ), List_of_count_and_name_pairs ), keysort( List_of_count_and_name_pairs, Ascending_list_of_count_and_name_pairs ), rev( Ascending_list_of_count_and_name_pairs, Descending_list_of_count_and_name_pairs ), tell( Name_statistics_file_name ), store_name_statistics__write_data_lines( Descending_list_of_count_and_name_pairs ), store_name_statistics__write_summary_lines, told, !. store_name_statistics__write_data_lines( [ First_occurrence_count-First_name | Rest_of_count_and_name_pairs ] ) :- write( First_occurrence_count ), write( ' ' ), write( First_name ), nl, update_name_occurrence_counters( First_occurrence_count ), !, store_name_statistics__write_data_lines( Rest_of_count_and_name_pairs ). store_name_statistics__write_data_lines( [] ) :- !. store_name_statistics__write_summary_lines :- nl, write( 'Total 1_to_2 3_to_4 5_to_9 10_or_more' ), nl, read_counter( total_number_of_names, Total_number_of_names ), write( Total_number_of_names ), write( ' ' ), read_counter( number_of_1_to_2_times_occurring_names, Number_of_1_to_2_times_occurring_names ), write( Number_of_1_to_2_times_occurring_names ), write( ' ' ), read_counter( number_of_3_to_4_times_occurring_names, Number_of_3_to_4_times_occurring_names ), write( Number_of_3_to_4_times_occurring_names ), write( ' ' ), read_counter( number_of_5_to_9_times_occurring_names, Number_of_5_to_9_times_occurring_names ), write( Number_of_5_to_9_times_occurring_names ), write( ' ' ), read_counter( number_of_10_or_more_times_occurring_names, Number_of_10_or_more_times_occurring_names ), write( Number_of_10_or_more_times_occurring_names ), write( ' ' ), nl, write('100% ' ), Percentage_of_1_to_2_times_occurring_names is ( Number_of_1_to_2_times_occurring_names * 100 ) // Total_number_of_names, write( Percentage_of_1_to_2_times_occurring_names ), write( '% ' ), Percentage_of_3_to_4_times_occurring_names is ( Number_of_3_to_4_times_occurring_names * 100 ) // Total_number_of_names, write( Percentage_of_3_to_4_times_occurring_names ), write( '% ' ), Percentage_of_5_to_9_times_occurring_names is ( Number_of_5_to_9_times_occurring_names * 100 ) // Total_number_of_names, write( Percentage_of_5_to_9_times_occurring_names ), write( '% ' ), Percentage_of_10_or_more_times_occurring_names is ( Number_of_10_or_more_times_occurring_names * 100 ) // Total_number_of_names, write( Percentage_of_10_or_more_times_occurring_names ), write( '% ' ), nl, reset_counter( number_of_1_to_2_times_occurring_names ), reset_counter( number_of_3_to_4_times_occurring_names ), reset_counter( number_of_5_to_9_times_occurring_names ), reset_counter( number_of_10_or_more_times_occurring_names ), !. store_word_statistics( Program_file_name ) :- name( Program_file_name, Program_file_name_as_list ), (( append( File_name_body, ".c", Program_file_name_as_list ), append( File_name_body, ".words", Word_statistics_file_name_as_list ) ); ( /* This code is for the case that Program_file_name is not ended by ".c" */ append( Program_file_name_as_list, ".words", Word_statistics_file_name_as_list ) ) ), !, name( Word_statistics_file_name, Word_statistics_file_name_as_list ), bagof( Occurrence_count-Word_as_string, found_word( Word_as_string, Occurrence_count ), List_of_count_and_word_pairs ), keysort( List_of_count_and_word_pairs, Ascending_list_of_count_and_word_pairs ), rev( Ascending_list_of_count_and_word_pairs, Descending_list_of_count_and_word_pairs ), tell( Word_statistics_file_name ), store_word_statistics__write_data_lines( Descending_list_of_count_and_word_pairs ), store_word_statistics__write_summary_lines, told, !. store_word_statistics__write_data_lines( [ First_occurrence_count-First_word | Rest_of_count_and_word_pairs ] ) :- write( First_occurrence_count ), write( ' ' ), write( First_word ), nl, update_word_occurrence_counters( First_occurrence_count ), !, store_word_statistics__write_data_lines( Rest_of_count_and_word_pairs ). store_word_statistics__write_data_lines( [] ) :- !. store_word_statistics__write_summary_lines :- nl, write( 'Total 1_to_2 3_to_4 5_to_9 10_or_more' ), nl, read_counter( total_number_of_words, Total_number_of_words ), write( Total_number_of_words ), write( ' ' ), read_counter( number_of_1_to_2_times_occurring_words, Number_of_1_to_2_times_occurring_words ), write( Number_of_1_to_2_times_occurring_words ), write( ' ' ), read_counter( number_of_3_to_4_times_occurring_words, Number_of_3_to_4_times_occurring_words ), write( Number_of_3_to_4_times_occurring_words ), write( ' ' ), read_counter( number_of_5_to_9_times_occurring_words, Number_of_5_to_9_times_occurring_words ), write( Number_of_5_to_9_times_occurring_words ), write( ' ' ), read_counter( number_of_10_or_more_times_occurring_words, Number_of_10_or_more_times_occurring_words ), write( Number_of_10_or_more_times_occurring_words ), write( ' ' ), nl, write('100% ' ), Percentage_of_1_to_2_times_occurring_words is ( Number_of_1_to_2_times_occurring_words * 100 ) // Total_number_of_words, write( Percentage_of_1_to_2_times_occurring_words ), write( '% ' ), Percentage_of_3_to_4_times_occurring_words is ( Number_of_3_to_4_times_occurring_words * 100 ) // Total_number_of_words, write( Percentage_of_3_to_4_times_occurring_words ), write( '% ' ), Percentage_of_5_to_9_times_occurring_words is ( Number_of_5_to_9_times_occurring_words * 100 ) // Total_number_of_words, write( Percentage_of_5_to_9_times_occurring_words ), write( '% ' ), Percentage_of_10_or_more_times_occurring_words is ( Number_of_10_or_more_times_occurring_words * 100 ) // Total_number_of_words, write( Percentage_of_10_or_more_times_occurring_words ), write( '% ' ), nl, reset_counter( number_of_1_to_2_times_occurring_words ), reset_counter( number_of_3_to_4_times_occurring_words ), reset_counter( number_of_5_to_9_times_occurring_words ), reset_counter( number_of_10_or_more_times_occurring_words ), !. update_database_with_string_occurrence_data( The_string, Occurrence_count_to_be_added ) :- found_string( The_string, Old_occurrence_count ), retract( found_string( The_string, Old_occurrence_count ) ), New_occurrence_count is Old_occurrence_count + Occurrence_count_to_be_added, assert( found_string( The_string, New_occurrence_count ) ), !. update_database_with_string_occurrence_data( The_string, Initial_occurrence_count ) :- assert( found_string( The_string, Initial_occurrence_count ) ), !. update_name_occurrence_counters( Occurrence_count ) :- increment_counter( total_number_of_names ), (( Occurrence_count < 3, increment_counter( number_of_1_to_2_times_occurring_names ) ); ( Occurrence_count < 5, increment_counter( number_of_3_to_4_times_occurring_names ) ); ( Occurrence_count < 10, increment_counter( number_of_5_to_9_times_occurring_names ) ); ( increment_counter( number_of_10_or_more_times_occurring_names ) ) ), !. update_string_occurrence_counters( Occurrence_count ) :- increment_counter( total_number_of_strings ), (( Occurrence_count < 3, increment_counter( number_of_1_to_2_times_occurring_strings ) ); ( Occurrence_count < 5, increment_counter( number_of_3_to_4_times_occurring_strings ) ); ( Occurrence_count < 10, increment_counter( number_of_5_to_9_times_occurring_strings ) ); ( increment_counter( number_of_10_or_more_times_occurring_strings ) ) ), !. update_word_occurrence_counters( Occurrence_count ) :- increment_counter( total_number_of_words ), (( Occurrence_count < 3, increment_counter( number_of_1_to_2_times_occurring_words ) ); ( Occurrence_count < 5, increment_counter( number_of_3_to_4_times_occurring_words ) ); ( Occurrence_count < 10, increment_counter( number_of_5_to_9_times_occurring_words ) ); ( increment_counter( number_of_10_or_more_times_occurring_words ) ) ), !.