​API reference​
Credentials credentials = new Credentials(System.getenv("LAS_CLIENT_ID"),System.getenv("LAS_CLIENT_SECRET"),System.getenv("LAS_API_KEY"),System.getenv("LAS_AUTH_ENDPOINT"),System.getenv("LAS_API_ENDPOINT"));​client = new Client(credentials);
public void createDocument() throws IOException, APIException, MissingAccessTokenException {ContentType contentType = ContentType.fromString("image/jpeg");Path path = Paths.get("path/to/document");byte[] content = Files.readAllBytes(path);​JSONObject document = client.createDocument(content, contentType);Assert.assertTrue(document.has("contentType"));Assert.assertTrue(document.has("documentId"));}
Suppose we wish to run inference on a document using one of the available models.
public void createPrediction() throws IOException, APIException, MissingAccessTokenException {String modelId = "las:model:<hex-uuid>";JSONObject prediction = client.createPrediction(documentId, modelId);JSONArray fields = prediction.getJSONArray("predictions");Assert.assertNotNull(fields);}
See what models you have available and their model id by using the method listModels()
Suppose we make a prediction that returns incorrect values and we wish to improve the model for future use. We can do so by sending groundTruth to the model, telling it what the expected values should have been.
public void setDocumentGroundTruth() throws IOException, APIException, MissingAccessTokenException {JSONObject groundTruth = new JSONObject();​JSONObject totalAmount = new JSONObject();totalAmount.put("label", "total_amount");totalAmount.put("value", "123.00");​JSONObject purchaseDate = new JSONObject();purchaseDate.put("label", "purchase_date");purchaseDate.put("value", "2019-05-23");​List<JSONObject> fieldList = Arrays.asList(totalAmount, purchaseDate);JSONArray fields = new JSONArray(fieldList);groundTruth.put("groundTruth", fields);​JSONObject groundTruthResponse = client.updateDocument(documentId, groundTruth);Assert.assertNotNull(groundTruthResponse.get("documentId"));Assert.assertNotNull(groundTruthResponse.get("consentId"));Assert.assertNotNull(groundTruthResponse.get("groundTruth"));}
Creating a batch is a way to group documents. This is useful for specifying batches of documents to use in improving the model later.
public void createBatch() throws IOException, APIException, MissingAccessTokenException {CreadBatchOptions options = new CreateBatchOptions().setName("TrainingData").setDescription("I'm gonna create a new batch, give me a batch id!");JSONObject response = client.createBatch(options);Assert.assertNotNull(response.get("batchId"));}