Example usage for org.apache.lucene.classification SimpleNaiveBayesClassifier assignClass

List of usage examples for org.apache.lucene.classification SimpleNaiveBayesClassifier assignClass

Introduction

In this page you can find the example usage for org.apache.lucene.classification SimpleNaiveBayesClassifier assignClass.

Prototype

@Override
    public ClassificationResult<BytesRef> assignClass(String inputDocument) throws IOException 

Source Link

Usage

From source file:org.solr.classtify.SimpleNaiveBayesClassifierTest.java

License:Apache License

@Test
public void classtify() throws IOException {
    SimpleNaiveBayesClassifier classifier = new SimpleNaiveBayesClassifier();
    IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(dir)));

    AtomicReader wrap = SlowCompositeReaderWrapper.wrap(reader);
    classifier.train(wrap, textFieldName, categoryFieldName, analyzer);
    ClassificationResult<BytesRef> assignClass = classifier.assignClass(newText);
    BytesRef assignedClass = assignClass.getAssignedClass();

    double score = assignClass.getScore();
    System.out.println(assignedClass.utf8ToString() + "," + score);
}