/* 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_dictionary.pro Version: 0.1 Status: draft Accepted by: File history: 12.7.1994 v0.0 File created Kari Laitinen 5.5.1995 v0.1 Last modification Kari Laitinen ----------------------------------------------------------------------------- N O T E S ----------------------------------------------------------------------------- 5.5.95: read_lines_from_currently_open_file does not make lowercase conversions any more. That may cause some troubles somewhere in general dictionary updating. ---------------------------------------------------------------------------*/ :- no_style_check(single_var). :- ensure_loaded( library( files ) ). :- ensure_loaded( library( strings ) ). :- ensure_loaded( library( caseconv ) ). :- ensure_loaded('inname_utilities.pro.qof'). :- multifile previous_name_substitution/2, name_substitution/3, domain_word/1. :- dynamic previous_name_substitution/2, name_substitution/3, domain_word/1. generate_backup_file( File_name, Backup_file_name ) :- name( File_name, File_name_as_list ), append( File_name_as_list, ".old", Backup_file_name_as_list ), name( Backup_file_name, Backup_file_name_as_list ), (( file_exists( Backup_file_name ), delete_file( Backup_file_name ) ) ; ( true ) ), !, (( file_exists( File_name ), rename_file( File_name, Backup_file_name ) ) ; ( true ) ), ! . generate_dictionary :- file_exists( 'inname_dictionary_words.facts' ), delete_file( 'inname_dictionary_words.facts' ), fail. generate_dictionary :- tell( 'inname_dictionary_words.facts' ), nl, write( ':- multifile dictionary_word/1.' ), nl, nl, see( 'dictionary_words.list' ), generate_dictionary_in_loop, seen, told, !. generate_dictionary_in_loop :- \+ at_end_of_file, read_one_line( One_word_from_raw_dictionary_words ), (( One_word_from_raw_dictionary_words \== '', writeq( dictionary_word( One_word_from_raw_dictionary_words ) ), write( '.' ), nl ) ; ( true ) ), !, generate_dictionary_in_loop. generate_dictionary_in_loop :- !. /*------------------------------------------------------------------------- DOMAIN DICTIONARY etc. -------------------------------------------------------------------------*/ list_domain_words :- domain_word( Word_in_string_form ), write( Word_in_string_form ), nl, fail. list_domain_words :- !. list_found_words :- found_word( Word_in_string_form, Occurrence_count ), write( Word_in_string_form ), nl, fail. list_found_words :- !. load_domain_dictionary( Dictionary_file_name ) :- file_exists( Dictionary_file_name ), retractall( domain_word( _ ) ), see( Dictionary_file_name ), read_lines_from_currently_open_file( List_of_domain_words ), load_domain_dictionary__generate_database( List_of_domain_words ), seen, write( List_of_domain_words ), nl, !. load_domain_dictionary( _ ) :- inform_user( 'Domain dictionary file not found' ), !. load_domain_dictionary__generate_database( [ First_word | Rest_of_words ] ) :- lower( First_word, Lowercase_first_word ), assertz( domain_word( Lowercase_first_word ) ), !, load_domain_dictionary__generate_database( Rest_of_words ). load_domain_dictionary__generate_database( [] ) :- !. store_domain_dictionary( Dictionary_file_name ) :- generate_backup_file( Dictionary_file_name, _ ), bagof( Word_in_string_form, domain_word( Word_in_string_form ), List_of_domain_words ), write( List_of_domain_words ), nl, tell( Dictionary_file_name ), write_list_of_lines_in_currently_open_file( List_of_domain_words ), told, !. update_domain_dictionary_with_new_words( [ First_word | Rest_of_words ] ) :- lower( First_word, Lowercased_first_word ), ( domain_word( Lowercased_first_word ) -> ( true ) ; ( asserta( domain_word( Lowercased_first_word ) ), increment_counter( number_of_addings_to_domain_dictionary ) ) ), !, update_domain_dictionary_with_new_words( Rest_of_words ), !. update_domain_dictionary_with_new_words( [] ) :- !. store_domain_words :- file_exists( 'domain_words.tmp' ), delete_file( 'domain_words.tmp' ), fail. store_domain_words :- tell( 'domain_words.tmp' ), fail. store_domain_words :- domain_word( Word_in_string_form ), name( Word_in_string_form, Word_in_list_form ), length( Word_in_list_form, Number_of_characters_in_the_word ), Number_of_characters_in_the_word > 1, write( Word_in_string_form ), nl, fail. store_domain_words :- told, !. store_found_words :- tell( 'found_words.tmp' ), fail. store_found_words :- found_word( Word_in_string_form, Occurrence_count ), name( Word_in_string_form, Word_in_list_form ), length( Word_in_list_form, Number_of_characters_in_the_word ), Number_of_characters_in_the_word > 1, write( Word_in_string_form ), nl, fail. store_found_words :- told, !. update_dictionary( File_containing_new_words ) :- file_exists( 'dictionary_words.old' ), delete_file( 'dictionary_words.old' ), fail. update_dictionary( File_containing_new_words ) :- (( file_exists( 'dictionary_words.list' ), rename_file( 'dictionary_words.list', 'dictionary_words.old' ), see( 'dictionary_words.old' ), read_lines_from_currently_open_file( List_of_old_dictionary_words ), seen ); ( List_of_old_dictionary_words = [] ) ), see( File_containing_new_words ), read_lines_from_currently_open_file( List_of_new_dictionary_words ), seen, append( List_of_old_dictionary_words, List_of_new_dictionary_words, List_in_wrong_order_with_possible_duplicates ), /* Sorting removes duplicates automatically. */ sort( List_in_wrong_order_with_possible_duplicates, Sorted_list_of_dictionary_words ), tell( 'dictionary_words.list' ), write_list_of_lines_in_currently_open_file( Sorted_list_of_dictionary_words ), told, !. update_dictionary_with_domain_words :- store_domain_words, update_dictionary( 'domain_words.tmp' ). /*------------------------------------------------------------------------- PROGRAMS TO HANDLE PREVIOUS NAME SUBSTITUTIONS -------------------------------------------------------------------------*/ convert_names_and_substitutions_into_storage_format( [ ( First_name, First_substitution ) | Rest_of_pairs_of_names_and_substitutions ], [ First_combined_string | Rest_of_combined_strings ] ) :- string_append( First_name, ' ', First_name_followed_by_a_space ), string_append( First_name_followed_by_a_space, First_substitution, First_combined_string ), !, convert_names_and_substitutions_into_storage_format( Rest_of_pairs_of_names_and_substitutions, Rest_of_combined_strings ), !. convert_names_and_substitutions_into_storage_format( [], [] ) :- !. form_list_of_new_substitutions( List_of_pairs_of_names_and_substitutions ) :- findall( ( Unknown_name, Substitution_as_string ), ( name_substitution( Unknown_name, Substitution_as_list_of_words, _ ), convert_list_of_words_to_underscored_string( Substitution_as_list_of_words, Substitution_as_string ) ), List_of_pairs_of_names_and_substitutions ), !. load_previous_substitutions :- file_exists( 'previous_name_substitutions.data' ), retractall( previous_name_substitution( _, _) ), see( 'previous_name_substitutions.data' ), read_lines_from_currently_open_file( List_of_strings ), seen, load_previous_substitutions__generate_database( List_of_strings ), !. load_previous_substitutions :- inform_user( 'Previous substitutions file not found' ), !. load_previous_substitutions__generate_database( [ First_string | Rest_of_strings ] ) :- atom_chars( First_string, String_as_list ), append( Name_as_list, [ 32 | Substitution_as_list ], String_as_list ), atom_chars( Name_as_string, Name_as_list ), atom_chars( Substitution_as_string, Substitution_as_list ), assertz( previous_name_substitution( Name_as_string, Substitution_as_string ) ), !, load_previous_substitutions__generate_database( Rest_of_strings ), !. load_previous_substitutions__generate_database( [] ) :- !. produce_new_previous_substitutions_file :- generate_backup_file( 'previous_name_substitutions.data', _ ), form_list_of_new_substitutions( List_of_pairs_of_new_names_and_substitutions ), findall( ( Unknown_name, Substitution_as_string ), previous_name_substitution( Unknown_name, Substitution_as_string ), List_of_pairs_of_old_names_and_substitutions ), append( List_of_pairs_of_new_names_and_substitutions, List_of_pairs_of_old_names_and_substitutions, List_of_pairs_of_all_names_and_substitutions ), sort( List_of_pairs_of_all_names_and_substitutions, Sorted_list_of_pairs_of_names_and_substitutions ), convert_names_and_substitutions_into_storage_format( Sorted_list_of_pairs_of_names_and_substitutions, List_of_strings_to_be_stored_to_file ), tell( 'previous_name_substitutions.data' ), write_list_of_lines_in_currently_open_file( List_of_strings_to_be_stored_to_file ), told, !.