You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2011/05/08 19:12:03 UTC
svn commit: r1100777 - in
/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic:
BayesianAnalyzer.java TokenProbabilityStrength.java
Author: rdonkin
Date: Sun May 8 17:12:03 2011
New Revision: 1100777
URL: http://svn.apache.org/viewvc?rev=1100777&view=rev
Log:
Factor out inner class.
Added:
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/TokenProbabilityStrength.java (with props)
Modified:
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalyzer.java
Modified: james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalyzer.java
URL: http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalyzer.java?rev=1100777&r1=1100776&r2=1100777&view=diff
==============================================================================
--- james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalyzer.java (original)
+++ james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalyzer.java Sun May 8 17:12:03 2011
@@ -102,7 +102,7 @@ public class BayesianAnalyzer {
* Default token probability to use when a token has not been encountered
* before.
*/
- private final static double DEFAULT_TOKEN_PROBABILITY = 0.4;
+ final static double DEFAULT_TOKEN_PROBABILITY = 0.4;
/** Map of ham tokens and their occurrences. */
private Map<String, Integer> hamTokenCounts = new HashMap<String, Integer>();
@@ -120,58 +120,6 @@ public class BayesianAnalyzer {
private Map<String, Double> corpus = new HashMap<String, Double>();
/**
- * Inner class for managing Token Probability Strengths during the
- * computeSpamProbability phase.
- *
- * By probability <i>strength</i> we mean the absolute distance of a
- * probability from the middle value 0.5.
- *
- * It implements Comparable so that it's sorting is automatic.
- */
- private class TokenProbabilityStrength implements Comparable<TokenProbabilityStrength> {
- /**
- * Message token.
- */
- String token = null;
-
- /**
- * Token's computed probability strength.
- */
- double strength = Math.abs(0.5 - DEFAULT_TOKEN_PROBABILITY);
-
- /**
- * Force the natural sort order for this object to be high-to-low.
- *
- * @param anotherTokenProbabilityStrength
- * A TokenProbabilityStrength instance to compare this
- * instance with.
- *
- * @return The result of the comparison (before, equal, after).
- */
- public final int compareTo(TokenProbabilityStrength anotherTokenProbabilityStrength) {
- int result = (int) ((((TokenProbabilityStrength) anotherTokenProbabilityStrength).strength - strength) * 1000000);
- if (result == 0) {
- return this.token.compareTo(((TokenProbabilityStrength) anotherTokenProbabilityStrength).token);
- } else {
- return result;
- }
- }
-
- /**
- * Simple toString () implementation mostly for debugging purposes.
- *
- * @return String representation of this object.
- */
- public String toString() {
- StringBuffer sb = new StringBuffer(30);
-
- sb.append(token).append("=").append(strength);
-
- return sb.toString();
- }
- }
-
- /**
* Basic class constructor.
*/
public BayesianAnalyzer() {
Added: james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/TokenProbabilityStrength.java
URL: http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/TokenProbabilityStrength.java?rev=1100777&view=auto
==============================================================================
--- james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/TokenProbabilityStrength.java (added)
+++ james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/TokenProbabilityStrength.java Sun May 8 17:12:03 2011
@@ -0,0 +1,72 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.ai.classic;
+
+/**
+ * Inner class for managing Token Probability Strengths during the
+ * computeSpamProbability phase.
+ *
+ * By probability <i>strength</i> we mean the absolute distance of a
+ * probability from the middle value 0.5.
+ *
+ * It implements Comparable so that it's sorting is automatic.
+ */
+class TokenProbabilityStrength implements Comparable<TokenProbabilityStrength> {
+ /**
+ * Message token.
+ */
+ String token = null;
+
+ /**
+ * Token's computed probability strength.
+ */
+ double strength = Math.abs(0.5 - BayesianAnalyzer.DEFAULT_TOKEN_PROBABILITY);
+
+ /**
+ * Force the natural sort order for this object to be high-to-low.
+ *
+ * @param anotherTokenProbabilityStrength
+ * A TokenProbabilityStrength instance to compare this
+ * instance with.
+ *
+ * @return The result of the comparison (before, equal, after).
+ */
+ public final int compareTo(TokenProbabilityStrength anotherTokenProbabilityStrength) {
+ int result = (int) ((((TokenProbabilityStrength) anotherTokenProbabilityStrength).strength - strength) * 1000000);
+ if (result == 0) {
+ return this.token.compareTo(((TokenProbabilityStrength) anotherTokenProbabilityStrength).token);
+ } else {
+ return result;
+ }
+ }
+
+ /**
+ * Simple toString () implementation mostly for debugging purposes.
+ *
+ * @return String representation of this object.
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer(30);
+
+ sb.append(token).append("=").append(strength);
+
+ return sb.toString();
+ }
+}
\ No newline at end of file
Propchange: james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/TokenProbabilityStrength.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org