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

📄 usearch.pas

📁 用于中文分词的算法。包括逆向分词和反向分词
💻 PAS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -