The programming language C is well known for its performance and widespread usage across all platforms and systems for multiple decades.
With Sapling, you can add grammar or spell checking functionality to an existing C application.
This page demonstrates a quick way to integrate grammar and spell checking functionality into a C application using Sapling's API. If you are not looking for a C guide, click here for guides for other programming languages.
Sapling does not currently maintain a C-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.
C does not have a standard HTTP or socket library. HTTP POST requests in C require an HTTP library like libcurl.
#include <stdio.h>
#include <curl/curl.h>
int main(void) {
char* jsonObj = "{\"key\":\"<API_KEY>\", \"text\":\"Lets get started!\", \"session_id\":\"Test Document UUID\"}";
struct curl_slist *headers = NULL;
curl_slist_append(headers, "Accept: application/json");
curl_slist_append(headers, "Content-Type: application/json");
curl_slist_append(headers, "charset: utf-8");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.sapling.ai/api/v1/edits");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonObj);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcrp/0.1");
res = curl_easy_perform(curl);
}
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