OSDN Git Service

例外を吐きそうな計算部に例外処理を適当に追加
authorh677 <h677>
Sun, 10 Jul 2005 04:16:46 +0000 (04:16 +0000)
committerh677 <h677>
Sun, 10 Jul 2005 04:16:46 +0000 (04:16 +0000)
GikoBayesian.pas

index f72a08b..450ef85 100644 (file)
@@ -4,7 +4,7 @@ unit GikoBayesian;
 \file          GikoBayesian.pas
 \brief \83x\83C\83W\83A\83\93\83t\83B\83\8b\83^
 
-$Id: GikoBayesian.pas,v 1.17 2004/11/05 14:24:26 h677 Exp $
+$Id: GikoBayesian.pas,v 1.17.4.1 2005/07/10 04:16:46 h677 Exp $
 }
 
 //! \95½\89¼\96¼\82ð\8e«\8f\91\82É\8aÜ\82ß\82È\82¢
@@ -739,8 +739,11 @@ begin
                        s := s * Single( narray[ i ] );
                        q := q * (1 - Single( narray[ i ] ));
                end;
-
-               Result := s / (s + q);
+               try
+                       Result := s / (s + q);
+               except
+            Result := 0.5;
+               end;
        finally
                narray.Free;
        end;
@@ -769,9 +772,13 @@ function TGikoBayesian.CalcGaryRobinson( wordCount : TWordCount ) : Extended;
                                ((info.NormalWord / info.NormalText ) +
                                 (info.ImportantWord / info.ImportantText));
                }
-                       Result := (info.ImportantWord * info.NormalText) /
-                               (info.NormalWord * info.ImportantText +
-                               info.ImportantWord * info.NormalText);
+                       try
+                               Result := (info.ImportantWord * info.NormalText) /
+                                       (info.NormalWord * info.ImportantText +
+                                       info.ImportantWord * info.NormalText);
+                       except
+                               Result := 0.5;
+                       end;
        end;
 
        function f( cnt : Integer; n, mean : Single ) : Extended;
@@ -816,8 +823,14 @@ begin
        cnt := wordCount.Count;
        if cnt = 0 then
                cnt := 1;
-       P1 := 1 - Power( P1, 1 / cnt );
-       Q1 := 1 - Power( Q1, 1 / cnt );
+       try
+               P1 := 1 - Power( P1, 1 / cnt );
+       except
+       end;
+       try
+               Q1 := 1 - Power( Q1, 1 / cnt );
+       except
+       end;
 
        if P1 + Q1 = 0 then begin
                Result := 0.5
@@ -908,8 +921,14 @@ begin
        cnt := wordCount.Count;
        if cnt = 0 then
                cnt := 1;
-       P1 := Power( P1, 1 / cnt );
-       Q1 := Power( Q1, 1 / cnt );
+       try
+               P1 := Power( P1, 1 / cnt );
+       except
+       end;
+       try
+               Q1 := Power( Q1, 1 / cnt );
+       except
+       end;
 
        P1 := 1 - prbx( -2 * Ln( P1 ), 2 * cnt );
        Q1 := 1 - prbx( -2 * Ln( Q1 ), 2 * cnt );