/ Published in: Pascal
Expand |
Embed | Plain Text
{ тема Юлиного курсовика по трпп: частотный анализ текста(по предложениям) (подсчитывается относительная частота встречаемости в тексте предложений различной длины(1,2,3...слова). Границами слов яв-ся символы: /* точка,запятая, двоеточие, пробел, точка с запятой, скобки, тире, вопр. и воскл. знаки */ . , " ' ; ( ) - ? ! границами предложения- /* точка, вопр. и воскл. знаки */ . ? ! Текст вводится по выбору пользователя с клавиатуры (при этом должна быть возможность записи его в файл), либо из текстового файла; вывод результатов- на экран, принтер или в файл по желанию пользователя. } { -------------------------------------------------------------------------- } program count; { Название программы } uses crt; { Использовать модуль для рисования псевдографики } type { секция обьявления новых типов данных } plist = ^tlist; { указатель } tlist = record { запись } words : integer; { количество слов } sentences : integer; { количество предложений } next : plist { указатель на следующий узел } end; { конец записи } var { секция обьявления переменных } list, start : plist; { бегающий и начальный указатели на список } buffer : string; { буффер для обработки текста } { переменные для хранения информации о количестве слов и предложений } words_all, sentences_all, ii, words_count, sentences_count : integer; input_file : text; { указатель на входной файл } state : integer; result : integer; mbuffer : char; { -------------------------------------------------------------------------- } { процедура ищет узел в списке по количеству } procedure Search (words : integer); { принимает количество слов } begin { начало тела процедуры } list := start; { перемотать указатель } while list <> nil do { пока не конец списка } begin if words = list^.words then { если совпадает то } break { закончить цикл } else list := list^.next; { иначе продолжить } end end; { конец процедуры Search } { -------------------------------------------------------------------------- } procedure Add ( words : integer ); { } var { } l : plist; { } begin { } sentences_count := sentences_count + 1; { } New (l); { } l^.sentences := 1; { } l^.words := words; { } l^.next := nil; { } if start <> nil then { } begin list := start; { } while list^.next <> nil do { } list := list^.next; { } list^.next := l { } end else start := l; { } list := l { } end; { } { -------------------------------------------------------------------------- } procedure Display; { } begin { } if start = nil then { } begin textcolor (red); { } writeLn ('no sentences were analised'); textcolor (yellow); { } exit { } end; list := start; { } textcolor (red); { } write; writeln ( '========================' ); { } textcolor (yellow); { } while list <> nil do { } begin { } writeln ( ' ', list^.words:3, ' (', (list^.words * 100)/words_all:2:2, '%) words in ', list^.sentences:2, ' (', ( list^.sentences * 100)/sentences_all :2:2 , '%) sentences.' ); list := list^.next { } end; textcolor (red); { } writeln ( '========================' ); { } textcolor (yellow); { } writeln ( 'sentences in file: ', sentences_all ); { } writeln ( 'words in file: ', words_all ); { } end; { -------------------------------------------------------------------------- } procedure sentence_done ( words : integer ); { } begin sentences_all := sentences_all + 1; { } search (words); { } if list = nil then { } add(words) { } else list^.sentences := list^.sentences + 1; { } end; { -------------------------------------------------------------------------- } procedure feed_char ( some_char : char ); { } begin case some_char of { } ',', { запятая } ' ', { пробел } ';', { точка с запятой } '(', { открывающая скобка } ')', { закрывающая скобка } '-': { тире } begin { увеличить счетчик слов } words_count := words_count + 1; words_all := words_all + 1; end; '.', { точка } '?', { вопр. знак } '!': { воскл. знак } begin { } { } words_count := words_count + 1; sentence_done ( words_count ); words_all := words_all + 1; words_count := 0; end; end; end; { -------------------------------------------------------------------------- } { -------------------------------------------------------------------------- } { -------------------------------------------------------------------------- } begin sentences_all := 0; { } words_all := 0; { } sentences_count := 0; { } words_count := 0; { } textbackground (blue); { Установить синий цвет фона } textcolor (white); { Установить желтый цвет текста } clrscr; state := 0; while state = 0 do begin writeln('From where?'); writeln(' 1-file;'); writeln(' 2-keyboard'); writeln(' 3-keyboard + write text to file'); read(state); end; clrscr; result := 0; while result = 0 do begin writeln('Where to display results?'); writeln(' 1-screen;'); writeln(' 2-printer;'); writeln(' 3-file;'); read(result); end; clrscr; if state = 1 then begin assign ( input_file, 'text_en.txt' ); { } reset ( input_file ); { } while not EOF ( input_file ) do { } begin readln ( input_file, buffer ); { } writeln ( buffer ); { } for ii := 1 to ord(buffer[0]) do { } feed_char( buffer[ii] ); end; display(); end else if state = 2 then begin mbuffer := #0; while mbuffer <> #27 do begin mbuffer := readKey; feed_char( mbuffer ); write(mbuffer); end; display(); end; textcolor (white); { } writeln('press ENTER'); { } readln { } end. { }
You need to login to post a comment.
