Example usage for org.apache.lucene.classification.document SimpleNaiveBayesDocumentClassifier SimpleNaiveBayesDocumentClassifier

List of usage examples for org.apache.lucene.classification.document SimpleNaiveBayesDocumentClassifier SimpleNaiveBayesDocumentClassifier

Introduction

In this page you can find the example usage for org.apache.lucene.classification.document SimpleNaiveBayesDocumentClassifier SimpleNaiveBayesDocumentClassifier.

Prototype

public SimpleNaiveBayesDocumentClassifier(IndexReader indexReader, Query query, String classFieldName,
        Map<String, Analyzer> field2analyzer, String... textFieldNames) 

Source Link

Document

Creates a new NaiveBayes classifier.

Usage

From source file:org.apache.solr.update.processor.ClassificationUpdateProcessor.java

License:Apache License

/**
 * Sole constructor/*from w  w  w  .  j  av a  2 s . c o  m*/
 *
 * @param classificationParams classification advanced params
 * @param next            next update processor in the chain
 * @param indexReader     index reader
 * @param schema          schema
 */
public ClassificationUpdateProcessor(ClassificationUpdateProcessorParams classificationParams,
        UpdateRequestProcessor next, IndexReader indexReader, IndexSchema schema) {
    super(next);
    this.trainingClassField = classificationParams.getTrainingClassField();
    this.predictedClassField = classificationParams.getPredictedClassField();
    this.maxOutputClasses = classificationParams.getMaxPredictedClasses();
    String[] inputFieldNamesWithBoost = classificationParams.getInputFieldNames();
    Algorithm classificationAlgorithm = classificationParams.getAlgorithm();

    Map<String, Analyzer> field2analyzer = new HashMap<>();
    String[] inputFieldNames = this.removeBoost(inputFieldNamesWithBoost);
    for (String fieldName : inputFieldNames) {
        SchemaField fieldFromSolrSchema = schema.getField(fieldName);
        Analyzer indexAnalyzer = fieldFromSolrSchema.getType().getQueryAnalyzer();
        field2analyzer.put(fieldName, indexAnalyzer);
    }
    switch (classificationAlgorithm) {
    case KNN:
        classifier = new KNearestNeighborDocumentClassifier(indexReader, null,
                classificationParams.getTrainingFilterQuery(), classificationParams.getK(),
                classificationParams.getMinDf(), classificationParams.getMinTf(), trainingClassField,
                field2analyzer, inputFieldNamesWithBoost);
        break;
    case BAYES:
        classifier = new SimpleNaiveBayesDocumentClassifier(indexReader, null, trainingClassField,
                field2analyzer, inputFieldNamesWithBoost);
        break;
    }
}