You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2012/11/29 08:30:57 UTC
svn commit: r1415063 -
/lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
Author: tommaso
Date: Thu Nov 29 07:30:57 2012
New Revision: 1415063
URL: http://svn.apache.org/viewvc?rev=1415063&view=rev
Log:
[LUCENE-4345] - avoid tokenizing the input doc multiple times
Modified:
lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
Modified: lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java?rev=1415063&r1=1415062&r2=1415063&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java (original)
+++ lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java Thu Nov 29 07:30:57 2012
@@ -99,9 +99,10 @@ public class SimpleNaiveBayesClassifier
Terms terms = MultiFields.getTerms(atomicReader, classFieldName);
TermsEnum termsEnum = terms.iterator(null);
BytesRef next;
+ String[] tokenizedDoc = tokenizeDoc(inputDocument);
while ((next = termsEnum.next()) != null) {
// TODO : turn it to be in log scale
- double clVal = calculatePrior(next) * calculateLikelihood(inputDocument, next);
+ double clVal = calculatePrior(next) * calculateLikelihood(tokenizedDoc, next);
if (clVal > max) {
max = clVal;
foundClass = next.utf8ToString();
@@ -111,10 +112,10 @@ public class SimpleNaiveBayesClassifier
}
- private double calculateLikelihood(String document, BytesRef c) throws IOException {
+ private double calculateLikelihood(String[] tokenizedDoc, BytesRef c) throws IOException {
// for each word
double result = 1d;
- for (String word : tokenizeDoc(document)) {
+ for (String word : tokenizedDoc) {
// search with text:word AND class:c
int hits = getWordFreqForClass(word, c);