X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=AbonUnit.pas;h=7ed49585b7655987e7486bd5fa77d7adb8b3552f;hb=refs%2Fheads%2FBb57;hp=9a93cb08aa0d01f9dc81cf45ea58fb1e4119c846;hpb=de2ee435d1cb9623055edc3b02c57fa4d3b5a488;p=gikonavigoeson%2Fgikonavi.git
diff --git a/AbonUnit.pas b/AbonUnit.pas
index 9a93cb0..7ed4958 100644
--- a/AbonUnit.pas
+++ b/AbonUnit.pas
@@ -1,3 +1,8 @@
+{
+NO_ABON Ú[ñÏÝÌXà\¦·é(²³êé)
+SPAM_FILTER_ENABLED XptB^ð@\³¹é
+}
+
unit AbonUnit;
interface
@@ -5,496 +10,938 @@ uses
Windows,Messages, ShellAPI, SysUtils, Classes,StdCtrls,StrUtils;
type
+ TIndiviAbon = class( TObject )
+ private
+ FRes: Integer;
+ FOption: Integer; // 0:§¾ 1:Êí Ú[ñ
+ public
+ property Res : Integer read FRes write FRes;
+ property Option : Integer read FOption write FOption;
+ end;
+
+ TIndiviAbonList = class( TList )
+ private
+ FFilePath : string; //!< t@CpX
+ FLearned : Integer; //!< XpwKÏÝX No
+
+ function GetItem( index : Integer ) : TIndiviAbon;
+ procedure SetItem( index : Integer; value : TIndiviAbon );
+
+ public
+ destructor Destroy; override;
+
+ property Items[ index : Integer ] : TIndiviAbon
+ read GetItem write SetItem; default;
+ procedure Sort; overload;
+ procedure LoadFromFile( const filePath : string );
+ procedure Save;
+ end;
+
TAbon = class(TObject)
private
- { Private é¾ }
- Froot : String;
- FNGwordpath : String;
- Ftokens : array of array of string;
- FAbonString : String;
- FRetStrings : TStringList;
- FCutoffNum : Integer; //±ÌÈãA±·é¯¶pðNG[hÆ·é
- procedure SetTokens(index: integer ; argline:String);
-
+ { Private é¾ }
+ Froot : String;
+ Flistpath : String;
+ FNGwordpath : String;
+ Ftokens : array of array of string;
+ FAbonRes : TIndiviAbonList;
+ FAbonString : String;
+ FpAbons : PChar;
+ FpAbone : PChar;
+ FDeleterlo : Boolean; //&rlo;ðíé© //ÇÁ&lro;àíé
+ FReplaceul :Boolean ; //
^Oð
^OÉu··é©
+ FReverse : Boolean ; //NG[hÅÌ Ú`ñÌÊð½]³¹é©
+ FAbonPopupRes : Boolean; //X|bvAbvÌÉ Ú[ñ·é©
+ FNGwordFileIndex : Integer; //»ÝÇÝñÅéNG[hªlist̽sÚ©
+ FNGwordname : String; //»ÝÇÝñÅéNG[hÌ\¦¼
+ FIndividualFileName : String; //ÂÊ Ú`ñÌt@C¼
+ FReturnNGwordLineNum : Boolean; //NG[hÌsðÔ·B
+ FSetNGResAnchor : Boolean; //NGÉYµ½Æ«É{¶É»ÌXÖÌXAJ[ð¯é©Ç¤©
+ FDeleteSyria: Boolean; //VAêuNÎôi܀~ݏj
+ FIgnoreKana: Boolean; //Sp¼pÐçªÈJ^JiÌá¢ð³·é©
+ procedure SetTokens(index: integer ; argline:String);
+ function Getlistpath() : String;
+ procedure Setlistpath(const Value : String);
+ function LoadListFile(path :String;listStringList : TStringList) : Boolean;
+ function ReadNGwordslist(line : Integer) : Boolean;
+ function LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
public
- { Public é¾ }
- constructor Create; // RXgN^
- destructor Destroy; override; // fXgN^
-
- procedure Setroot(root :String);
- function Getroot() : String;
- procedure SetNGwordpath(path :String);
- function GetNGwordpath() : String;
- procedure SetCutoffNum(value : Integer);
- function GetCutoffNum() : Integer;
- function LoadFromNGwordFile(path :String) : Boolean;
- function ReLoadFromNGwordFile() : Boolean;
- function FindNGwords(line : String) : Boolean; //1C¸ÂpB
- function Cutoff(line : String) : String; //CutOfflÈãÂ̯¶pªÀñÅ¢½çtrue
- // Ú`ñÌÉ¢ÅÉ&rlo;ð³éA^Oð
^OÉu··é©AöÌu[lÍtrue¾ÆANG[hðÜÞà̾¯ðÔ·B
- function Execute(DestStrings : TStringList; deleterlo : Boolean; replaceul :Boolean ; reverse : Boolean) : TStringList; overload;
- function Execute(DestStrings : TStringList; NGwords : TStringList ; deleterlo : Boolean; replaceul :Boolean ;reverse : Boolean) : TStringList; overload;
- function Execute(DestStrings : TStringList; NGwords : TStrings ; deleterlo : Boolean; replaceul :Boolean ;reverse : Boolean) : TStringList; overload;
- //--
- function ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; overload;//DATt@Cð¼É¢¶é
- function ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; overload; //DATt@Cð¼É¢¶é
- function ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; overload; //DATt@Cð¼É¢¶é
- function ReverseExecuteFile(datfilepath : String) : Boolean; overload; //DATt@Cð¼É¢¶é
- function ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; overload; //DATt@Cð¼É¢¶é
- function ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; overload; //DATt@Cð¼É¢¶é
+ { Public é¾ }
+ constructor Create; // RXgN^
+ destructor Destroy; override; // fXgN^
+ property Deleterlo: Boolean read FDeleterlo write FDeleterlo default false;
+ property Replaceul: Boolean read FReplaceul write FReplaceul default false;
+ property Reverse: Boolean read FReverse write FReverse default false;
+ property AbonString : String read FAbonString write FAbonString;
+ property AbonPopupRes : Boolean read FAbonPopupRes write FAbonPopupRes default false;
+ property listpath : String read Getlistpath write Setlistpath;
+ property NGwordFileIndex : Integer read FNGwordFileIndex write FNGwordFileIndex default 0;
+ property NGwordname : String read FNGwordname write FNGwordname;
+ property ReturnNGwordLineNum : Boolean read FReturnNGwordLineNum write FReturnNGwordLineNum default false;
+ property SetNGResAnchor : Boolean read FSetNGResAnchor write FSetNGResAnchor default false;
+ property DeleteSyria : Boolean read FDeleteSyria write FDeleteSyria default false;
+ property IgnoreKana: Boolean read FIgnoreKana write FIgnoreKana default false;
+ procedure Setroot(root :String);
+ function Getroot() : String;
+
+ function Getfullpath(argpath : String) : String;
+ procedure SetNGwordpath(path :String);
+ function GetNGwordpath() : String;
+ function LoadFromNGwordFile(path :String) : Boolean;
+ function ReLoadFromNGwordFile() : Boolean;
+ procedure LoadFromStringList( bufstl : TStringList );
+ function CheckAbonPopupRes(line : String) :Boolean;
+ function FindNGwords(const line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean;//1C¸ÂpB
+ // Ú`ñ(NG[hÅÌtB^O)
+ procedure Execute(var ThreadStrings : TStringList); overload;
+ procedure Execute(var ResString : String; ResNumber : Integer); overload; //åÉplugin©çÌDat To HTML p
+
+{$IFDEF SPAM_FILTER_ENABLED}
+ //! XptB^ÌwK
+ procedure Learn( resList : TStringList );
+{$ENDIF}
+ //ÂÊ Ú`ñµåè
+ procedure IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String); overload;
+ procedure IndividualAbon(var ResString : String; SetResNumFile : String; ResNumber : Integer); overload;
+ procedure AddIndividualAbon( ResNum : Integer ; option : Integer; SetResNumFile : String);
+ function CheckIndividualAbonList(ResNum : Integer) : Boolean;
+
+ procedure EditNGwords(); //NGword.txtðJB
+ function ShowAllTokens() : String; //fobOp
+ //--
+ procedure GoHome();//ListÌPsÚðÇÞ
+ function GoForward() : Boolean; //ListÌêÂÌNG[ht@CðÇÝÞ
+ function GoBack() : Boolean; //ListÌêÂOÌNG[ht@CðÇÝÞ
+ //--
+ function TreatSyria(AString: string): string;
//--
- procedure EditNGwords(); //NGword.txtðJB
- function ShowAllTokens() : String; //fobOp
+ function AddToken(AString: string; Invisible: Boolean): Boolean;
end;
var
- Abon1 :TAbon;
+ Abon1 :TAbon;
+const
+ NGwordListFileName : String = 'NGwords.list';
implementation
-constructor TAbon.Create;
+uses MojuUtils, GikoSystem, GikoBayesian, Setting;
+
+function InvidiAbonListSort( item1, item2 : Pointer ) : Integer;
begin
- // ú»
- FAbonString := ' <> <> <> <><>';
- FRetStrings := TStringList.Create;
- SetCutoffNum(0);
+
+ Result := TIndiviAbon( item1 ).Res - TIndiviAbon( item2 ).Res;
+
end;
-destructor TAbon.Destroy;
+destructor TIndiviAbonList.Destroy;
+var
+ i : Integer;
begin
- FRetStrings.Free;
- inherited;
+
+ for i := 0 to Count - 1 do
+ if inherited Items[ i ] <> nil then
+ TObject( inherited Items[ i ] ).Free;
+
+ inherited;
+
end;
+function TIndiviAbonList.GetItem( index : Integer ) : TIndiviAbon;
+begin
+
+ Result := TIndiviAbon( inherited Items[ index ] );
+
+end;
+
+procedure TIndiviAbonList.SetItem( index : Integer; value : TIndiviAbon );
+begin
+ inherited Items[ index ] := Pointer( value );
-//rootÍExeÌ¢étH_
+end;
+
+procedure TIndiviAbonList.Sort;
+begin
+
+ inherited Sort( InvidiAbonListSort );
+
+end;
+
+procedure TIndiviAbonList.LoadFromFile( const filePath : string );
+var
+ bufStringList : TStringList;
+ bufLine : string;
+ i : Integer;
+ item : TIndiviAbon;
+begin
+
+ if not FileExists( filePath ) then begin
+ FLearned := 0;
+ Exit;
+ end;
+
+ FFilePath := filePath;
+ bufStringList := TStringList.Create;
+ try
+ bufStringList.LoadFromFile( filePath );
+ if bufStringList.Values[ 'Learned' ] <> '' then begin
+ FLearned := StrToInt( bufStringList.Values[ 'Learned' ] );
+ bufStringList.Delete( bufStringList.IndexOfName( 'Learned' ) );
+ end else begin
+ FLearned := 0;
+ end;
+
+ //ósí
+ for i := bufStringList.Count-1 downto 0 do begin
+ if bufStringList.Strings[i] = '' then begin
+ bufStringList.Delete(i);
+ end;
+ end;
+
+ //ãü
+ for i := 0 to bufStringList.Count - 1 do begin
+ bufLine := Trim(bufStringList.Strings[i]);
+ item := TIndiviAbon.Create;
+ item.Res := StrToInt(Copy(bufLine,1,AnsiPos('-',bufLine)-1));
+ item.option := StrToInt(Copy(bufLine,AnsiPos('-',bufLine)+1,1));
+ Add( item );
+ end;
+ finally
+ bufStringList.Free;
+ end;
+
+end;
+
+procedure TIndiviAbonList.Save;
+var
+ bufStringList : TStringList;
+ i : Integer;
+begin
+
+ bufStringList := TStringList.Create;
+ try
+ bufStringList.Values[ 'Learned' ] := IntToStr( FLearned );
+
+ for i := 0 to Count - 1 do begin
+ bufStringList.Add(
+ IntToStr( Items[ i ].Res ) + '-' + IntToStr( Items[ i ].Option ) );
+ end;
+
+ bufStringList.SaveToFile( FFilePath );
+ finally
+ bufStringList.Free;
+ end;
+
+end;
+
+constructor TAbon.Create;
+begin
+ // ú»
+ FAbonString := ' <> <> <> <><>';
+ FAbonRes := TIndiviAbonList.Create;
+ FpAbons := PChar(FAbonString);
+ FpAbone := FpAbons + Length(FAbonString);
+
+end;
+
+destructor TAbon.Destroy;
+begin
+ FAbonRes.Free;
+ inherited;
+end;
+//rootÍExe\config\NGwordstH_
procedure TAbon.Setroot(root :String);
+var
+ bufStringList : TStringList;
begin
- Froot := root;
+ bufStringList := TStringList.Create;
+ try
+ if not DirectoryExists(root) then begin
+ CreateDir(root);
+ end;
+ if root[Length(root)] <> '\' then begin
+ root := root + '\';
+ end;
+ Flistpath := root + NGwordListFileName;
+ LoadListFile(Flistpath, bufStringList);
+ finally
+ bufStringList.Free;
+ end;
+ Froot := root;
end;
function TAbon.Getroot() : String;
begin
- Result := Froot;
+ Result := Froot;
end;
//NGwordpathÍNGword.txtÌtpX
procedure TAbon.SetNGwordpath(path :String);
begin
- FNGwordpath := path;
- LoadFromNGwordFile(FNGwordpath);
+ FNGwordpath := Getfullpath(path);
+ LoadFromNGwordFile(FNGwordpath);
end;
function TAbon.GetNGwordpath() : String;
begin
- Result := FNGwordpath;
+ Result := FNGwordpath;
+end;
+//tpXÅȯêÎtpXɵÄÔ·B
+function TAbon.Getfullpath(argpath : String) : String;
+begin
+ if AnsiPos(':\',argpath) <> 2 then begin //hCu©çÌtpXª³¯êÎ
+ if Getroot() = '' then begin
+ Result := ''; //rootpXªÝè³êÄÈ¢©óÉ·é
+ end else begin
+ if (Froot[Length(Froot)] = '\') and (argpath[1] = '\') then begin //æªÌ\ðí
+ Delete(argpath,1,1);
+ end;
+ Insert( Getroot(), argpath , 1);//rootpXð}ü
+ Result := argpath;
+ end;
+ end else begin
+ Result := argpath;
+ end;
+
end;
//NGwordt@CÌÇÝÝ
function TAbon.LoadFromNGwordFile(path :String) : boolean;
var
- bufstl : TStringList;
- i : integer;
+ bufstl : TStringList;
begin
- if AnsiPos(':\',path) <> 2 then begin //hCu©çÌtpXª³¯êÎ
- if Getroot() = '' then begin
- Result := false; //rootpXªÝè³êÄÈ¢©çfalse
- Exit;
- end else begin
- if (Froot[Length(Froot)] = '\') and (path[1] = '\') then begin //æªÌ\ðí
- Delete(path,1,1);
- end;
- Insert( Getroot(), path , 1);//rootpXð}ü
- end;
- end;
- bufstl := TStringList.Create;
- try
- bufstl.LoadFromFile(path);
- SetLength(Ftokens,bufstl.Count);
- for i := 0 to bufstl.Count -1 do begin
- SetTokens(i , bufstl.Strings[i]);
- end;
+ path := Getfullpath(path);
+ if path = '' then begin
+ Result := false;
+ end else begin
+
+ bufstl := TStringList.Create;
+ try
+ if not FileExists(path) then begin
+ Result := false;
+ try
+ bufstl.SaveToFile(path);
+ except
+ end;
+ end else begin
+ bufstl.LoadFromFile(path);
+ LoadFromStringList( bufstl );
+ Result := true;
+ end;
+ finally
+ bufstl.Free;
+ end;
+ end;
- except
- bufstl.Free;
- Result := false;
- Exit;
- end;
- bufstl.Free;
- Result := true;
+end;
+//NGwordXgÇÝÝ
+procedure TAbon.LoadFromStringList( bufstl : TStringList );
+var
+ i : integer;
+begin
+ try
+ for i := bufstl.Count -1 downto 0 do begin
+ if bufstl.Strings[i] = '' then begin
+ bufstl.Delete(i);
+ end;
+ end;
+ SetLength(Ftokens,bufstl.Count);
+ for i := 0 to bufstl.Count -1 do begin
+ SetTokens(i , bufstl.Strings[i]);
+ end;
+
+ except
+ Exit;
+ end;
end;
//NGwordpathªùÉÝè³êÄ¢éÆ«Ì[hpÖ
function TAbon.ReLoadFromNGwordFile() : boolean;
begin
- if GetNGwordpath() ='' then begin
- Result := false;
- end else begin
- Result := LoadFromNGwordFile( GetNGwordpath() );
- end;
+ if GetNGwordpath() ='' then begin
+ Result := false;
+ end else begin
+ Result := LoadFromNGwordFile( GetNGwordpath() );
+ end;
end;
-
-//êsÌÌg[NðØ誯ÄZbg
-procedure TAbon.SetTokens(index: integer ; argline : String);
-var
- ret : Integer;
- bufstl : TStringList;
- i : Integer;
-begin
- bufstl := TStringList.Create;
- bufstl.Delimiter := #9; //æØèqðf^ufÉÝè
- bufstl.DelimitedText := argline;
- ret := bufstl.Count;
- SetLength(Ftokens[index],ret);
- for i := 0 to bufstl.Count - 1 do begin
- Ftokens[index][i] := bufstl.Strings[i];
- end;
- bufstl.Free;
-
+function TAbon.Getlistpath() : String;
+begin
+ Result := Flistpath;
end;
-procedure TAbon.SetCutoffNum(value : Integer);
+procedure TAbon.Setlistpath(const Value : String);
begin
- if value > 2 then begin
- FCutoffNum := value;
- end else begin
- FCutoffNum := 0;
- end;
+ Flistpath := Getfullpath(Value);
end;
-function TAbon.GetCutoffNum() : Integer;
+//êsÌÌg[NðØ誯ÄZbg
+procedure TAbon.SetTokens(index: integer ; argline : String);
+var
+ ret : Integer;
+ bufstl : TStringList;
+ i : Integer;
+ pos : Integer;
+ buftoken : String;
begin
- Result := FCutoffNum;
+ bufstl := TStringList.Create;
+ try
+ if Length(argline) > 0 then begin
+ pos := AnsiPos(#9,argline);
+ while pos <> 0 DO begin
+ buftoken := Copy(argline,1,pos-1);
+ Delete(argline,1,pos);
+ if Length(buftoken) > 0 then begin
+ // >> ÅnÜég[NÍRgµ¢Å³·é
+ if AnsiPos('>>', buftoken) <> 1 then begin
+ bufstl.Append(buftoken);
+ end;
+ end else if ( bufstl.Count = 0 ) then begin
+ bufstl.Append('');
+ end;
+ pos := AnsiPos(#9,argline);
+ end;
+ if Length(argline) > 0 then begin
+ // >> ÅnÜég[NÍRgµ¢Å³·é
+ if AnsiPos('>>', argline) <> 1 then begin
+ bufstl.Append(argline);
+ end;
+ end;
+ ret := bufstl.Count;
+ SetLength(Ftokens[index],ret);
+ for i := 0 to bufstl.Count - 1 do begin
+ if IgnoreKana then
+ Ftokens[index][i] := ZenToHan(bufstl.Strings[i])
+ else
+ Ftokens[index][i] := bufstl.Strings[i];
+ end;
+ end;
+ finally
+ bufstl.Free;
+ end;
+
end;
+//Debugp¿áñÆNG[hðE¦Ä¢é©
function TAbon.ShowAllTokens() : String;
var
- i : Integer;
- j : Integer;
- ret : String;
+ i : Integer;
+ j : Integer;
+ ret : String;
begin
- for i := 0 to High(Ftokens) do begin
- for j := 0 to High(Ftokens[i]) do begin
- ret := ret + Ftokens[i][j];
- end;
- end;
- Result := ret;
+ for i := 0 to High(Ftokens) do begin
+ for j := 0 to High(Ftokens[i]) do begin
+ ret := ret + Ftokens[i][j];
+ end;
+ end;
+ Result := ret;
end;
-
-//****************************************************************************//
-//NG[hªÜÜêĽçtrueðÔ·B
-function TAbon.FindNGwords(line : String) : Boolean;
+//NG[hªÜÜêÄ¢½çtrueðÔµA»ÌNG[hÌsðNGwordsLineNumÉüêÄÔ·B
+//àµà§¾ Ú`ñÉ·éÈçInbisibleðtrueɵÄÔ·
+function TAbon.FindNGwords(const line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean; //1C¸ÂpB
var
- i : Integer;
- j : Integer;
- hit : Boolean;
-begin
- hit := false;
- if AnsiPos(FAbonString,line) <> 1 then begin
- for i := 0 to High(Ftokens) do begin
- hit := true;
- for j := 0 to High(Ftokens[i]) do begin
- if AnsiPos(Ftokens[i][j],line) = 0 then begin
- hit := false;
- break;
- end;
- end;
- if hit = true then begin
- break;
+ lines : Integer;
+ cells : Integer;
+ hit : Boolean;
+ bufline : String;
+ start : Integer;
+ target : String;
+ pos : PChar;
+ pts, pte : PChar;
+ trgLen : Integer;
+begin
+ hit := false;
+ if AnsiStrPosEx(PChar(line), PChar(line)+Length(line), FpAbons, FpAbone) = nil then begin
+ //S¼pÐçJi³·é©
+ if IgnoreKana then
+ target := ZenToHan(line)
+ else
+ target := line;
+
+ trgLen := Length(target);
+
+ for lines := 0 to High(Ftokens) do begin
+ if Length(Ftokens[lines]) = 0 then begin
+ Continue;
end;
- end;
- end;
- Result := hit;
-
+ hit := true;
+ bufline := target;
+ pts := PChar(bufline);
+ pte := pts + trgLen;
+
+ if Ftokens[lines][0] <> '' then begin
+ Invisible := false;
+ start := 0;
+ end else begin
+ Invisible := true;
+ start := 1;
+ end;
+
+ for cells := start to High(Ftokens[lines]) do begin
+ pos := AnsiStrPosEx(pts, pte,
+ PChar(Ftokens[lines][cells]), PChar(Ftokens[lines][cells]) + Length(Ftokens[lines][cells]));
+ if pos = nil then begin
+ hit := false;
+ break;
+ end else begin
+ Delete(bufline, pos - pte + 1, Length(Ftokens[lines][cells]));
+ pts := PChar(bufline);
+ pte := pts + Length(bufline);
+ end;
+ end;
+ if hit = true then begin
+ NGwordsLineNum := lines + 1;
+ break;
+ end;
+ end;
+ end;
+ Result := hit;
end;
-//CutOfflÈãÂ̯¶pªÀñÅ¢½ç Ú`ñ
-function TAbon.Cutoff(line : String) : String;
+//öÌu[lÍtrue¾ÆANG[hðÜÞà̾¯ðÔ·B
+procedure TAbon.Execute(var ThreadStrings : TStringList);
var
- i : Integer;
- sheed : AnsiChar;
- buf : String;
- ret : String;
-begin
- ret := line;
- if FCutoffNum <> 0 then begin
- for i := 65 to 90 do begin
- sheed := Chr(i);
- buf := DupeString(sheed, FCutoffNum);
- if AnsiContainsText(line, buf) = true then begin
- ret := FAbonString;
- break;
- end;
- end;
- end;
- Result := ret;
+ i : Integer;
+ NGwordsLine : Integer;
+ bufline : String;
+ invisi : Boolean;
+begin
+ for i:=0 to ThreadStrings.Count - 1 do begin
+ NGwordsLine := 0;
+ if FindNGwords(ThreadStrings.Strings[i], NGwordsLine ,invisi) <> Reverse then begin
+ if invisi = true then begin
+ ThreadStrings.Strings[i] := '';
+ end else begin
+ if not ReturnNGwordLineNum and not SetNGResAnchor then begin
+ ThreadStrings.Strings[i] := FAbonString;
+ end else if not ReturnNGwordLineNum then begin
+ ThreadStrings.Strings[i] := Format(' <> <> <>>%d<><>',[(i+1)]);
+ end else if not SetNGResAnchor then begin
+ ThreadStrings.Strings[i] := Format(' <> <> <> %d sÚÌNG[hªÜÜêĢܷB<><>',[NGwordsLine]);
+ end else begin
+ ThreadStrings.Strings[i] := Format(' <> <> <> %d sÚÌNG[hªÜÜêĢܷB>%d <><>',[NGwordsLine,(i+1)]);
+ end;
+ end;
+ end else begin
+ bufline := ThreadStrings.Strings[i];
+ if Deleterlo = true then begin
+ bufline := CustomStringReplace(bufline,'&rlo;','');
+ bufline := CustomStringReplace(bufline,'&lro;','');
+ end;
+ if Replaceul = true then begin
+ bufline := CustomStringReplace( bufline,'','
' );
+ bufline := CustomStringReplace( bufline,'
','
' );
+ end;
+ if DeleteSyria = true then
+ bufline := TreatSyria(bufline);
+ ThreadStrings.Strings[i] := bufline;
+ end;
+ end;
end;
-//öÌu[lÍtrue¾ÆANG[hðÜÞà̾¯ðÔ·B
-function TAbon.Execute(DestStrings : TStringList; deleterlo : Boolean; replaceul :Boolean ;reverse : Boolean) : TStringList;
+procedure TAbon.Execute(var ResString : String; ResNumber : Integer);
var
- i : Integer;
- bufline : String;
+ NGwordsLine : Integer;
+ bufline : String;
+ invisi : Boolean;
begin
- FRetStrings.Clear;
+ NGwordsLine := 0;
+ if FindNGwords(ResString, NGwordsLine ,invisi) <> Reverse then begin
+ if invisi = true then begin
+ ResString := '';
+ end else begin
+ if not ReturnNGwordLineNum and not SetNGResAnchor then begin
+ ResString := FAbonString;
+ end else if not ReturnNGwordLineNum then begin
+ ResString := Format(' <> <> <>>%d<><>',[(ResNumber)]);
+ end else if not SetNGResAnchor then begin
+ ResString := Format(' <> <> <> %d sÚÌNG[hªÜÜêĢܷB<><>',[NGwordsLine]);
+ end else begin
+ ResString := Format(' <> <> <> %d sÚÌNG[hªÜÜêĢܷB>%d <><>',[NGwordsLine,(ResNumber)]);
+ end;
+ end;
+ end else begin
+ bufline := ResString;
+ if Deleterlo = true then begin
+ bufline := CustomStringReplace( bufline,'&rlo;','' );
+ bufline := CustomStringReplace( bufline,'&lro;','' );
+ end;
+ if Replaceul = true then begin
+ bufline := CustomStringReplace( bufline,'','
' );
+ bufline := CustomStringReplace( bufline,'
','
' );
+ end;
+ if DeleteSyria = true then
+ bufline := TreatSyria(bufline);
+ ResString := bufline;
+ end;
+end;
- if reverse = false then begin
- for i:=0 to DestStrings.Count - 1 do begin
- if FindNGwords(DestStrings.Strings[i]) = true then begin
- FRetStrings.Append(FAbonString);
- end else begin
- bufline := DestStrings.Strings[i];
- if deleterlo = true then begin
- bufline := AnsiReplaceText( bufline,'&rlo;','' );
- end;
- if replaceul = true then begin
- bufline := AnsiReplaceText( bufline,'','
' );
- bufline := AnsiReplaceText( bufline,'
','
' );
- end;
- FRetStrings.Append(bufline);
- end;
- end;
- end else begin
- for i:=0 to DestStrings.Count - 1 do begin
- if FindNGwords(DestStrings.Strings[i]) = false then begin
- FRetStrings.Append(FAbonString);
- end else begin
- bufline := DestStrings.Strings[i];
- if deleterlo = true then begin
- while AnsiPos('&rlo',bufline) <> 0 do begin
- Delete(bufline,AnsiPos('&rlo',bufline),4);
- end;
- end;
- if replaceul = true then begin
- bufline := AnsiReplaceText( bufline,'','
' );
- bufline := AnsiReplaceText( bufline,'
','
' );
- end;
- FRetStrings.Append(bufline);
- end;
- end;
- end;
- Result := FRetStrings;
+//****************************************************************************//
+//»ÝZbg³êÄ¢éNGword.txtðJ
+procedure TAbon.EditNGwords();
+begin
+ ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
end;
-function TAbon.Execute(DestStrings : TStringList; NGwords : TStringList ; deleterlo : Boolean; replaceul :Boolean ; reverse : Boolean) : TStringList;
+//|bvAbvp»èÖ
+function TAbon.CheckAbonPopupRes(line : String) :Boolean;
var
- i : Integer;
+ i: Integer;
+ v: boolean;
begin
- SetLength(Ftokens,NGwords.Count);
- for i := 0 to NGwords.Count -1 do begin
- SetTokens(i , NGwords.Strings[i]);
- end;
- Result := Execute(DestStrings,deleterlo,replaceul,reverse);
-
+ if AbonPopupRes = true then begin
+ Result := FindNGwords(line, i ,v);
+ end else begin
+ Result := false;
+ end;
end;
-function TAbon.Execute(DestStrings : TStringList; NGwords : TStrings ; deleterlo : Boolean; replaceul :Boolean ;reverse : Boolean) : TStringList;
-var
- i : Integer;
- buf : TStringList;
-begin
- buf := TStringList.Create;
- buf.AddStrings(NGwords);
- SetLength(Ftokens,buf.Count);
- for i := 0 to buf.Count -1 do begin
- SetTokens(i , buf.Strings[i]);
+//¡ÌNG[heLXgðÇÝÞ==============================================
+//Listt@CðÇÝÞ
+function TAbon.LoadListFile(path :String; listStringList : TStringList) : Boolean;
+begin
+ try
+ listStringList.LoadFromFile(path);
+ Result := true;
+ except
+ listStringList.Append('êÊ=NGword.txt');
+ listStringList.SaveToFile(path);
+ Result := false;
end;
- Result := Execute(DestStrings,deleterlo,replaceul,reverse);
- buf.Free;
end;
-
-
-//****************************************************************************//
-//DATð¼É¢¶ézç===========================================================
-//NG[hðÜÞXÌæªÉ Ú[ñð}ü
-function TAbon.ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; //DATt@Cð¼É¢¶é
+//ListÌêÂÌNG[ht@CðÇÝÞ
+function TAbon.GoForward() : Boolean;
+begin
+ FNGwordFileIndex := FNGwordFileIndex + 1;
+ Result := ReadNGwordslist(FNGwordFileIndex);
+end;
+//ListÌêÂOÌNG[ht@CðÇÝÞ
+function TAbon.GoBack() : Boolean;
+begin
+ FNGwordFileIndex := FNGwordFileIndex -1;
+ Result := ReadNGwordslist(FNGwordFileIndex);
+end;
+//ListÌPsÚðÇÞ
+procedure TAbon.GoHome();
+begin
+ FNGwordFileIndex := 0;
+ ReadNGwordslist(FNGwordFileIndex);
+end;
+//ListÌlinesÚðÇÞ
+function TAbon.ReadNGwordslist(line : Integer) : Boolean;
var
- datstl : TStringList;
- ret : Boolean;
- i : Integer;
+ liststl : TStringList;
+ linebuf : String;
begin
- datstl := TStringList.Create;
- ret := true;
+ liststl := TStringList.Create;
try
- try
- datstl.LoadFromFile(datfilepath);
- for i := 0 to datstl.Count -1 do begin
- if FindNGwords(datstl.Strings[i]) = true then begin
- datstl.Strings[i] := FAbonString + datstl.Strings[i]
- end;
+ if LoadListFile(Flistpath,liststl) = true then begin
+ if line < 0 then begin
+ line := liststl.Count - 1;
+ FNGwordFileIndex := liststl.Count - 1;
+ end else if line > liststl.Count - 1 then begin
+ line := 0;
+ FNGwordFileIndex := 0;
end;
-
- datstl.SaveToFile(datfilepath);
- except
- ret := false;
- end;
+ linebuf := liststl.Strings[line];
+ FNGwordname := Copy(linebuf,1,AnsiPos('=',linebuf)-1);
+ Delete(linebuf,1,AnsiPos('=',linebuf));
+ SetNGwordpath(linebuf);
+ Result := true;
+ end else begin
+ Result := false;
+ end
finally
- datstl.Free;
+ liststl.Free;
end;
- Result := ret;
end;
-//wè³ê½XÔÌæªÉ Ú[ñ}ü
-function TAbon.ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DATt@Cð¼É¢¶é
+
+{$IFDEF SPAM_FILTER_ENABLED}
+procedure TAbon.Learn( resList : TStringList );
var
- datstl : TStringList;
- ret : Boolean;
+ i, j : Integer;
+ wordCount : TWordCount;
+ spamminess : Extended;
+ indiviAbon : TIndiviAbon;
+const
+ SPAM_THRESHOLD = 0.9;
begin
- ret := true;
- datstl := TStringList.Create;
- try
- try
- datstl.LoadFromFile(datfilepath);
- if (resnum > 0) and (resnum <= datstl.Count) then begin
- if AnsiPos(FAbonString, datstl.Strings[resnum-1]) <> 1 then begin
- datstl.Strings[resnum-1] := FAbonString + datstl.Strings[resnum-1];
- end;
- end;
- datstl.SaveToFile(datfilepath);
- except
- ret := false;
- end;
- finally
- datstl.Free;
- end;
- Result := ret;
+
+ if GikoSys.Setting.SpamFilterAlgorithm = gsfaNone then Exit;
+ j := 0;
+ wordCount := TWordCount.Create;
+ try
+ if (FAbonRes.FLearned = 0) and (FAbonRes.Count = 0) then begin
+ // ßÄÌwK©ÂÂÊ Ú`ñ èÈÌÅAver©çÌÚsÉ«
+ // ÂÊ Ú`ñðgÁ½wK
+ FAbonRes.Sort;
+ for i := 0 to FAbonRes.Count - 1 do begin
+ while (j < resList.Count) and (j + 1 < FAbonRes[ j ].Res) do begin
+ wordCount.Clear;
+ GikoSys.Bayesian.CountWord( resList[ j ], wordCount );
+ GikoSys.Bayesian.Learn( wordCount, False );
+ Inc( j );
+ end;
+ if j < resList.Count then begin
+ wordCount.Clear;
+ GikoSys.Bayesian.CountWord( resList[ j ], wordCount );
+ GikoSys.Bayesian.Learn( wordCount, True );
+ Inc( j );
+ end;
+ end;
+
+ while j < resList.Count do begin
+ wordCount.Clear;
+ GikoSys.Bayesian.CountWord( resList[ j ], wordCount );
+ GikoSys.Bayesian.Learn( wordCount, False );
+ Inc( j );
+ end;
+ end else begin
+ // ver©çÌÚsÅÍÈ¢ÌÅXðSÄ_ÅwK
+ // ¦_ªÔáÁÄ¢éêÍ[Uª Ú`ñðC³·éÅwK³êé
+ for j := FAbonRes.FLearned to resList.Count - 1 do begin
+ wordCount.Clear;
+ spamminess := GikoSys.SpamParse( resList[ j ], wordCount );
+ if spamminess >= SPAM_THRESHOLD then begin
+ // Xp
+ GikoSys.Bayesian.Learn( wordCount, True );
+ indiviAbon := TIndiviAbon.Create;
+ indiviAbon.Res := j + 1;
+ indiviAbon.Option := 1;
+ FAbonRes.Add( indiviAbon );
+ end else begin
+ // n
+ GikoSys.Bayesian.Learn( wordCount, False );
+ end;
+ end;
+ end;
+
+ FAbonRes.FLearned := resList.Count;
+ FAbonRes.Save;
+ finally
+ wordCount.Free;
+ end;
+
+ FAbonRes.Save;
+ GikoSys.Bayesian.Save;
+
end;
-//firstres©çcountÂÌXÌæªÉ Ú[ñ}ü
-function TAbon.ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; //DATt@Cð¼É¢¶é
+{$ENDIF}
+
+//¡ÌNG[heLXgðÇÝÞ=====±±ÜÅ=================================
+//ÂÊ Ú`ñÀsÖ
+procedure TAbon.IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String);
var
- datstl : TStringList;
- i : Integer;
- endnum : Integer; //IíèÌXÔ
- ret : Boolean;
+ i : Integer;
+ f : Boolean;
begin
- ret := true;
- datstl := TStringList.Create;
- try
- try
- datstl.LoadFromFile(datfilepath);
- if (firstres > 0) and (firstres <= datstl.Count) then begin
- if firstres + count -1 > datstl.Count then begin
- endnum := datstl.Count;
- end else if count <= 0 then begin
- endnum := firstres + 1;
- end else begin
- endnum := firstres + count -1;
- end;
-
- for i := firstres to endnum do begin
- if AnsiPos(FAbonString, datstl.Strings[i-1]) <> 1 then begin
- datstl.Strings[i-1] := FAbonString + datstl.Strings[i-1];
+ f := LoadFromSetResNumFile( SetResNumFile );
+ FAbonRes.FFilePath := SetResNumFile; // Learn ÍÅÛ¶·éÌÅ
+{$IFDEF SPAM_FILTER_ENABLED}
+ Learn( ThreadStrings );
+{$ENDIF}
+
+ if f then begin
+ for i := 0 to FAbonRes.Count - 1 do begin
+ if (FAbonRes[i].Res <= ThreadStrings.Count) and (FAbonRes[i].Res > 0) then begin
+{$IFDEF NO_ABON}
+ ThreadStrings.Strings[FAbonRes[i].Res-1] :=
+ ' Ú`ñÏÝ' +
+ ThreadStrings.Strings[FAbonRes[i].Res-1];
+{$ELSE}
+ if FAbonRes[i].option = 0 then begin
+ ThreadStrings.Strings[FAbonRes[i].Res-1] := '';
+ end else begin
+ ThreadStrings.Strings[FAbonRes[i].Res-1] := ' Ú`ñ<> Ú`ñ<> Ú`ñ<> Ú`ñ<>';
+ end;
+{$ENDIF}
+ end;
+ end;
+ end;
+end;
+procedure TAbon.IndividualAbon(var ResString : String; SetResNumFile : String; ResNumber : Integer);
+var
+ i : Integer;
+begin
+ if FileExists(SetResNumFile) = true then begin
+ if LoadFromSetResNumFile(SetResNumFile) = true then begin
+ for i := 0 to FAbonRes.Count - 1 do begin
+ if FAbonRes[i].Res = ResNumber then begin
+ if FAbonRes[i].option = 0 then begin
+ ResString := '';
+ end else begin
+ ResString := ' Ú`ñ<> Ú`ñ<> Ú`ñ<> Ú`ñ<>';
end;
- end;
+ Exit;
+ end;
end;
- datstl.SaveToFile(datfilepath);
- except
- ret := false;
end;
- finally
- datstl.Free;
- end;
- Result := ret;
+ end else begin
+ FIndividualFileName := SetResNumFile;
+ FAbonRes.Free;
+ FAbonRes := TIndiviAbonList.Create;
+ end;
end;
-//DATð¼É¢¶ézç==========±±ÜÅ=========================================
-//³Éß·zç==================================================================
-function TAbon.ReverseExecuteFile(datfilepath : String) : Boolean; //DATt@Cð¼É¢¶é
+//ÂÊ Ú`ñt@CÇÝÝÖ
+function TAbon.LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
+begin
+
+ FIndividualFileName := SetResNumFile;
+ FAbonRes.Free;
+ FAbonRes := TIndiviAbonList.Create;
+ if FileExists( SetResNumFile ) then begin
+ FAbonRes.LoadFromFile( SetResNumFile );
+ Result := true;
+ end else begin
+ Result := False;
+ end;
+
+end;
+//ÂÊ Ú`ñt@CÉÇÁ
+procedure TAbon.AddIndividualAbon( ResNum : Integer ; option : Integer; SetResNumFile : String);
var
- datstl : TStringList;
- i : Integer;
- buf : String;
- ret : Boolean;
+ IndividualFile : TStringList;
+ i, j : Integer;
begin
- ret := true;
- datstl := TStringList.Create;
- try
- try
- datstl.LoadFromFile(datfilepath);
- for i:=0 to datstl.Count -1 do begin
- if AnsiPos(FAbonString, datstl.Strings[i]) = 1 then begin
- buf := datstl.Strings[i];
- Delete(buf,1,Length(FAbonString));
- datstl.Strings[i] := buf;
- end;
- end;
- datstl.SaveToFile(datfilepath);
- except
- ret := false;
- end;
- finally
- datstl.Free;
- end;
- Result := ret;
+ IndividualFile := TStringList.Create;
+ try
+ if FileExists(SetResNumFile) then begin
+ IndividualFile.LoadFromFile(SetResNumFile);
+ i := -1;
+ for j := 0 to IndividualFile.Count -1 do begin
+ if AnsiPos(IntToStr(ResNum) + '-', IndividualFile[j]) = 1 then begin
+ i := j;
+ break;
+ end;
+ end;
+ if i = -1 then
+ IndividualFile.Add(IntToStr(ResNum) + '-' + IntToStr(option))
+ else
+ IndividualFile[j] := IntToStr(ResNum) + '-' + IntToStr(option);
+
+ end else begin
+ IndividualFile.Add(IntToStr(ResNum) + '-' + IntToStr(option));
+ end;
+ IndividualFile.SaveToFile(SetResNumFile);
+ finally
+ IndividualFile.Free;
+ end;
+end;
+
+//|bvAbvÌ»èp
+function TAbon.CheckIndividualAbonList(ResNum : Integer) : Boolean;
+var
+ i : Integer;
+begin
+ if (FAbonRes.Count > 0) and (FAbonRes[0].Res <> 0) then begin
+ for i := 0 to FAbonRes.Count - 1 do begin
+ if FAbonRes[i].Res = ResNum then begin
+ Result := true;
+ Exit;
+ end;
+ end;
+ end;
+ Result := false;
end;
-function TAbon.ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DATt@Cð¼É¢¶é
+//VAêuNÎô
+function TAbon.TreatSyria(AString: string): string;
+const
+ UNI_TAG = '';
var
- datstl : TStringList;
- buf : String;
- ret : Boolean;
+ //count: Integer; //(܀~ݏ)
+ ps : PChar;
+ p, pe, s, se : PChar;
+ scode: String;
+ icode: Integer;
begin
- ret := true;
- datstl := TStringList.Create;
- try
- try
- datstl.LoadFromFile(datfilepath);
- if (resnum > 0) and (resnum <= datstl.Count) then begin
- if AnsiPos(FAbonString, datstl.Strings[resnum-1]) = 1 then begin
- buf := datstl.Strings[resnum-1];
- Delete(buf,1,Length(FAbonString));
- datstl.Strings[resnum-1] := buf;
- end;
+
+ Result := '';
+
+ p := PChar(AString);
+ pe := p + Length(AString);
+ s := PChar(UNI_TAG);
+ se := s + Length(UNI_TAG);
+
+ p := AnsiStrPosEx(p, pe, s, se);
+
+ while p <> nil do begin
+ //ÌèOÜÅRs[·é
+ Result := Result + Copy(AString, 1, p - PChar(AString));
+ //ÌèOÜÅí·é
+ Delete(AString, 1, p - PChar(AString));
+
+ //AStringÉ3¶Èã êÎÌ3¶Úð`FbN
+ if Length(AString) > 2 then begin
+ ps := PChar(AString) + 2;
+ if (ps^ = 'x') or (ps^ = 'X') then begin
+ //16i\L
+ Inc(ps);
+ scode := '0x';
+ while ((ps^ >= '0') and (ps^ <= '9')) or
+ ((ps^ >= 'a') and (ps^ <= 'f')) or
+ ((ps^ >= 'A') and (ps^ <= 'F')) do begin
+
+ scode := scode + String(ps^);
+ Inc(ps);
+ end;
+ end else begin
+ //10i\L
+ scode := '';
+ while ((ps^ >= '0') and (ps^ <= '9')) do begin
+ scode := scode + String(ps^);
+ Inc(ps);
+ end;
+ end;
+ icode := StrToIntDef(scode, 0);
+
+ //Åãª;ŶĢȯêÎAê¶OÜÅÉ·é
+ if not (ps^ = ';') then
+ Dec(ps);
+
+ //VAêuNÌÅÈ¢
+ if ( icode < 1758) or
+ ((icode > 1871) and (icode < 1958)) or
+ (icode > 1968) then begin
+ Result := Result + Copy(AString, 1, ps - PChar(AString) + 1);
end;
- datstl.SaveToFile(datfilepath);
- except
- ret := false;
- end;
- finally
- datstl.Free;
- end;
- Result := ret;
+ Delete(AString, 1, ps - PChar(AString) + 1);
+ end else begin
+ //ãëɶª³¢ÌÅA»ÌÜÜResultÉËÁÞ
+ Result := Result + AString;
+ AString := '';
+ end;
+ p := PChar(AString);
+ pe := p + Length(AString);
+ p := AnsiStrPosEx(p, pe, s, se);
+ end;
+
+ //cÁ½¶ñð«µÄÊÉ·é
+ Result := Result + AString;
end;
-function TAbon.ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean;//DATt@Cð¼É¢¶é
+
+// NG[ht@CÉÇÁ ÇÁ³ê½êATrueª©¦é
+function TAbon.AddToken(AString: string; Invisible: Boolean): Boolean;
var
- datstl : TStringList;
- i : Integer;
- endnum : Integer; //IíèÌXÔ
- buf : String;
- ret : Boolean;
-begin
- ret := true;
- datstl := TStringList.Create;
- try
+ bufStringList : TStringList;
+ ngword: String;
+begin
+ Result := False;
+ if FileExists(GetNGwordpath) then begin
+ bufStringList := TStringList.Create;
try
- datstl.LoadFromFile(datfilepath);
- if (firstres > 0) and (firstres <= datstl.Count) then begin
- if firstres + count -1 > datstl.Count then begin
- endnum := datstl.Count;
- end else if count <= 0 then begin
- endnum := firstres + 1;
- end else begin
- endnum := firstres + count -1;
- end;
- for i := firstres to endnum do begin
- if AnsiPos(FAbonString, datstl.Strings[i-1]) = 1 then begin
- buf := datstl.Strings[i-1];
- Delete(buf,1,Length(FAbonString));
- datstl.Strings[i-1] := buf;
- end;
- end;
+ bufStringList.LoadFromFile(GetNGwordpath);
+ if (Invisible) then begin
+ ngword := #9 + AString;
+ end else begin
+ ngword := AString;
+ end;
+ if (bufStringList.IndexOf(ngword) = -1) then begin
+ bufStringList.Add(ngword);
+ bufStringList.SaveToFile(GetNGwordpath);
+ Result := True;
end;
- datstl.SaveToFile(datfilepath);
- except
- ret := false;
+ finally
+ bufStringList.Free;
end;
- finally
- datstl.Free;
end;
- Result := ret;
-end;
-//³Éß·zç=================±±ÜÅ=========================================
-//»ÝZbg³êÄ¢éNGword.txtðJ
-procedure TAbon.EditNGwords();
-begin
- ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
end;
-
end.