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 2015/04/17 15:46:17 UTC
svn commit: r1674304 - in
/lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification:
BooleanPerceptronClassifier.java Classifier.java
Author: tommaso
Date: Fri Apr 17 13:46:17 2015
New Revision: 1674304
URL: http://svn.apache.org/r1674304
Log:
LUCENE-6433 - using generics in Classifier#getClasses
Modified:
lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/BooleanPerceptronClassifier.java
lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/Classifier.java
Modified: lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/BooleanPerceptronClassifier.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/BooleanPerceptronClassifier.java?rev=1674304&r1=1674303&r2=1674304&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/BooleanPerceptronClassifier.java (original)
+++ lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/BooleanPerceptronClassifier.java Fri Apr 17 13:46:17 2015
@@ -173,21 +173,24 @@ public class BooleanPerceptronClassifier
Integer.MAX_VALUE).scoreDocs) {
StoredDocument doc = indexSearcher.doc(scoreDoc.doc);
- // assign class to the doc
- ClassificationResult<Boolean> classificationResult = assignClass(doc
- .getField(textFieldName).stringValue());
- Boolean assignedClass = classificationResult.getAssignedClass();
+ StorableField textField = doc.getField(textFieldName);
// get the expected result
- StorableField field = doc.getField(classFieldName);
+ StorableField classField = doc.getField(classFieldName);
- Boolean correctClass = Boolean.valueOf(field.stringValue());
- long modifier = correctClass.compareTo(assignedClass);
- if (modifier != 0) {
- updateWeights(leafReader, scoreDoc.doc, assignedClass,
- weights, modifier, batchCount % batchSize == 0);
+ if (textField != null && classField != null) {
+ // assign class to the doc
+ ClassificationResult<Boolean> classificationResult = assignClass(textField.stringValue());
+ Boolean assignedClass = classificationResult.getAssignedClass();
+
+ Boolean correctClass = Boolean.valueOf(classField.stringValue());
+ long modifier = correctClass.compareTo(assignedClass);
+ if (modifier != 0) {
+ updateWeights(leafReader, scoreDoc.doc, assignedClass,
+ weights, modifier, batchCount % batchSize == 0);
+ }
+ batchCount++;
}
- batchCount++;
}
weights.clear(); // free memory while waiting for GC
}
@@ -246,18 +249,18 @@ public class BooleanPerceptronClassifier
* {@inheritDoc}
*/
@Override
- public List<ClassificationResult<BytesRef>> getClasses(String text)
+ public List<ClassificationResult<Boolean>> getClasses(String text)
throws IOException {
- return null;
+ throw new RuntimeException("not implemented");
}
/**
* {@inheritDoc}
*/
@Override
- public List<ClassificationResult<BytesRef>> getClasses(String text, int max)
+ public List<ClassificationResult<Boolean>> getClasses(String text, int max)
throws IOException {
- return null;
+ throw new RuntimeException("not implemented");
}
}
Modified: lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/Classifier.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/Classifier.java?rev=1674304&r1=1674303&r2=1674304&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/Classifier.java (original)
+++ lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/Classifier.java Fri Apr 17 13:46:17 2015
@@ -48,7 +48,7 @@ public interface Classifier<T> {
* @return the whole list of {@link ClassificationResult}, the classes and scores. Returns <code>null</code> if the classifier can't make lists.
* @throws IOException If there is a low-level I/O error.
*/
- public List<ClassificationResult<BytesRef>> getClasses(String text) throws IOException;
+ public List<ClassificationResult<T>> getClasses(String text) throws IOException;
/**
* Get the first <code>max</code> classes (sorted by score, descending) assigned to the given text String.
@@ -58,7 +58,7 @@ public interface Classifier<T> {
* @return the whole list of {@link ClassificationResult}, the classes and scores. Cut for "max" number of elements. Returns <code>null</code> if the classifier can't make lists.
* @throws IOException If there is a low-level I/O error.
*/
- public List<ClassificationResult<BytesRef>> getClasses(String text, int max) throws IOException;
+ public List<ClassificationResult<T>> getClasses(String text, int max) throws IOException;
/**
* Train the classifier using the underlying Lucene index