@Test public void schemaFromJsonTest() throws ModelLoadingException { final String directoryPath = getClass().getResource(File.separator + "random_forest").getPath(); final DatasetSchema datasetSchema = LoadSchemaUtils.datasetSchemaFromJson(Paths.get(directoryPath)); assertThat(datasetSchema.getFieldSchemas()) .as("number of fields of the schema") .hasSize(4); }
public static DatasetSchema datasetSchemaFromJson(final Path filePath) throws ModelLoadingException { if (!Files.isDirectory(filePath)) { throw new ModelLoadingException("The path should be a directory"); } final Path jsonFilePath = filePath.resolve(SCHEMA_IMPORT_MODEL); if (!Files.exists(jsonFilePath)) { throw new ModelLoadingException("There is no model.json file on the model path."); } try { final String jsonContent = new String(Files.readAllBytes(jsonFilePath)); final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new SerializersInModule()); return mapper.readValue(jsonContent, DatasetSchema.class); } catch (final IOException e) { final String msg = String.format("Could not load schema for model in path %s due to %s", filePath, e.toString()); logger.error(msg); logger.trace(msg, e); throw new ModelLoadingException(e.toString()); } }
LoadSchemaUtils { public static DatasetSchema datasetSchemaFromJson(final Path filePath) throws ModelLoadingException { if (!Files.isDirectory(filePath)) { throw new ModelLoadingException("The path should be a directory"); } final Path jsonFilePath = filePath.resolve(SCHEMA_IMPORT_MODEL); if (!Files.exists(jsonFilePath)) { throw new ModelLoadingException("There is no model.json file on the model path."); } try { final String jsonContent = new String(Files.readAllBytes(jsonFilePath)); final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new SerializersInModule()); return mapper.readValue(jsonContent, DatasetSchema.class); } catch (final IOException e) { final String msg = String.format("Could not load schema for model in path %s due to %s", filePath, e.toString()); logger.error(msg); logger.trace(msg, e); throw new ModelLoadingException(e.toString()); } } }
LoadSchemaUtils { public static DatasetSchema datasetSchemaFromJson(final Path filePath) throws ModelLoadingException { if (!Files.isDirectory(filePath)) { throw new ModelLoadingException("The path should be a directory"); } final Path jsonFilePath = filePath.resolve(SCHEMA_IMPORT_MODEL); if (!Files.exists(jsonFilePath)) { throw new ModelLoadingException("There is no model.json file on the model path."); } try { final String jsonContent = new String(Files.readAllBytes(jsonFilePath)); final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new SerializersInModule()); return mapper.readValue(jsonContent, DatasetSchema.class); } catch (final IOException e) { final String msg = String.format("Could not load schema for model in path %s due to %s", filePath, e.toString()); logger.error(msg); logger.trace(msg, e); throw new ModelLoadingException(e.toString()); } } private  LoadSchemaUtils(); }
LoadSchemaUtils { public static DatasetSchema datasetSchemaFromJson(final Path filePath) throws ModelLoadingException { if (!Files.isDirectory(filePath)) { throw new ModelLoadingException("The path should be a directory"); } final Path jsonFilePath = filePath.resolve(SCHEMA_IMPORT_MODEL); if (!Files.exists(jsonFilePath)) { throw new ModelLoadingException("There is no model.json file on the model path."); } try { final String jsonContent = new String(Files.readAllBytes(jsonFilePath)); final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new SerializersInModule()); return mapper.readValue(jsonContent, DatasetSchema.class); } catch (final IOException e) { final String msg = String.format("Could not load schema for model in path %s due to %s", filePath, e.toString()); logger.error(msg); logger.trace(msg, e); throw new ModelLoadingException(e.toString()); } } private  LoadSchemaUtils(); static DatasetSchema datasetSchemaFromJson(final Path filePath); static String getValueSchemaTypeToString(final AbstractValueSchema valueSchema); }
LoadSchemaUtils { public static DatasetSchema datasetSchemaFromJson(final Path filePath) throws ModelLoadingException { if (!Files.isDirectory(filePath)) { throw new ModelLoadingException("The path should be a directory"); } final Path jsonFilePath = filePath.resolve(SCHEMA_IMPORT_MODEL); if (!Files.exists(jsonFilePath)) { throw new ModelLoadingException("There is no model.json file on the model path."); } try { final String jsonContent = new String(Files.readAllBytes(jsonFilePath)); final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new SerializersInModule()); return mapper.readValue(jsonContent, DatasetSchema.class); } catch (final IOException e) { final String msg = String.format("Could not load schema for model in path %s due to %s", filePath, e.toString()); logger.error(msg); logger.trace(msg, e); throw new ModelLoadingException(e.toString()); } } private  LoadSchemaUtils(); static DatasetSchema datasetSchemaFromJson(final Path filePath); static String getValueSchemaTypeToString(final AbstractValueSchema valueSchema); static final String CATEGORICAL; static final String NUMERIC; static final String STRING; }