Einzelnen Beitrag anzeigen

t.roller
(Gast)

n/a Beiträge
 
#13

AW: Buchstabenhäufigkeit

  Alt 13. Feb 2017, 16:54
Ich habe auch eine Lösung:
Es arbeitet mit der Buchstabenhäufigkeit lt. Tabelle in
Buchstabenhäufigkeit in deutschsprachigen Texten

Jeder gefundene Buchstabe wird gelöscht und verkürzt den Text, was nachfolgende Suchen beschleunigt.
Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Vcl.ExtDlgs;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Memo11: TMemo;
    Memo13: TMemo;
    Button4: TButton;
    OpenTextFileDialog1: TOpenTextFileDialog;
    Button1: TButton;
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  nextLetter : Integer;
  LOT : Integer; //Length(Memo11.text);

implementation

{$R *.dfm}

function CountChars(const subtext, Text: String): Integer;
var Text3 : String;
begin
inc(nextLetter);
Text3:= StringReplace(Text, subtext, '', [rfReplaceAll, rfIgnoreCase]);
Result := Length(Text) - Length(Text3);
Form1.Memo11.text:= Text3;
Form1.StringGrid1.Cells[0,nextLetter]:= subtext;
Form1.StringGrid1.Cells[1,nextLetter]:= INTTOSTR(Result);
Form1.StringGrid1.Cells[2,nextLetter]:= FLOATTOSTR(Result / (LOT/100));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Memo11.Clear; Memo13.Clear;
if OpenTextfileDialog1.Execute then
BEGIN
  Memo11.Lines.LoadFromFile(OpenTextfileDialog1.FileName);
  nextLetter:=0;
  Application.ProcessMessages;
  LOT:= Length(Memo11.text);
END;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
    StringGrid1.Cells[0,0]:= 'Buchstabe';
    StringGrid1.Cells[1,0]:= 'Häufigkeit';
    StringGrid1.Cells[2,0]:= 'Prozent';
    Memo13.Lines.Add('Memo11-Length: '+INTTOSTR(Length(Memo11.text)));
    Memo13.Lines.Add('e: '+INTTOSTR(CountChars('e',Memo11.Text)));
    Memo13.Lines.Add('n:'+INTTOSTR(CountChars('n',Memo11.Text)));
    Memo13.Lines.Add('i: '+INTTOSTR(CountChars('i',Memo11.Text)));
    Memo13.Lines.Add('s: '+INTTOSTR(CountChars('s',Memo11.Text)));
    Memo13.Lines.Add('r: '+INTTOSTR(CountChars('r',Memo11.Text)));
    Memo13.Lines.Add('a: '+INTTOSTR(CountChars('a',Memo11.Text)));
    Memo13.Lines.Add('t: '+INTTOSTR(CountChars('t',Memo11.Text)));
    Memo13.Lines.Add('d: '+INTTOSTR(CountChars('d',Memo11.Text)));
    Memo13.Lines.Add('h: '+INTTOSTR(CountChars('h',Memo11.Text)));
    Memo13.Lines.Add('u: '+INTTOSTR(CountChars('u',Memo11.Text)));
    Memo13.Lines.Add('l: '+INTTOSTR(CountChars('l',Memo11.Text)));
    Memo13.Lines.Add('c: '+INTTOSTR(CountChars('c',Memo11.Text)));
    Memo13.Lines.Add('g: '+INTTOSTR(CountChars('g',Memo11.Text)));
    Memo13.Lines.Add('m: '+INTTOSTR(CountChars('m',Memo11.Text)));
    Memo13.Lines.Add('o: '+INTTOSTR(CountChars('o',Memo11.Text)));
    Memo13.Lines.Add('b: '+INTTOSTR(CountChars('b',Memo11.Text)));
    Memo13.Lines.Add('w: '+INTTOSTR(CountChars('w',Memo11.Text)));
    Memo13.Lines.Add('f: '+INTTOSTR(CountChars('f',Memo11.Text)));
    Memo13.Lines.Add('k: '+INTTOSTR(CountChars('k',Memo11.Text)));
    Memo13.Lines.Add('z: '+INTTOSTR(CountChars('z',Memo11.Text)));
    Memo13.Lines.Add('p: '+INTTOSTR(CountChars('p',Memo11.Text)));
    Memo13.Lines.Add('v: '+INTTOSTR(CountChars('v',Memo11.Text)));
    Memo13.Lines.Add('ß: '+INTTOSTR(CountChars('ß',Memo11.Text)));
    Memo13.Lines.Add('j: '+INTTOSTR(CountChars('j',Memo11.Text)));
    Memo13.Lines.Add('y: '+INTTOSTR(CountChars('y',Memo11.Text)));
    Memo13.Lines.Add('x: '+INTTOSTR(CountChars('x',Memo11.Text)));
    Memo13.Lines.Add('q: '+INTTOSTR(CountChars('q',Memo11.Text)));
    Memo13.Lines.Add('ä: '+INTTOSTR(CountChars('ä',Memo11.Text)));
    Memo13.Lines.Add('ö: '+INTTOSTR(CountChars('ö',Memo11.Text)));
    Memo13.Lines.Add('ü: '+INTTOSTR(CountChars('ü',Memo11.Text)));
    Memo13.Lines.Add('0: '+INTTOSTR(CountChars('0',Memo11.Text)));
    Memo13.Lines.Add('1: '+INTTOSTR(CountChars('1',Memo11.Text)));
    Memo13.Lines.Add('2: '+INTTOSTR(CountChars('2',Memo11.Text)));
    Memo13.Lines.Add('3: '+INTTOSTR(CountChars('3',Memo11.Text)));
    Memo13.Lines.Add('4: '+INTTOSTR(CountChars('4',Memo11.Text)));
    Memo13.Lines.Add('5: '+INTTOSTR(CountChars('5',Memo11.Text)));
    Memo13.Lines.Add('6: '+INTTOSTR(CountChars('6',Memo11.Text)));
    Memo13.Lines.Add('7: '+INTTOSTR(CountChars('7',Memo11.Text)));
    Memo13.Lines.Add('8: '+INTTOSTR(CountChars('8',Memo11.Text)));
    Memo13.Lines.Add('9: '+INTTOSTR(CountChars('9',Memo11.Text)));
    Memo13.Lines.Add('Memo11-Length: '+INTTOSTR(Length(Memo11.text)));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  nextLetter:=0;
  Memo11.Lines.LoadFromFile('F:\schtasks.txt');
  Application.ProcessMessages;
  LOT:= Length(Memo11.text);
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var s: string;
begin
  s := StringGrid1.Cells[ACol, ARow];
  StringGrid1.Canvas.FillRect(Rect);
  DrawText(StringGrid1.Canvas.Handle, PChar(s), Length(s), Rect,
  DT_SINGLELINE or DT_Center or DT_VCENTER); // Text zentrieren
end;

end.
Miniaturansicht angehängter Grafiken
bsh-01.jpg  

Geändert von t.roller (13. Feb 2017 um 17:04 Uhr)
  Mit Zitat antworten Zitat