X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=AbonUnit.pas;h=7ed49585b7655987e7486bd5fa77d7adb8b3552f;hb=4e996b06dc4616d8c9bd469d5fec93cef695cd98;hp=3925ee37a61150146731d8068acd2f77d9be316c;hpb=cd03959a483d10653e7160654c3e871ca607b0c3;p=gikonavigoeson%2Fgikonavi.git
diff --git a/AbonUnit.pas b/AbonUnit.pas
index 3925ee3..7ed4958 100644
--- a/AbonUnit.pas
+++ b/AbonUnit.pas
@@ -1,3 +1,8 @@
+{
+NO_ABON Ú[ñÏÝÌXà\¦·é(²³êé)
+SPAM_FILTER_ENABLED XptB^ð@\³¹é
+}
+
unit AbonUnit;
interface
@@ -5,83 +10,100 @@ uses
Windows,Messages, ShellAPI, SysUtils, Classes,StdCtrls,StrUtils;
type
- TIndiviAbon = record
- Res: Integer;
- option: Integer; // 0:§¾ 1:Êí Ú[ñ
- end;
+ 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;
- Flistpath : String;
- FNGwordpath : String;
- Ftokens : array of array of string;
- FAbonRes : array of TIndiviAbon;
- FAbonString : String;
-// FCutoffNum : Integer; //±ÌÈãA±·é¯¶pðNG[hÆ·é
- FDeleterlo : Boolean; //&rlo;ðíé© //ÇÁ&lro;àíé
- FReplaceul :Boolean ; //
^Oð
^OÉu··é©
- FReverse : Boolean ; //NG[hÅÌ Ú`ñÌÊð½]³¹é©
- FAbonPopupRes : Boolean; //X|bvAbvÌÉ Ú[ñ·é©
- FCreateNGwordFile : Boolean; //wè³ê½pathÉNG[htxtª³©Á½Æ«É©®Iɶ¬·é©
- 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
- 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;
+ { 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^
- 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 CreateNGwordFile: Boolean read FCreateNGwordFile write FCreateNGwordFile;
- 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;
+ { 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;
- 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;
+ 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
- function FindNGwordsEx(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 ThreadStrings : TStringList; NGwords : TStringList); overload;
- procedure Execute(var ThreadStrings : TStringList; NGwords : TStrings); overload;
procedure Execute(var ResString : String; ResNumber : Integer); overload; //åÉplugin©çÌDat To HTML p
- procedure ExecuteEx(var ThreadStrings : TStringList); overload;
- procedure ExecuteEx(var ThreadStrings : TStringList; NGwords : TStringList); overload;
- procedure ExecuteEx(var ThreadStrings : TStringList; NGwords : TStrings); overload;
- procedure ExecuteEx(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);
- procedure DeleteIndividualAbon( ResNum : Integer);
- function GetAbonResCount() : Integer;
- function GetAbonResString(Num : Integer) : String;
+ procedure AddIndividualAbon( ResNum : Integer ; option : Integer; SetResNumFile : String);
function CheckIndividualAbonList(ResNum : Integer) : Boolean;
procedure EditNGwords(); //NGword.txtðJB
@@ -92,6 +114,8 @@ type
function GoBack() : Boolean; //ListÌêÂOÌNG[ht@CðÇÝÞ
//--
function TreatSyria(AString: string): string;
+ //--
+ function AddToken(AString: string; Invisible: Boolean): Boolean;
end;
var
Abon1 :TAbon;
@@ -100,21 +124,129 @@ const
implementation
-uses MojuUtils;
+uses MojuUtils, GikoSystem, GikoBayesian, Setting;
+
+function InvidiAbonListSort( item1, item2 : Pointer ) : Integer;
+begin
+
+ Result := TIndiviAbon( item1 ).Res - TIndiviAbon( item2 ).Res;
+
+end;
+
+destructor TIndiviAbonList.Destroy;
+var
+ i : Integer;
+begin
+
+ 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 );
+
+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 := ' <> <> <> <><>';
- FCreateNGwordFile := true;
- SetLength(FAbonRes,1);
- FAbonRes[0].Res := 0;
- FAbonRes[0].option := -1;
+ FAbonRes := TIndiviAbonList.Create;
+ FpAbons := PChar(FAbonString);
+ FpAbone := FpAbons + Length(FAbonString);
end;
destructor TAbon.Destroy;
begin
+ FAbonRes.Free;
inherited;
end;
//rootÍExe\config\NGwordstH_
@@ -178,17 +310,19 @@ begin
if path = '' then begin
Result := false;
end else begin
+
bufstl := TStringList.Create;
try
- 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;
- except
- if CreateNGwordFile = true then begin
- bufstl.SaveToFile(path);
- end;
- Result := false;
end;
finally
bufstl.Free;
@@ -242,7 +376,6 @@ var
pos : Integer;
buftoken : String;
begin
- pos := 0;
bufstl := TStringList.Create;
try
if Length(argline) > 0 then begin
@@ -251,19 +384,28 @@ begin
buftoken := Copy(argline,1,pos-1);
Delete(argline,1,pos);
if Length(buftoken) > 0 then begin
- bufstl.Append(buftoken);
+ // >> Å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
- bufstl.Append(argline);
+ // >> Å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
- Ftokens[index][i] := bufstl.Strings[i];
+ if IgnoreKana then
+ Ftokens[index][i] := ZenToHan(bufstl.Strings[i])
+ else
+ Ftokens[index][i] := bufstl.Strings[i];
end;
end;
finally
@@ -297,52 +439,30 @@ var
hit : Boolean;
bufline : String;
start : Integer;
+ target : String;
+ pos : PChar;
+ pts, pte : PChar;
+ trgLen : Integer;
begin
hit := false;
- if AnsiPos(FAbonString,line) <> 1 then begin
- for lines := 0 to High(Ftokens) do begin
- hit := true;
- bufline := line;
- if Ftokens[lines][0] <> '' then begin
- Invisible := false;
- start := 0;
- end else begin
- Invisible := true;
- start := 1;
- end;
+ 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 cells := start to High(Ftokens[lines]) do begin
- if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
- hit := false;
- break;
- end else begin
- Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
- end;
- end;
- if hit = true then begin
- NGwordsLineNum := lines + 1;
- break;
- end;
- end;
- end;
- Result := hit;
-end;
-//NG[hªÜÜêÄ¢½çtrueðÔµA»ÌNG[hÌsðNGwordsLineNumÉüêÄÔ·B
-//àµà§¾ Ú`ñÉ·éÈçInbisibleðtrueɵÄÔ·
-//¼pSp³
-function TAbon.FindNGwordsEx(const line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean;//1C¸ÂpB
-var
- lines : Integer;
- cells : Integer;
- hit : Boolean;
- bufline : String;
- start : Integer;
-begin
- hit := false;
- if AnsiPos(FAbonString,line) <> 1 then begin
for lines := 0 to High(Ftokens) do begin
+ if Length(Ftokens[lines]) = 0 then begin
+ Continue;
+ end;
hit := true;
- bufline := line;
+ bufline := target;
+ pts := PChar(bufline);
+ pte := pts + trgLen;
+
if Ftokens[lines][0] <> '' then begin
Invisible := false;
start := 0;
@@ -352,11 +472,15 @@ begin
end;
for cells := start to High(Ftokens[lines]) do begin
- if VaguePos(Ftokens[lines][cells],bufline) = 0 then 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, VaguePos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
+ Delete(bufline, pos - pte + 1, Length(Ftokens[lines][cells]));
+ pts := PChar(bufline);
+ pte := pts + Length(bufline);
end;
end;
if hit = true then begin
@@ -444,134 +568,7 @@ begin
end;
end;
-procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStringList);
-var
- i : Integer;
-begin
- SetLength(Ftokens,NGwords.Count);
- for i := 0 to NGwords.Count -1 do begin
- SetTokens(i , NGwords.Strings[i]);
- end;
- Execute(ThreadStrings);
-end;
-procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStrings);
-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]);
- end;
- Execute(ThreadStrings);
- buf.Free;
-end;
-
-//öÌu[lÍtrue¾ÆANG[hðÜÞà̾¯ðÔ·B
-procedure TAbon.ExecuteEx(var ThreadStrings : TStringList);
-var
- i : Integer;
- NGwordsLine : Integer;
- bufline : String;
- invisi : Boolean;
-begin
- for i:=0 to ThreadStrings.Count - 1 do begin
- NGwordsLine := 0;
- if FindNGwordsEx(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;
-procedure TAbon.ExecuteEx(var ResString : String; ResNumber : Integer);
-var
- NGwordsLine : Integer;
- bufline : String;
- invisi : Boolean;
-begin
- NGwordsLine := 0;
- if FindNGwordsEx(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;
-
-procedure TAbon.ExecuteEx(var ThreadStrings : TStringList; NGwords : TStringList);
-var
- i : Integer;
-begin
- SetLength(Ftokens,NGwords.Count);
- for i := 0 to NGwords.Count -1 do begin
- SetTokens(i , NGwords.Strings[i]);
- end;
- ExecuteEx(ThreadStrings);
-
-end;
-procedure TAbon.ExecuteEx(var ThreadStrings : TStringList; NGwords : TStrings);
-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]);
- end;
- ExecuteEx(ThreadStrings);
- buf.Free;
-end;
//****************************************************************************//
//»ÝZbg³êÄ¢éNGword.txtðJ
@@ -651,31 +648,109 @@ begin
end;
end;
+
+{$IFDEF SPAM_FILTER_ENABLED}
+procedure TAbon.Learn( resList : TStringList );
+var
+ i, j : Integer;
+ wordCount : TWordCount;
+ spamminess : Extended;
+ indiviAbon : TIndiviAbon;
+const
+ SPAM_THRESHOLD = 0.9;
+begin
+
+ 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;
+{$ENDIF}
+
//¡ÌNG[heLXgðÇÝÞ=====±±ÜÅ=================================
//ÂÊ Ú`ñÀsÖ
procedure TAbon.IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String);
var
i : Integer;
-begin
- if FileExists(SetResNumFile) = true then begin
- if LoadFromSetResNumFile(SetResNumFile) = true then begin
- for i := 0 to High(FAbonRes) do begin
- if (FAbonRes[i].Res <= ThreadStrings.Count) and (FAbonRes[i].Res > 0) then begin
- if FAbonRes[i].option = 0 then begin
- ThreadStrings.Strings[FAbonRes[i].Res-1] := '';
- end else begin
- ThreadStrings.Strings[FAbonRes[i].Res-1] := ' Ú`ñ<> Ú`ñ<> Ú`ñ<> Ú`ñ<>';
- end;
- end;
-
- end;
- end;
- end else begin
- FIndividualFileName := SetResNumFile;
- SetLength(FAbonRes,1);
- FAbonRes[0].Res := 0;
- FAbonRes[0].option := -1;
- end;
+ f : Boolean;
+begin
+ 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
@@ -683,7 +758,7 @@ var
begin
if FileExists(SetResNumFile) = true then begin
if LoadFromSetResNumFile(SetResNumFile) = true then begin
- for i := 0 to High(FAbonRes) do 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 := '';
@@ -695,187 +770,178 @@ begin
end;
end;
end else begin
- FIndividualFileName := SetResNumFile;
- SetLength(FAbonRes,1);
- FAbonRes[0].Res := 0;
- FAbonRes[0].option := -1;
- end;
+ FIndividualFileName := SetResNumFile;
+ FAbonRes.Free;
+ FAbonRes := TIndiviAbonList.Create;
+ end;
end;
//ÂÊ Ú`ñt@CÇÝÝÖ
function TAbon.LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
-var
- bufStringList : TStringList;
- bufLine : String;
- i : Integer;
begin
- bufStringList := TStringList.Create;
- try
- try
- bufStringList.LoadFromFile(SetResNumFile);
- FIndividualFileName := SetResNumFile;
- //ósí
- for i := bufStringList.Count-1 downto 0 do begin
- if bufStringList.Strings[i] = '' then begin
- bufStringList.Delete(i);
- end;
- end;
-
- //mÛ
- SetLength(FAbonRes,bufStringList.Count);
- //ãü
- for i :=0 to bufStringList.Count - 1 do begin
- bufLine := Trim(bufStringList.Strings[i]);
- FAbonRes[i].Res := StrToInt(Copy(bufLine,1,AnsiPos('-',bufLine)-1));
- FAbonRes[i].option := StrToInt(Copy(bufLine,AnsiPos('-',bufLine)+1,1));
- end;
- except
- Result := false;
- Exit;
- end;
- finally
- bufStringList.Free;
- end;
- Result := true;
+
+ 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);
-var
- IndividualFile : TStringList;
- linebuf : String;
- i : Integer;
-begin
- IndividualFile := TStringList.Create;
- if FAbonRes[0].Res <> 0 then begin
- for i := 0 to High(FAbonRes) do begin
- if FAbonRes[i].Res <> ResNum then begin
- linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
- IndividualFile.Append(linebuf);
- end;
- end;
- end;
- linebuf := IntToStr(ResNum) + '-' + IntToStr(option);
- IndividualFile.Append(linebuf);
- try
- IndividualFile.SaveToFile(FIndividualFileName);
- finally
- IndividualFile.Free;
- end;
-end;
-//ÂÊ Ú`ñt@C©çí
-procedure TAbon.DeleteIndividualAbon( ResNum : Integer);
+procedure TAbon.AddIndividualAbon( ResNum : Integer ; option : Integer; SetResNumFile : String);
var
IndividualFile : TStringList;
- linebuf : String;
- i : Integer;
-begin
- IndividualFile := TStringList.Create;
- if FAbonRes[0].Res <> 0 then begin
- for i := 0 to High(FAbonRes) do begin
- if FAbonRes[i].Res <> ResNum then begin
- linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
- IndividualFile.Append(linebuf);
- end;
- end;
- end;
- if IndividualFile.Count <> 0 then begin
- try
- IndividualFile.SaveToFile(FIndividualFileName);
- finally
- IndividualFile.Free;
- end;
- end else begin
- if FileExists(FIndividualFileName) = true then begin
- DeleteFile(FIndividualFileName);
- end;
- end;
-end;
-//ÂÊ Ú`ñÌXgÌÂðÔ·
-function TAbon.GetAbonResCount() : Integer;
-var
- i : Integer;
-begin
- if FAbonRes[0].Res = 0 then begin
- Result := 0
- end else begin
- i := High(FAbonRes);
- Result := i+1;
- end;
-end;
-//ÂÊ Ú`ñÌXgÌsÚÌXð¶ñÅÔ·
-function TAbon.GetAbonResString(Num : Integer) : String;
+ i, j : Integer;
begin
- if (Num <= High(FAbonRes)) and (Num >= 0) then begin
- Result := IntToStr(FAbonRes[Num].Res);
- end else begin
- Result := '';
- end;
+ 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[0].Res <> 0 then begin
- for i := 0 to High(FAbonRes) do begin
- if FAbonRes[i].Res = ResNum then begin
- Result := true;
- Exit;
- end;
- end;
- end;
- Result := false;
+ 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;
//VAêuNÎô
function TAbon.TreatSyria(AString: string): string;
+const
+ UNI_TAG = '';
var
//count: Integer; //(܀~ݏ)
- pos: Integer;
- tmp: string;
-begin
- pos := AnsiPos('', AString);
- while pos <> 0 do begin
- if AString[pos+6] = ';' then begin
- if StrToIntDef(Copy(AString, pos+4, 2), 0) <= 71 then begin
- tmp := tmp + Copy(AString, 1, pos - 1);
- Delete(AString, 1, pos+6);
- end else begin
- tmp := tmp + Copy(AString, 1, pos + 6);
- Delete(AString, 1, pos+6);
+ ps : PChar;
+ p, pe, s, se : PChar;
+ scode: String;
+ icode: Integer;
+begin
+
+ 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;
- end else begin
- tmp := tmp + Copy(AString, 1, pos + 3);
- Delete(AString, 1, pos+3);
- end;
- pos := AnsiPos('', AString);
- end;
- if Length(AString) > 0 then
- tmp := tmp + AString;
- AString := tmp;
- tmp := '';
-
- pos := AnsiPos('³', AString);
- while pos <> 0 do begin
- if AString[pos+6] = ';' then begin
- if StrToIntDef(Copy(AString, pos+5, 1), 0) > 2 then begin
- tmp := tmp + Copy(AString, 1, pos - 1);
- Delete(AString, 1, pos+6);
+
+ 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;
+
+// NG[ht@CÉÇÁ ÇÁ³ê½êATrueª©¦é
+function TAbon.AddToken(AString: string; Invisible: Boolean): Boolean;
+var
+ bufStringList : TStringList;
+ ngword: String;
+begin
+ Result := False;
+ if FileExists(GetNGwordpath) then begin
+ bufStringList := TStringList.Create;
+ try
+ bufStringList.LoadFromFile(GetNGwordpath);
+ if (Invisible) then begin
+ ngword := #9 + AString;
end else begin
- tmp := tmp + Copy(AString, 1, pos + 6);
- Delete(AString, 1, pos+6);
+ ngword := AString;
end;
- tmp := tmp + Copy(AString, 1, pos - 1);
- Delete(AString, 1, pos+6);
- end else begin
- tmp := tmp + Copy(AString, 1, pos + 4);
- Delete(AString, 1, pos+4);
+ if (bufStringList.IndexOf(ngword) = -1) then begin
+ bufStringList.Add(ngword);
+ bufStringList.SaveToFile(GetNGwordpath);
+ Result := True;
+ end;
+ finally
+ bufStringList.Free;
end;
- pos := AnsiPos('³', AString);
end;
- if Length(AString) > 0 then
- tmp := tmp + AString;
- Result := tmp;
end;
+
+
end.