class GBN_TRANS -- should tranlslate standard input to standard output -- according to the supplied file, which contains pairs -- of strings to be translated using a trie. -- get_word doesn't work because trailing characters seem -- to be skipped. creation go feature array_1, array_2 : ARRAY [ STRING ] the_file : TEXT_FILE_READ error : STD_ERROR trie : GBN_TRIE word_count : INTEGER setup is local str, word_1, word_2 : STRING i, j : INTEGER input_finished : BOOLEAN do from !! array_1 . make ( 1, 100 ) !! array_2 . make ( 1, 100 ) until input_finished loop the_file . read_line str := the_file . last_string if str.count = 0 then input_finished := true else word_count := word_count + 1 j := str . first_index_of ( ' ' ) word_1 := str . substring ( 1, j - 1 ) word_2 := str . substring ( j+1, str.count ) array_1.force ( word_1, word_count ) array_2.force ( word_2, word_count ) end if the_file . end_of_input then input_finished := true end end array_1.resize ( 1, word_count ) array_2.resize ( 1, word_count ) !! trie . make ( array_1 ) error.put_string ( "Translation pairs:%N" ) from i := 1 until i > word_count loop error . put_string ( i.out + " " + array_1.item (i) + " " + array_2.item (i) + "%N" ) i := i + 1 end end translate is local i : INTEGER do from i := 1 trie . find_match until not trie . match_found loop io . put_string ( trie.text.substring ( i, trie.start_of_match - 1 )) io . put_string ( array_2 . item ( trie.index_of_match ) ) i := trie.start_of_match + trie.length_of_match trie . find_match end io . put_string ( trie.text.substring ( i, trie.text.count ) ) io . put_new_line end go is do !! error . make if argument_count /= 1 then error . put_string ( "Only one argument (filename) expected%N" ) else !! the_file . connect_to ( argument ( 1 ) ) if the_file . is_connected then setup from io . read_line until io . end_of_input loop trie . install ( io . last_string ) translate io . read_line end the_file . disconnect else error . put_string ( argument(1) + "cannot be opened for reading%N" ) end end end end -- class GBN_TRANS