org.apache.lucene.classification

## Class CachingNaiveBayesClassifier

- java.lang.Object
- - org.apache.lucene.classification.SimpleNaiveBayesClassifier
  - - org.apache.lucene.classification.CachingNaiveBayesClassifier

- All Implemented Interfaces:
    Classifier<BytesRef>

      public class CachingNaiveBayesClassifier
      extends SimpleNaiveBayesClassifier

  A simplistic Lucene based NaiveBayes classifier, with caching feature, see `http://en.wikipedia.org/wiki/Naive_Bayes_classifier`

  This is NOT an online classifier.

  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.classification.SimpleNaiveBayesClassifier

      `analyzer, classFieldName, indexSearcher, leafReader, query, textFieldNames`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CachingNaiveBayesClassifier()` Creates a new NaiveBayes classifier with inside caching.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `reInitCache(int minTermOccurrenceInCache, boolean justCachedTerms)` This function is building the frame of the cache.
    `void` | `train(LeafReader leafReader, String[] textFieldNames, String classFieldName, Analyzer analyzer, Query query)` Train the classifier using the underlying Lucene index
    `void` | `train(LeafReader leafReader, String textFieldName, String classFieldName, Analyzer analyzer)` Train the classifier using the underlying Lucene index
    `void` | `train(LeafReader leafReader, String textFieldName, String classFieldName, Analyzer analyzer, Query query)` Train the classifier using the underlying Lucene index

    - ### Methods inherited from class org.apache.lucene.classification.SimpleNaiveBayesClassifier

      `assignClass, countDocsWithClass, getClasses, getClasses, tokenizeDoc`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CachingNaiveBayesClassifier

          public CachingNaiveBayesClassifier()

      Creates a new NaiveBayes classifier with inside caching. Note that you must call `train()` before you can classify any documents. If you want less memory usage you could call `reInitCache()`.

  - ### Method Detail

    - #### train

          public void train(LeafReader leafReader,
                   String textFieldName,
                   String classFieldName,
                   Analyzer analyzer)
                     throws IOException

      Train the classifier using the underlying Lucene index
      Specified by:
        `train` in interface `Classifier<BytesRef>`
      Overrides:
        `train` in class `SimpleNaiveBayesClassifier`
      Parameters:
        `leafReader` - the reader to use to access the Lucene index
        `textFieldName` - the name of the field used to compare documents
        `classFieldName` - the name of the field containing the class assigned to documents
        `analyzer` - the analyzer used to tokenize / filter the unseen text
      Throws:
        `IOException` - If there is a low-level I/O error.

    - #### train

          public void train(LeafReader leafReader,
                   String textFieldName,
                   String classFieldName,
                   Analyzer analyzer,
                   Query query)
                     throws IOException

      Train the classifier using the underlying Lucene index
      Specified by:
        `train` in interface `Classifier<BytesRef>`
      Overrides:
        `train` in class `SimpleNaiveBayesClassifier`
      Parameters:
        `leafReader` - the reader to use to access the Lucene index
        `textFieldName` - the name of the field used to compare documents
        `classFieldName` - the name of the field containing the class assigned to documents
        `analyzer` - the analyzer used to tokenize / filter the unseen text
        `query` - the query to filter which documents use for training
      Throws:
        `IOException` - If there is a low-level I/O error.

    - #### train

          public void train(LeafReader leafReader,
                   String[] textFieldNames,
                   String classFieldName,
                   Analyzer analyzer,
                   Query query)
                     throws IOException

      Train the classifier using the underlying Lucene index
      Specified by:
        `train` in interface `Classifier<BytesRef>`
      Overrides:
        `train` in class `SimpleNaiveBayesClassifier`
      Parameters:
        `leafReader` - the reader to use to access the Lucene index
        `textFieldNames` - the names of the fields to be used to compare documents
        `classFieldName` - the name of the field containing the class assigned to documents
        `analyzer` - the analyzer used to tokenize / filter the unseen text
        `query` - the query to filter which documents use for training
      Throws:
        `IOException` - If there is a low-level I/O error.

    - #### reInitCache

          public void reInitCache(int minTermOccurrenceInCache,
                         boolean justCachedTerms)
                           throws IOException

      This function is building the frame of the cache. The cache is storing the word occurrences to the memory after those searched once. This cache can made 2-100x speedup in proper use, but can eat lot of memory. There is an option to lower the memory consume, if a word have really low occurrence in the index you could filter it out. The other parameter is switching between the term searching, if it true, just the terms in the skeleton will be searched, but if it false the terms whoes not in the cache will be searched out too (but not cached).
      Parameters:
        `minTermOccurrenceInCache` - Lower cache size with higher value.
        `justCachedTerms` - The switch for fully exclude low occurrence docs.
      Throws:
        `IOException` - If there is a low-level I/O error.

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.