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/05/12 19:04:50 UTC
svn commit: r1679005 - in /lucene/dev/trunk/lucene/classification/src:
java/org/apache/lucene/classification/BooleanPerceptronClassifier.java
test/org/apache/lucene/classification/BooleanPerceptronClassifierTest.java
Author: tommaso
Date: Tue May 12 17:04:49 2015
New Revision: 1679005
URL: http://svn.apache.org/r1679005
Log:
LUCENE-6045 - refactored BPC constructor to be more consistent with others
Modified:
lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/BooleanPerceptronClassifier.java
lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/BooleanPerceptronClassifierTest.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=1679005&r1=1679004&r2=1679005&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 Tue May 12 17:04:49 2015
@@ -68,18 +68,18 @@ public class BooleanPerceptronClassifier
* Creates a {@link BooleanPerceptronClassifier}
*
* @param leafReader the reader on the index to be used for classification
- * @param textFieldName the name of the field used as input for the classifier
- * @param classFieldName the name of the field used as the output for the classifier
* @param analyzer an {@link Analyzer} used to analyze unseen text
* @param query a {@link Query} to eventually filter the docs used for training the classifier, or {@code null}
* if all the indexed docs should be used
* @param batchSize the size of the batch of docs to use for updating the perceptron weights
* @param threshold the threshold used for class separation
+ * @param classFieldName the name of the field used as the output for the classifier
+ * @param textFieldName the name of the field used as input for the classifier
* @throws IOException if the building of the underlying {@link FST} fails and / or {@link TermsEnum} for the text field
* cannot be found
*/
- public BooleanPerceptronClassifier(LeafReader leafReader, String textFieldName, String classFieldName, Analyzer analyzer,
- Query query, Integer batchSize, Double threshold) throws IOException {
+ public BooleanPerceptronClassifier(LeafReader leafReader, Analyzer analyzer, Query query, Integer batchSize,
+ Double threshold, String classFieldName, String textFieldName) throws IOException {
this.textTerms = MultiFields.getTerms(leafReader, textFieldName);
if (textTerms == null) {
Modified: lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/BooleanPerceptronClassifierTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/BooleanPerceptronClassifierTest.java?rev=1679005&r1=1679004&r2=1679005&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/BooleanPerceptronClassifierTest.java (original)
+++ lucene/dev/trunk/lucene/classification/src/test/org/apache/lucene/classification/BooleanPerceptronClassifierTest.java Tue May 12 17:04:49 2015
@@ -18,7 +18,6 @@ package org.apache.lucene.classification
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.index.LeafReader;
-import org.apache.lucene.index.SlowCompositeReaderWrapper;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.TermQuery;
import org.junit.Test;
@@ -34,7 +33,7 @@ public class BooleanPerceptronClassifier
try {
MockAnalyzer analyzer = new MockAnalyzer(random());
leafReader = populateSampleIndex(analyzer);
- checkCorrectClassification(new BooleanPerceptronClassifier(leafReader, textFieldName, booleanFieldName, analyzer, null, 1, null), TECHNOLOGY_INPUT, false);
+ checkCorrectClassification(new BooleanPerceptronClassifier(leafReader, analyzer, null, 1, null, booleanFieldName, textFieldName), TECHNOLOGY_INPUT, false);
} finally {
if (leafReader != null) {
leafReader.close();
@@ -48,7 +47,9 @@ public class BooleanPerceptronClassifier
try {
MockAnalyzer analyzer = new MockAnalyzer(random());
leafReader = populateSampleIndex(analyzer);
- checkCorrectClassification(new BooleanPerceptronClassifier(leafReader, textFieldName, booleanFieldName, analyzer, null, 1, 100d), TECHNOLOGY_INPUT, false);
+ BooleanPerceptronClassifier classifier = new BooleanPerceptronClassifier(leafReader, analyzer, null, 1, 50d, booleanFieldName, textFieldName);
+ checkCorrectClassification(classifier, TECHNOLOGY_INPUT, false);
+ checkCorrectClassification(classifier, POLITICS_INPUT, true);
} finally {
if (leafReader != null) {
leafReader.close();
@@ -63,7 +64,7 @@ public class BooleanPerceptronClassifier
try {
MockAnalyzer analyzer = new MockAnalyzer(random());
leafReader = populateSampleIndex(analyzer);
- checkCorrectClassification(new BooleanPerceptronClassifier(leafReader, textFieldName, booleanFieldName, analyzer, query, 1, null), TECHNOLOGY_INPUT, false);
+ checkCorrectClassification(new BooleanPerceptronClassifier(leafReader, analyzer, query, 1, null, booleanFieldName, textFieldName), TECHNOLOGY_INPUT, false);
} finally {
if (leafReader != null) {
leafReader.close();