use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class ClassificationUpdateProcessorTest method knnMultiClass_maxOutputClasses2_shouldAssignMax2Classes.
@Test
public void knnMultiClass_maxOutputClasses2_shouldAssignMax2Classes() throws Exception {
UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
prepareTrainedIndexMultiClass();
AddUpdateCommand update = new AddUpdateCommand(req());
SolrInputDocument unseenDocument1 = sdoc(ID, "10", TITLE, "word1 word1 word1", CONTENT, "word2 word2 ", AUTHOR, "unseenAuthor");
update.solrDoc = unseenDocument1;
ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.KNN);
params.setMaxPredictedClasses(2);
updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
updateProcessorToTest.processAdd(update);
ArrayList<Object> assignedClasses = (ArrayList) unseenDocument1.getFieldValues(TRAINING_CLASS);
assertThat(assignedClasses.size(), is(2));
assertThat(assignedClasses.get(0), is("class2"));
assertThat(assignedClasses.get(1), is("class1"));
}
use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class ClassificationUpdateProcessorTest method knnMonoClass_sampleParams_shouldAssignCorrectClass.
@Test
public void knnMonoClass_sampleParams_shouldAssignCorrectClass() throws Exception {
UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
prepareTrainedIndexMonoClass();
AddUpdateCommand update = new AddUpdateCommand(req());
SolrInputDocument unseenDocument1 = sdoc(ID, "10", TITLE, "word4 word4 word4", CONTENT, "word2 word2 ", AUTHOR, "unseenAuthor");
update.solrDoc = unseenDocument1;
ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.KNN);
updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
updateProcessorToTest.processAdd(update);
assertThat(unseenDocument1.getFieldValue(TRAINING_CLASS), is("class2"));
}
use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class ClassificationUpdateProcessorTest method bayesMonoClass_boostFields_shouldAssignCorrectClass.
@Test
public void bayesMonoClass_boostFields_shouldAssignCorrectClass() throws Exception {
UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
prepareTrainedIndexMonoClass();
AddUpdateCommand update = new AddUpdateCommand(req());
SolrInputDocument unseenDocument1 = sdoc(ID, "10", TITLE, "word4 word4 word4", CONTENT, "word2 word2 ", AUTHOR, "unseenAuthor");
update.solrDoc = unseenDocument1;
ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.BAYES);
params.setInputFieldNames(new String[] { TITLE + "^1.5", CONTENT + "^0.5", AUTHOR + "^2.5" });
updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
updateProcessorToTest.processAdd(update);
assertThat(unseenDocument1.getFieldValue(TRAINING_CLASS), is("class2"));
}
use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class ClassificationUpdateProcessorTest method classificationMonoClass_predictedClassFieldSet_shouldAssignClassInPredictedClassField.
@Test
public void classificationMonoClass_predictedClassFieldSet_shouldAssignClassInPredictedClassField() throws Exception {
UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
prepareTrainedIndexMonoClass();
AddUpdateCommand update = new AddUpdateCommand(req());
SolrInputDocument unseenDocument1 = sdoc(ID, "10", TITLE, "word4 word4 word4", CONTENT, "word2 word2 ", AUTHOR, "unseenAuthor");
update.solrDoc = unseenDocument1;
ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.KNN);
params.setPredictedClassField(PREDICTED_CLASS);
updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
updateProcessorToTest.processAdd(update);
assertThat(unseenDocument1.getFieldValue(PREDICTED_CLASS), is("class2"));
}
use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class ClassificationUpdateProcessorTest method knnMonoClass_boostFields_shouldAssignCorrectClass.
@Test
public void knnMonoClass_boostFields_shouldAssignCorrectClass() throws Exception {
UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
prepareTrainedIndexMonoClass();
AddUpdateCommand update = new AddUpdateCommand(req());
SolrInputDocument unseenDocument1 = sdoc(ID, "10", TITLE, "word4 word4 word4", CONTENT, "word2 word2 ", AUTHOR, "unseenAuthor");
update.solrDoc = unseenDocument1;
ClassificationUpdateProcessorParams params = initParams(ClassificationUpdateProcessorFactory.Algorithm.KNN);
params.setInputFieldNames(new String[] { TITLE + "^1.5", CONTENT + "^0.5", AUTHOR + "^2.5" });
updateProcessorToTest = new ClassificationUpdateProcessor(params, mockProcessor, reader, req().getSchema());
updateProcessorToTest.processAdd(update);
assertThat(unseenDocument1.getFieldValue(TRAINING_CLASS), is("class2"));
}
Aggregations