5 Windows,Messages, ShellAPI, SysUtils, Classes,StdCtrls,StrUtils,
6 GikoXMLDoc, GikoSystem, bmRegExp;
9 //
\83\8a\83X
\83g
\82Ì
\95\
\8e¦
\83A
\83C
\83e
\83\80\91I
\91ð
10 TGikoNGType = (gntAll, gntName, gntMail, gntDateId, gntBody);
13 NG
\83\8f\81[
\83h
\83N
\83\89\83X
15 TNGWord = class( TObject )
18 FNGType : TGikoNGType;
21 procedure ReadXMLElement(element :IXMLNode);
22 function ToXMLString(): String;
23 property Rank : Integer read FRank write FRank;
24 property NGType : TGikoNGType read FNGType write FNGType;
25 property Word : String read FWord write FWord;
29 NG
\83\8f\81[
\83h
\8fW
\8d\87\83N
\83\89\83X
31 TNGWords = class( TList )
39 property Rank : Integer read FRank write FRank;
40 property Invisible : Boolean read FInvisible write FInvisible;
41 function ReadXMLElement(element :IXMLNode): Boolean;
42 function ToXMLString(): String;
43 function ToString(): String;
44 procedure Delete(word: TNGWord); overload;
45 function IsNG(PRes : PResRec): Boolean;
49 NG
\83\8f\81[
\83h
\8aÇ
\97\9d\83N
\83\89\83X
51 TNGWordList = class( TList )
55 procedure LoadFromFile(fileName: String);
56 procedure SaveToFrile(fileName: String);
57 procedure Delte(NGWords: TNGWords); overload;
58 function IsNG(PRes : PResRec): Integer;
61 function CompareRank(Item1, Item2: Pointer): Integer;
63 NGWordList: TNGWordList;
70 function CompareRank(Item1, Item2: Pointer): Integer;
72 if TObject(item1) is TNGWords then begin
74 TNGWords(Item1).Rank, TNGWords(Item2).Rank);
77 TNGWord(Item1).Rank, TNGWord(Item2).Rank);
80 constructor TNGWords.Create;
83 FAWKStr := TAWKStr.Create(nil);
85 procedure TNGWords.Free;
89 for i := 0 to Count - 1 do begin
90 TObject(Items[i]).Free;
95 function TNGWords.ReadXMLElement(element :IXMLNode): Boolean;
102 if element.NodeName = 'NGWords' then begin
103 Rank := StrToIntDef(element.Attributes['rank'],
105 Invisible := StrToBoolDef(element.Attributes['invisible'],
107 bound := element.ChildNodes.Count - 1;
108 for i := 0 to bound do begin
109 NGWordNode := element.ChildNodes[i];
110 if NGWordNode.NodeName = 'NGWord' then begin
111 NG := TNGWord.Create;
112 NG.ReadXMLElement( NGWordNode );
120 function TNGWords.ToXMLString(): String;
124 Result := '<NGWords ' +
125 'rank="' + IntToStr(FRank) + '" ' +
126 'invisible="' + BoolToStr(Invisible) + '" >'#13#10;
127 for i := 0 to Count - 1 do begin
128 Result := Result + TNGWord(Items[i]).ToXMLString + #13#10;
130 Result := Result + '</NGWords>';
132 function TNGWords.ToString(): String;
137 for i := 0 to Count - 1 do begin
138 Result := Result + TNGWord(Items[i]).Word + ' , ';
141 procedure TNGWords.Delete(word: TNGWord);
145 for i := Count - 1 downto 0 do begin
146 if ( Items[i] = word ) then begin
147 TNGWord(Items[i]).Free;
153 function TNGWords.IsNG(PRes : PResRec): Boolean;
156 RStart, RLength: Integer;
160 for i := 0 to Count - 1 do begin
161 word := TNGWord(Items[i]);
162 FAWKStr.RegExp := word.Word;
163 case Ord(word.FNGType) of
166 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FTitle),
167 RStart, RLength) <> 0;
168 if Result then break;
169 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FMailTo),
170 RStart, RLength) <> 0;
171 if Result then break;
172 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FName),
173 RStart, RLength) <> 0;
174 if Result then break;
175 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FDateTime),
176 RStart, RLength) <> 0;
177 if Result then break;
178 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FBody),
179 RStart, RLength) <> 0;
182 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FName),
183 RStart, RLength) <> 0;
185 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FMailTo),
186 RStart, RLength) <> 0;
188 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FDateTime),
189 RStart, RLength) <> 0;
191 Result := FAWKStr.Match(FAWKStr.ProcessEscSeq(PRes.FBody),
192 RStart, RLength) <> 0;
194 if not Result then Exit;
199 procedure TNGWord.ReadXMLElement(element :IXMLNode);
201 FRank := StrToIntDef(element.Attributes['rank'],
203 FNGType := TGikoNGType(StrToIntDef(
204 Trim(element.Attributes['ngtype']),
207 FWord := Trim(element.Attributes['word']);
208 if FWord <> '' then begin
209 FWord := MojuUtils.UnSanitize( FWord );
213 function TNGWord.ToXMLString(): String;
215 Result := '<NGWord ' +
216 'rank="' + IntToStr(FRank) + '" ' +
217 'ngtype="' + IntToStr(Integer(FNGType)) + '" ' +
218 'word="' + MojuUtils.Sanitize(FWord) + '" />';
221 procedure TNGWordList.Free;
225 for i := Self.Count - 1 downto 0 do begin
226 TNGWords(Self.Items[i]).Free;
231 procedure TNGWordList.SaveToFrile(fileName: String);
233 xmlStrings: TStringList;
236 xmlStrings := TStringList.Create;
238 xmlStrings.Add('<?xml version="1.0" encoding="Shift_JIS" standalone="yes"?>');
239 xmlStrings.Add('<root>');
240 for i := 0 to Self.Count - 1 do begin
242 TNGWords(Self.Items[i]).ToXMLString);
245 xmlStrings.Add('</root>');
246 xmlStrings.SaveToFile(fileName);
252 procedure TNGWordList.LoadFromFile(fileName: String);
256 XMLDoc : IXMLDocument;
266 if FileExists( FileName ) then begin
267 if (Self.Count > 0) then begin
272 XMLDoc := IXMLDocument.Create;
273 //XMLDoc := LoadXMLDocument(FileName);
274 LoadXMLDocument(FileName, XMLDoc);
276 XMLNode := XMLDoc.DocumentElement;
278 if XMLNode.NodeName = 'root' then begin
279 bound := XMLNode.ChildNodes.Count - 1;
280 for i := 0 to bound do begin
281 NG := TNGWords.Create;
282 if (NG.ReadXMLElement(XMLNode.ChildNodes[i])) then
294 rt := GetTickCount - st;
295 Writeln('Runtime(Load NGWords) : ' + IntToStr(rt) + ' ms');
298 procedure TNGWordList.Delte(NGWords: TNGWords);
302 for i := Count - 1 downto 0 do begin
303 if ( Items[i] = NGWords ) then begin
304 TNGWords(Items[i]).Free;
311 function TNGWordList.IsNG(PRes : PResRec): Integer;
317 if Count > 0 then begin
318 for i := 0 to Count - 1 do begin
319 if (TNGWords(Items[i]).IsNG(PRes)) then begin
327 //
\83V
\83\93\83O
\83\8b\83g
\83\93\82Ì
\83C
\83\93\83X
\83^
\83\93\83X
329 NGWordList := TNGWordList.Create;
332 if NGWordList <> nil then begin