{ Вывод результатов работы WORDS.EXE. (c) ICS, 1994
from: Pasha
to: Anna }
{ (8)Программа считает частоту употребления служебных слов в выборке текста
установленного размера с введенным шагом и выводит на экран график.
С таймером, датой, скроллингом.
Усреднение. }
Program WriteCountRes;
uses
Crt,Dos,Graph;
const
kQuan=7;
NSize=3000;
days : array[0..6] of string[11]
=('Воскресенье','Понедельник','Вторник','Среда','Четверг',
'Пятница','Суббота');
type
WordType = string [40];
WordRecType = record
WStr : WordType;
WPos : Longint;
WFlg : Char;
WNo : Longint;
end;
CountArrayType = record
StartWord : Longint;
EndWord : Longint;
CountWord : Longint;
end;
var
y,m,d,dow : word;
f : file of WordRecType;
WStr : WordRecType;
st,nost,i,j,p : longint;
grDrv,grMode,a,size : integer;
y0,b,y1,c : real;
ch : char;
T : array [1..NSize] of longint;
CountArray : array [1..1000] of CountArrayType;
Pasha : array [-kQuan..kQuan] of real;
MaxTh,WCount : longint;
StartCount : longint;
AWords,AW : longint;
MaxPer,MinPer,MidPer,DisPer : real;
MidQuan : real;
s,x,SSt,SSt1,SSt2 : string;
SSt3,SSt4,SSt5,SSt6 : string;
myString : string;
myFile,myFile2Anya : file of real;
myFileName : string;
myI : byte;
myJ,myK : longint;
myDec : longint;
k,l : longint;
Begin
clrscr;
AWords:=0; { количество слов в тексте }
WCount:=0; { счетчик служебных слов в тексте}
MaxTh:=0; { max число выборок }
StartCount:=0;
b:=0;
writeln(' Программа считает частоту употребления служебных слов в выборке текста');
writeln(' установленного размера с введенным шагом и выводит на экран график.');
write(' Введите имя файла:');
readln(x);
writeln;
myFileName:='pasha.$$$';
writeln(' Установка параметров: '); myI:=whereY;
writeln(' 1.ручная ');
writeln(' 2.автоматическая');
gotoxy(23,myI-1);
read(s);
if s='1' then
begin
gotoxy(1,myI+3);
write(' Введите оьъем выборки : ');
read(st);
write(' Введите шаг : ');
read(nost);
assign(f,x);
reset(f);
AWords:=FileSize(f);
close(f);
if AWords<st then
begin
writeln(' Смените параметры (объем выборки должен быть меньше ',AWords,')');
ch:=readkey;
halt;
end;
if nost>=0 then AW:=AWords div (st+nost);
if nost<0 then AW:=(AWords-st) div (st+nost);
end;
if s='2' then
begin
gotoxy(1,myI+3);
assign(f,x);
reset(f);
AWords:=FileSize(f);
close(f);
st:=16000;
AW:=(AWords div st)+1;
if AWords<st then
begin
writeln(' Установка параметров ручная ( объем выборки должен быть меньше ',AWords,')');
ch:=readkey;
halt;
end;
nost:=-(AW*st-AWords) div (AWords div st);
end;
assign(f,x);
reset(f);
for i:=1 to AW do
begin
CountArray[i].StartWord:=StartCount;
CountArray[i].EndWord:=StartCount+st;
CountArray[i].CountWord:=0;
StartCount:=StartCount+st+nost;
end;
write(' % выполнено'); myI:=whereY;
myK:=fileSize(f)-1;
for myJ:=0 to myK do
begin
read(f,WStr);
gotoxy(2,myI); write(round(myJ/myK*100):3);
if not(WStr.WFlg=' ') then
begin
for i:=1 to AW do
if (WStr.WNo>CountArray[i].StartWord) and
(WStr.WNo<CountArray[i].EndWord)
then inc(CountArray[i].CountWord);
inc(WCount);
MaxTh:=i;
end;
end;
close(f);
assign(myFile,myFileName);
rewrite(myFile);
c:=0;
for i:=1 to kQuan do write(myFile,c);
gotoxy(1,myI+1);
writeln(' Количество выборок - ',MaxTh);
writeln(' Служебные слова встречаются ',WCount,' раз.');
ch:=readkey;
MaxPer:=CountArray[1].CountWord*100/st;
MinPer:=CountArray[1].CountWord*100/st;
for i:=1 to AW do
begin
writeln('T[',i:4,']:=',CountArray[i].CountWord*100/st:3:3,'%');
if MaxPer<CountArray[i].CountWord*100/st then MaxPer:=CountArray[i].CountWord*100/st;
if MinPer>CountArray[i].CountWord*100/st then MinPer:=CountArray[i].CountWord*100/st;
c:=CountArray[i].CountWord*100/st;
write(myFile,c);
for a:=1 to 50 do
if i=15*a then ch:=readkey;
end;
for i:=1 to AW do b:=b+CountArray[i].CountWord*100/st;
MidPer:=b/AW; {Средний процент}
b:=0;
for i:=1 to AW do b:=b+((CountArray[i].CountWord*100/st-MidPer)*(CountArray[i].CountWord*100/st-MidPer));
DisPer:=sqrt(b/AW); {Дисперсия}
writeln(' Максимальный процент: ',MaxPer);
writeln(' Минимальный процент: ',MinPer);
writeln(' Средний процент: ',MidPer);
writeln(' Дисперсия: ',DisPer);
c:=0;
for i:=1 to kQuan+1 do write(myFile,c);
close(myFile);
repeat until readkey=#27;
writeln('Нажмите <Esc>');
grDrv:=0; grMode:=0;
InitGraph(grDrv,grMode,'');
SetLineStyle(SolidLn,0,1);
SetColor(LightGray);
Line(2,0,2,278); Line(0,275,640,275);
Line(0,5,2,0); Line(2,0,4,5);
Line(632,273,640,275); Line(640,275,632,277);
OutTextXY(10,3,'y,%'); OutTextXY(600,265,'x,th');
Str(MaxPer,SSt);
Str(MinPer,SSt1);
OutTextXY(10,280,'Максимальный % (max) -');
OutTextXY(10,290,'Минимальный % (min) -');
OutTextXY(180,280,SSt);
OutTextXY(180,290,SSt1);
SetColor(White);
MoveTo(2,275);
for i:=1 to MaxTh do
begin
y0:=round(CountArray[i].CountWord*100/st);
LineTo(round(i*640/MaxTh),275-round(y0*2.75));
end;
SetColor(LightGray);
OutTextXY(500,20,'Нажмите <Esc>');
repeat until readkey=#27;
ClearDevice;
SetLineStyle(SolidLn,0,1);
SetColor(LightGray);
Line(2,0,2,278); Line(0,275,640,275);
Line(0,5,2,0); Line(2,0,4,5);
Line(632,273,640,275); Line(640,275,632,277);
OutTextXY(10,3,'y,%'); OutTextXY(600,280,'x,th');
Str(MaxPer,SSt);
Str(MinPer,SSt1);
Str(MidPer,SSt2);
Str(DisPer,SSt3);
Str(st,SSt4);
Str(nost,SSt5);
Str(MaxTh,SSt6);
OutTextXY(10,280,'Максимальный % (max) -');
OutTextXY(10,290,'Минимальный % (min) -');
OutTextXY(10,300,'Средний % (mid) -');
OutTextXY(10,310,'Дисперсия -');
OutTextXY(10,320,'Шаг считаемый :');
OutTextXY(10,330,'Шаг несчитаемый :');
OutTextXY(10,340,'Количество выборок:');
OutTextXY(10,350,'Файл :');
OutTextXY(180,280,SSt);
OutTextXY(180,290,SSt1);
OutTextXY(180,300,SSt2);
OutTextXY(180,310,SSt3);
OutTextXY(180,320,SSt4);
OutTextXY(180,330,SSt5);
OutTextXY(180,340,SSt6);
OutTextXY(180,350,x);
OutTextXY(4,265,'min');
OutTextXY(4,10,'max');
GetDate(y,m,d,dow);
Str(m:0,SSt2);
Str(d:0,SSt3);
Str(y:0,SSt4);
sst5:=days[dow]+'/'+sst2+'/'+sst3+'/'+sst4;
OutTextXY(10,370,'Сегодня ');
MoveTo(80,370);
OutText(SSt5);
OutTextXY(4,277-round((MidPer-MinPer)*(270/(MaxPer-MinPer))),'mid');
MoveTo(2,275);
SetColor(White);
p:=1; setColor(White);
myDec:=630;
if (p+myDec)>=MaxTh then myDec:=MaxTh-p-2;
for i:=p to p+myDec do
begin
y0:=CountArray[i].CountWord*100/st;
y1:=CountArray[i+1].CountWord*100/st;
Line(i+6-p,274-round((y0-MinPer)*(270/(MaxPer-MinPer))),
i+7-p,274-round((y1-MinPer)*(270/(MaxPer-MinPer))));
end;
{скроллинг}
repeat
ch:=upcase(readkey);
case ch of
'B' : begin
if p=0 then p:=1;
myDec:=630;
if (p+myDec)>=MaxTh then myDec:=MaxTh-p-2;
for i:=p to p+myDec do
begin
y0:=CountArray[i].CountWord*100/st;
y1:=CountArray[i+1].CountWord*100/st;
SetColor(Black);
Line(i+6-p,274-round((y0-MinPer)*(270/(MaxPer-MinPer))),
i+7-p,274-round((y1-MinPer)*(270/(MaxPer-MinPer))));
SetColor(White);
y0:=CountArray[i+2].CountWord*100/st;
Line(i+6-p,274-round((y1-MinPer)*(270/(MaxPer-MinPer))),
i+7-p,274-round((y0-MinPer)*(270/(MaxPer-MinPer))));
end;
SetColor(Black);
Line(i+7-p,274-round((y0-MinPer)*(270/(MaxPer-MinPer))),
i+6-p,274-round((y1-MinPer)*(270/(MaxPer-MinPer))));
inc(p);
end;
'C': begin
if p<=1 then p:=2;
myDec:=630;
if (p+myDec)>=MaxTh then myDec:=MaxTh-p-2;
for i:=p to p+myDec do
begin
y0:=CountArray[i].CountWord*100/st;
y1:=CountArray[i+1].CountWord*100/st;
SetColor(Black);
Line(i+6-p,274-round((y0-MinPer)*(270/(MaxPer-MinPer))),
i+7-p,274-round((y1-MinPer)*(270/(MaxPer-MinPer))));
SetColor(White);
y1:=CountArray[i-1].CountWord*100/st;
Line(i+6-p,274-round((y1-MinPer)*(270/(MaxPer-MinPer))),
i+7-p,274-round((y0-MinPer)*(270/(MaxPer-MinPer))));
end;
dec(p); if p<=1 then p:=1;
end;
end;
SetColor(LightGray);
OutTextXY(4,265,'min');
OutTextXY(4,10,'max');
OutTextXY(4,277-round((MidPer-MinPer)*(270/(MaxPer-MinPer))),'mid');
OutTextXY(500,300,'Нажмите <Esc>');
until ch=#27;
reset(myFile);
assign(myFile2Anya,'HA-HA.$$$');
rewrite(myFile2Anya);
{усреднение}
for i:=1 to MaxTh-1 do
begin
b:=0;
MidQuan:=0;
seek(myFile,i-1);
for j:=-kQuan to kQuan do read(myFile,Pasha[j]);
{Сортируем все это}
for k:=-kQuan to kQuan do
begin
if Pasha[k]<MinPer then Pasha[k]:=Pasha[0];
b:=b+Pasha[k];
end;
MidQuan:=b/(kQuan*2+1);
write(myFile2Anya,MidQuan);
end;
close(myFile); close(myFile2Anya);
ClearDevice;
SetLineStyle(SolidLn,0,1);
SetColor(LightGray);
Line(2,0,2,278); Line(0,275,640,275);
Line(0,5,2,0); Line(2,0,4,5);
Line(632,273,640,275); Line(640,275,632,277);
OutTextXY(10,3,'y,%'); OutTextXY(600,280,'x,th');
reset(myFile2Anya);
MoveTo(2,275);
SetColor(White);
for i:=1 to MaxTh-1 do
begin
read(myFile2Anya,y0);
LineTo(i,275-round((y0-MinPer)*(270/(MaxPer-MinPer))));
end;
readkey;
end.