public class SimpleNaiveBayesDocumentClassifier extends SimpleNaiveBayesClassifier implements DocumentClassifier<BytesRef>
http://en.wikipedia.org/wiki/Naive_Bayes_classifier
Modifier and Type | Field and Description |
---|---|
protected Map<String,Analyzer> |
field2analyzer
Analyzer to be used for tokenizing document fields |
analyzer, classFieldName, indexReader, indexSearcher, query, textFieldNames
Constructor and Description |
---|
SimpleNaiveBayesDocumentClassifier(IndexReader indexReader,
Query query,
String classFieldName,
Map<String,Analyzer> field2analyzer,
String... textFieldNames)
Creates a new NaiveBayes classifier.
|
Modifier and Type | Method and Description |
---|---|
ClassificationResult<BytesRef> |
assignClass(Document document)
Assign a class (with score) to the given
Document |
List<ClassificationResult<BytesRef>> |
getClasses(Document document)
Get all the classes (sorted by score, descending) assigned to the given
Document . |
List<ClassificationResult<BytesRef>> |
getClasses(Document document,
int max)
Get the first
max classes (sorted by score, descending) assigned to the given text String. |
protected String[] |
getTokenArray(TokenStream tokenizedText)
Returns a token array from the
TokenStream in input |
assignClass, assignClassNormalizedList, countDocsWithClass, getClasses, getClasses, normClassificationResults, tokenize
public SimpleNaiveBayesDocumentClassifier(IndexReader indexReader, Query query, String classFieldName, Map<String,Analyzer> field2analyzer, String... textFieldNames)
indexReader
- the reader on the index to be used for classificationquery
- a Query
to eventually filter the docs used for training the classifier, or null
if all the indexed docs should be usedclassFieldName
- the name of the field used as the output for the classifier NOTE: must not be havely analyzed
as the returned class will be a token indexed for this fieldtextFieldNames
- the name of the fields used as the inputs for the classifier, they can contain boosting indication e.g. title^10public ClassificationResult<BytesRef> assignClass(Document document) throws IOException
Document
assignClass
in interface DocumentClassifier<BytesRef>
document
- a Document
to be classified. Fields are considered features for the classification.ClassificationResult
holding assigned class of type T
and scoreIOException
- If there is a low-level I/O error.public List<ClassificationResult<BytesRef>> getClasses(Document document) throws IOException
Document
.getClasses
in interface DocumentClassifier<BytesRef>
document
- a Document
to be classified. Fields are considered features for the classification.ClassificationResult
, the classes and scores. Returns null
if the classifier can't make lists.IOException
- If there is a low-level I/O error.public List<ClassificationResult<BytesRef>> getClasses(Document document, int max) throws IOException
max
classes (sorted by score, descending) assigned to the given text String.getClasses
in interface DocumentClassifier<BytesRef>
document
- a Document
to be classified. Fields are considered features for the classification.max
- 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.IOException
- If there is a low-level I/O error.protected String[] getTokenArray(TokenStream tokenizedText) throws IOException
TokenStream
in inputtokenizedText
- the tokenized content of a fieldString
array of the resulting tokensIOException
- If tokenization fails because there is a low-level I/O errorCopyright © 2000-2017 Apache Software Foundation. All Rights Reserved.