public class KNearestFuzzyClassifier extends java.lang.Object implements Classifier<BytesRef>
NearestFuzzyQuery
.Modifier and Type | Field and Description |
---|---|
private Analyzer |
analyzer |
private java.lang.String |
classFieldName
the name of the field used as the output text
|
private IndexSearcher |
indexSearcher
an
IndexSearcher used to perform queries |
private int |
k
the no.
|
private Query |
query
a
Query used to filter the documents that should be used from this classifier's underlying LeafReader |
private java.lang.String[] |
textFieldNames
the name of the fields used as the input text
|
Constructor and Description |
---|
KNearestFuzzyClassifier(IndexReader indexReader,
Similarity similarity,
Analyzer analyzer,
Query query,
int k,
java.lang.String classFieldName,
java.lang.String... textFieldNames)
Creates a
KNearestFuzzyClassifier . |
Modifier and Type | Method and Description |
---|---|
ClassificationResult<BytesRef> |
assignClass(java.lang.String text)
Assign a class (with score) to the given text String
|
private java.util.List<ClassificationResult<BytesRef>> |
buildListFromTopDocs(TopDocs topDocs)
build a list of classification results from search results
|
java.util.List<ClassificationResult<BytesRef>> |
getClasses(java.lang.String text)
Get all the classes (sorted by score, descending) assigned to the given text String.
|
java.util.List<ClassificationResult<BytesRef>> |
getClasses(java.lang.String text,
int max)
Get the first
max classes (sorted by score, descending) assigned to the given text String. |
private TopDocs |
knnSearch(java.lang.String text) |
java.lang.String |
toString() |
private final java.lang.String[] textFieldNames
private final java.lang.String classFieldName
private final IndexSearcher indexSearcher
IndexSearcher
used to perform queriesprivate final int k
private final Query query
Query
used to filter the documents that should be used from this classifier's underlying LeafReader
private final Analyzer analyzer
public KNearestFuzzyClassifier(IndexReader indexReader, Similarity similarity, Analyzer analyzer, Query query, int k, java.lang.String classFieldName, java.lang.String... textFieldNames)
KNearestFuzzyClassifier
.indexReader
- the reader on the index to be used for classificationanalyzer
- an Analyzer
used to analyze unseen textsimilarity
- the Similarity
to be used by the underlying IndexSearcher
or null
(defaults to BM25Similarity
)query
- a Query
to eventually filter the docs used for training the classifier, or null
if all the indexed docs should be usedk
- the no. of docs to select in the MLT results to find the nearest neighborclassFieldName
- the name of the field used as the output for the classifiertextFieldNames
- the name of the fields used as the inputs for the classifier, they can contain boosting indication e.g. title^10public ClassificationResult<BytesRef> assignClass(java.lang.String text) throws java.io.IOException
Classifier
assignClass
in interface Classifier<BytesRef>
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<BytesRef>> getClasses(java.lang.String text) throws java.io.IOException
Classifier
getClasses
in interface Classifier<BytesRef>
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<BytesRef>> 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<BytesRef>
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.private TopDocs knnSearch(java.lang.String text) throws java.io.IOException
java.io.IOException
private java.util.List<ClassificationResult<BytesRef>> buildListFromTopDocs(TopDocs topDocs) throws java.io.IOException
topDocs
- the search results as a TopDocs
objectList
of ClassificationResult
, one for each existing classjava.io.IOException
- if it's not possible to get the stored value of class fieldpublic java.lang.String toString()
toString
in class java.lang.Object