Scala is a programming language designed to run on the JVM, supporting both functional and object-oriented programming patterns. It is designed to be more concise than Java.
With Sapling, you can add grammar or spell checking functionality to an existing Scala application.
This page demonstrates a quick way to integrate grammar and spell checking functionality into a Scala application using Sapling's API. If you are not looking for a Scala guide, click here for guides for other programming languages.
Sapling does not currently maintain a Scala-specific SDK, but you can access the Sapling Grammar Checking HTTP API using any programming language that supports HTTP POST requests. An example is shown below.
This is an example of doing an HTTP Post request using scalaj-http, which is now deprecated
import scalaj.http.{Http, HttpOptions}
object Main {
def main(args: Array[String]): Unit = {
println("Hello world!")
val data : String = """{"key":"API_KEY","text":"Lets get started", "session_id": "Test Document UUID"}"""
val url : String = "https://api.sapling.ai/api/v1/edits"
val result = Http(url).postData(data)
.header("Content-Type", "application/json")
.header("Charset", "UTF-8")
.option(HttpOptions.readTimeout(30000)).asString
}
}
You can also use the native Java HTTPClient to reduce dependancies
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
object Main {
def main(args: Array[String]): Unit = {
println("Hello world!")
val params : String = """{"key":"API_KEY","text":"Lets get started", "session_id": "Test Document UUID"}"""
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(params))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
Returned result:
{
"edits":[
{
"end":4,
"error_type":"R:OTHER",
"general_error_type":"Other",
"id":"aa5ee291-a073-5146-8ebc-c9c899d01278",
"replacement":"Let's",
"sentence":"Lets get started!",
"sentence_start":0,
"start":0
}
]
}
Addtional parameters and Sapling's full API documentation can be accessed here: https://sapling.ai/docs