⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umain.~pas

📁 用于中文分词的算法。包括逆向分词和反向分词
💻 ~PAS
字号:
unit UMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,UDic,UParser,UDocuments,UCalcWeight, ComCtrls, Grids,
  DB, ADODB;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    StatusBar1: TStatusBar;
    Button4: TButton;
    Button5: TButton;
    StringGrid1: TStringGrid;
    ADOConnection1: TADOConnection;
    StringGrid2: TStringGrid;
    Button6: TButton;
    ListBox1: TListBox;
    ListBox2: TListBox;
    Button3: TButton;
    Button7: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure StringGrid2SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure Button7Click(Sender: TObject);
  private
    { Private declarations }
    FDic : TAbstractDic;
    FParser : TParser;
    FVSMList : TVSMList;
    FDocs : TAbstractDocs;
    FDocWeights : TDocWeights;
    FCalcWeight : TCalcWeight;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  ConnString : string;
begin
  FDic := TFileDic.Create('dic.txt');
  FVSMList := TVSMList.Create;
  FParser := TParser.Create(FDic,FVSMList);
  //连接字符串
  ConnString := 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=ice';
  FDocs := TDBDocs.Create(ConnString,'问题答案表','ID号','答案');
  //
  FDocWeights := TDocWeights.Create ;
  FCalcWeight := TCalcWeight.Create(FDocWeights,FVSMList,FDocs);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //进行中文词的分析 
  while not FDocs.EndDoc do
  begin
    StatusBar1.Panels[0].Text := IntToStr(FDocs.getID());
    Application.ProcessMessages;
    FParser.Parser(FDocs.GetID(),FDocs.GetText());
    Application.ProcessMessages;
    FDocs.NextDoc;
  end;
  StatusBar1.Panels[0].text := '分析完成!打开文件数:'+IntToStr(FDocs.GetDocCount);
  //保存向量空间列表
  FVSMList.SaveVector('c:\a.vsm');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i,j : integer;
  Str : string;
begin
stringgrid2.RowCount:=FVSMList.Count+1;
StringGrid2.Cells[0,0]:='关键词';
 StringGrid2.Cells[1,0]:='向量1';
 StringGrid2.Cells[2,0]:='向量2';
 StringGrid2.Cells[3,0]:='向量3';
 StringGrid2.Cells[4,0]:='向量4';
 StringGrid2.Cells[5,0]:='向量5';
 StringGrid2.Cells[6,0]:='向量6';
 StringGrid2.Cells[7,0]:='向量7';
 StringGrid2.Cells[8,0]:='向量8';
 StringGrid2.Cells[9,0]:='向量9';
 StringGrid2.Cells[10,0]:='向量10';
 StringGrid2.Cells[11,0]:='向量11';
 StringGrid2.Cells[12,0]:='向量12';
 StringGrid2.Cells[13,0]:='向量13';
 StringGrid2.Cells[14,0]:='向量14';
 StringGrid2.Cells[15,0]:='向量15';
 StringGrid2.Cells[16,0]:='向量16';
 StringGrid2.Cells[17,0]:='向量17';
 StringGrid2.Cells[18,0]:='向量18';
 StringGrid2.Cells[19,0]:='向量19';
 StringGrid2.Cells[20,0]:='向量20';
 StringGrid2.Cells[21,0]:='向量21';
 StringGrid2.Cells[22,0]:='向量22';
 StringGrid2.Cells[23,0]:='向量23';
 StringGrid2.Cells[24,0]:='向量24';
 StringGrid2.Cells[25,0]:='向量25';
 StringGrid2.Cells[26,0]:='向量26';
 StringGrid2.Cells[27,0]:='向量27';
 StringGrid2.Cells[28,0]:='向量28';
 StringGrid2.Cells[29,0]:='向量29';
 StringGrid2.Cells[30,0]:='向量30';
  //显示向量空间列表
  for i:=0 to FVSMList.Count -1 do
  begin
    stringgrid2.Cells[0,i+1] := FVSMList.GetWords(i);
    for j:=0 to fvsmlist.vsm(i).count-1 do
    begin
      stringgrid2.Cells[j+1,i+1] := ' ('+IntToStr(FVSMList.VSM(i).Vector(J).FID)+','+IntToStr(FVSMList.VSM(i).Vector(J).FPos)+') ';
    end;
    ListBox2.Items:=StringGrid2.Rows[StringGrid2.Row];
  end;
end;

{procedure TForm1.Button3Click(Sender: TObject);
begin
 //读取向量空间列表
  FVSMList.ReadVector('c:\a.vsm');
end;}

procedure TForm1.Button4Click(Sender: TObject);
begin
  //进行计算
  FCalcWeight.Calc;
  FDocWeights.Save('c:\a.wgt');
  StatusBar1.Panels[0].text :='计算已完成!请点击显示权重!';
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  i,j : integer;
  Str : String;
  docWeight : TDocWeight;
begin
stringgrid1.Cells[0,0]:='ID\关键词';
StringGrid1.colcount:=FVSMlist.count+1;
stringgrid1.RowCount:=fdocweights.Count+1;
for i:=0 to fvsmlist.Count-1 do
begin
stringgrid1.Cells[i+1,0]:=fvsmlist.GetWords(i);
end;
  //显示文档权重
  For i:=0 to FDocWeights.Count-1 do
  begin

    docWeight := FDocWeights.Weight_Index(i);
    stringgrid1.Cells[0,i+1]:= IntToStr(docWeight.DocID);
    For j :=1 to stringgrid1.ColCount-1 do
    begin
       stringgrid1.Cells[j,i+1]:=FloatToStr(fdocweights.Weight_IDWord(fdocweights.Weight_Index(i).DocID,stringgrid1.Cells[j,0]));
    end;
    ListBox1.Items:=StringGrid1.cols[stringgrid1.Col];
  end;
end;

{procedure TForm1.Button6Click(Sender: TObject);
begin
  //加载文档权重
  FDocWeights.Load('c:\a.wgt'); 
end;}

procedure TForm1.FormShow(Sender: TObject);
begin
  FDic.LoadDic;
  FDocs.LoadDocs;
  StatusBar1.Panels[0].text := '打开的文件数:'+IntToStr(FDocs.GetDocCount);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  i,j : integer;
  Str : String;
begin
 listBox1.Clear ;
 listBox2.Clear ;
 For i :=1 to stringgrid1.ColCount-1 do
 begin
  stringgrid1.Cols[i].Clear;
 end;
 For i :=1 to stringgrid2.ColCount-1 do
 begin
 stringgrid2.Cols[i].Clear;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
form1.Hide;
form2.show;
end;

procedure TForm1.StringGrid2SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
ListBox2.Items.Assign(StringGrid2.Rows[ARow]);
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
ListBox1.Items.Assign(StringGrid1.Rows[ARow]);
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
 form1.Hide;
form5.show;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -