public class BooleanPerceptronClassifier extends java.lang.Object implements Classifier<java.lang.Boolean>
http://en.wikipedia.org/wiki/Perceptron
) based
Boolean
Classifier
. The
weights are calculated using
TermsEnum.totalTermFreq()
both on a per field
and a per document basis and then a corresponding
FST
is used for class assignment.Modifier and Type | Field and Description |
---|---|
private Analyzer |
analyzer |
private java.lang.Double |
bias |
private FST<java.lang.Long> |
fst |
private java.lang.String |
textFieldName |
private Terms |
textTerms |
Constructor and Description |
---|
BooleanPerceptronClassifier(IndexReader indexReader,
Analyzer analyzer,
Query query,
java.lang.Integer batchSize,
java.lang.Double bias,
java.lang.String classFieldName,
java.lang.String textFieldName)
Creates a
BooleanPerceptronClassifier |
Modifier and Type | Method and Description |
---|---|
ClassificationResult<java.lang.Boolean> |
assignClass(java.lang.String text)
Assign a class (with score) to the given text String
|
java.util.List<ClassificationResult<java.lang.Boolean>> |
getClasses(java.lang.String text)
Get all the classes (sorted by score, descending) assigned to the given text String.
|
java.util.List<ClassificationResult<java.lang.Boolean>> |
getClasses(java.lang.String text,
int max)
Get the first
max classes (sorted by score, descending) assigned to the given text String. |
private void |
updateFST(java.util.SortedMap<java.lang.String,java.lang.Double> weights) |
private void |
updateWeights(IndexReader indexReader,
int docId,
java.lang.Boolean assignedClass,
java.util.SortedMap<java.lang.String,java.lang.Double> weights,
double modifier,
boolean updateFST) |
private final java.lang.Double bias
private final Terms textTerms
private final Analyzer analyzer
private final java.lang.String textFieldName
private FST<java.lang.Long> fst
public BooleanPerceptronClassifier(IndexReader indexReader, Analyzer analyzer, Query query, java.lang.Integer batchSize, java.lang.Double bias, java.lang.String classFieldName, java.lang.String textFieldName) throws java.io.IOException
BooleanPerceptronClassifier
indexReader
- the reader on the index to be used for classificationanalyzer
- an Analyzer
used to analyze unseen textquery
- a Query
to eventually filter the docs used for training the classifier, or null
if all the indexed docs should be usedbatchSize
- the size of the batch of docs to use for updating the perceptron weightsbias
- the bias used for class separationclassFieldName
- the name of the field used as the output for the classifiertextFieldName
- the name of the field used as input for the classifierjava.io.IOException
- if the building of the underlying FST
fails and / or TermsEnum
for the text field
cannot be foundprivate void updateWeights(IndexReader indexReader, int docId, java.lang.Boolean assignedClass, java.util.SortedMap<java.lang.String,java.lang.Double> weights, double modifier, boolean updateFST) throws java.io.IOException
java.io.IOException
private void updateFST(java.util.SortedMap<java.lang.String,java.lang.Double> weights) throws java.io.IOException
java.io.IOException
public ClassificationResult<java.lang.Boolean> assignClass(java.lang.String text) throws java.io.IOException
Classifier
assignClass
in interface Classifier<java.lang.Boolean>
text
- a String containing text to be classifiedClassificationResult
holding assigned class of type T
and scorejava.io.IOException
- If there is a low-level I/O error.public java.util.List<ClassificationResult<java.lang.Boolean>> getClasses(java.lang.String text) throws java.io.IOException
Classifier
getClasses
in interface Classifier<java.lang.Boolean>
text
- a String containing text to be classifiedClassificationResult
, the classes and scores. Returns null
if the classifier can't make lists.java.io.IOException
- If there is a low-level I/O error.public java.util.List<ClassificationResult<java.lang.Boolean>> getClasses(java.lang.String text, int max) throws java.io.IOException
Classifier
max
classes (sorted by score, descending) assigned to the given text String.getClasses
in interface Classifier<java.lang.Boolean>
text
- a String containing text to be classifiedmax
- the number of return list elementsClassificationResult
, the classes and scores. Cut for "max" number of elements. Returns null
if the classifier can't make lists.java.io.IOException
- If there is a low-level I/O error.