usearch.pas

来自「用于中文分词的算法。包括逆向分词和反向分词」· PAS 代码 · 共 92 行

PAS
92
字号
unit USearch;

{
//////////////////////////////////////////
  搜索类
//////////////////////////////////////////
}

interface
uses Classes,UDic,UDocuments,UParser,UCalcWeight,Windows;


Type
   TSearcher = Class
   private
     //FParser : TParser;
     //临时的向量列表
     FTmpVSMList : TVSMList;
     FTmpVSM : TVSM;
    FWeigths: TDocWeights;
   private
     //保存对象引用
     FVSMList : TVSMList;
     FParser : TParser;
     FWeights : TDocWeights;
   public
     Function StartSearch(Text : string):integer;
   public
     property VSMList : TVSMList read FVSMList Write FVSMList;
     property Parser : TParser read FParser write FParser;
     property Weigths : TDocWeights read FWeigths write FWeights;
   public
     Constructor Create(VSMList : TVSMList;Parser : TParser;Weights : TDocWeights);overload;
     Constructor Create();overload;
     Destructor Destroy();override;
   end;

implementation

{ TSearcher }

constructor TSearcher.Create(VSMList : TVSMList;Parser : TParser;Weights : TDocWeights);
begin
  FVSMList := VSMList;
  FParser := Parser;
  FWeights := Weights;
  FTmpVSMList := TVSMList.Create ;
  FTmpVSM := TVSM.Create;
end;

constructor TSearcher.Create;
begin
  FTmpVSMList := TVSMList.Create ;
  FTmpVSM := TVSM.Create;
end;

destructor TSearcher.Destroy;
begin
  FTmpVSM.Free;
  FTmpVSMList.Free;
  inherited;
end;

Function TSearcher.StartSearch(Text : string):integer;
var
  i : integer;
  VSMs : TVSMList;
  VSM : TVSM;
begin
  FTmpVSMList.Clear();
  VSMs := FParser.VSMList;
  FParser.VSMList := FTmpVSMList;
  FParser.Parser(0,Text);
  //查找文档
  FTmpVSM.Clear();
  for i:=0 to FTmpVSMList.Count-1 do
  begin
     VSM := FVSMList.VSM(FTmpVSMList.GetWords(i));
     if VSM <> nil then
     begin
       VSM.CloneTo(FTmpVSMList.VSM(i)); 
       FTmpVSMList.VSM(i).SigleDocID();
       FTmpVSM.AddVSM(FTmpVSMList.VSM(i));
     end;
  end;
  //从FTmpVSM
  Result := FTmpVSM.MaxDocID();
  FParser.VSMList := VSMs;
end;

end.

⌨️ 快捷键说明

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