/** * Create classifier. * * This method is here for backwards-compatibility with the old version of createClassifier. * * @param name the classifier name * @param language IETF primary language for the classifier. for example: 'en' * @param trainingData the set of questions and their "keys" used to adapt a system to a domain (the ground truth) * @return the classifier * @throws FileNotFoundException if the file could not be found */ public ServiceCall<Classifier> createClassifier(String name, String language, File trainingData) throws FileNotFoundException { Map<String, String> metadataMap = new HashMap<>(); metadataMap.put("name", name); metadataMap.put("language", language); String metadataString = GsonSingleton.getGson().toJson(metadataMap); CreateClassifierOptions createClassifierOptions = new CreateClassifierOptions.Builder() .metadata(new ByteArrayInputStream(metadataString.getBytes())) .trainingData(trainingData) .build(); return createClassifier(createClassifierOptions); }
/** * Create classifier. * * This method is here for backwards-compatibility with the old version of createClassifier. * * @param name the classifier name * @param language IETF primary language for the classifier. for example: 'en' * @param trainingData the set of questions and their "keys" used to adapt a system to a domain (the ground truth) * @return the classifier * @throws FileNotFoundException if the file could not be found */ public ServiceCall<Classifier> createClassifier(String name, String language, File trainingData) throws FileNotFoundException { Map<String, String> metadataMap = new HashMap<>(); metadataMap.put("name", name); metadataMap.put("language", language); String metadataString = GsonSingleton.getGson().toJson(metadataMap); CreateClassifierOptions createClassifierOptions = new CreateClassifierOptions.Builder() .metadata(new ByteArrayInputStream(metadataString.getBytes())) .trainingData(trainingData) .build(); return createClassifier(createClassifierOptions); }
/** * Test null training data file. */ @Test(expected = FileNotFoundException.class) public void testNullTrainingDataFile() throws FileNotFoundException { server.enqueue(jsonResponse(classifier)); File metadata = new File(RESOURCE + "metadata.json"); File trainingData = new File(RESOURCE + "notfound.txt"); CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder() .metadata(metadata) .trainingData(trainingData) .trainingDataFilename("notfound.txt") .build(); service.createClassifier(createOptions).execute(); }
/** * Test create classifier. * * @throws InterruptedException the interrupted exception */ @Test public void testCreateClassifier() throws InterruptedException, FileNotFoundException { server.enqueue(jsonResponse(classifier)); File metadata = new File(RESOURCE + "metadata.json"); File trainingData = new File(RESOURCE + "weather_data_train.csv"); CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder() .metadata(metadata) .trainingData(trainingData) .trainingDataFilename("weather_data_train.csv") .build(); final Classifier response = service.createClassifier(createOptions).execute(); final RecordedRequest request = server.takeRequest(); assertEquals(CLASSIFIERS_PATH, request.getPath()); assertEquals(classifier, response); }
/** * Creates the classifier. * * @throws Exception the exception */ @Test public void aCreate() throws Exception { final File trainingData = new File("src/test/resources/natural_language_classifier/weather_data_train.csv"); final File metadata = new File("src/test/resources/natural_language_classifier/metadata.json"); CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder() .metadata(metadata) .trainingData(trainingData) .trainingDataFilename("weather_data_train.csv") .build(); Classifier classifier = service.createClassifier(createOptions).execute(); try { assertNotNull(classifier); assertEquals(Status.TRAINING, classifier.getStatus()); assertEquals("test-classifier", classifier.getName()); assertEquals("en", classifier.getLanguage()); } finally { classifierId = classifier.getClassifierId(); } }