Statistics
The Statistics endpoint computes simple statistics for a given text document. These statistics include word and sentence counts as well as Flesch-Kincaid score.
Statistics POST
Sample Code
- cURL
- JavaScript
- Python
curl -X POST https://api.sapling.ai/api/v1/statistics \
-H "Content-Type: application/json" \
-d '{"key":"<api-key>", "text":"Hi, how are you doing?"}'
import axios from 'axios';
async function run(text) {
try {
const response = await axios.post(
'https://api.sapling.ai/api/v1/statistics',
{
"key": '<api-key>',
text,
},
);
const {status, data} = response;
console.log({status});
console.log(JSON.stringify(data, null, 4));
} catch (err) {
const { msg } = err.response.data;
console.log({err: msg});
}
}
run('Hi, how are you doing?');
import requests
from pprint import pprint
response = requests.post(
"https://api.sapling.ai/api/v1/statistics",
json={
"key": "<api-key>",
"text": "Hi, how are you doing?"
}
)
pprint(response.json())
Sample Response
{
"chars": 22,
"readability": 0.5,
"reading_time_min": 1,
"reading_time_sec": 1.13,
"sentences": 1,
"words": 5
}
Request Parameters
https://api.sapling.ai/api/v1/statistics
HTTP method: POST
The Statistics API POST endpoint takes JSON parameters documented below:
key: String
32-character API key.
text: String
Text to compute statistics for.
session_id: String
Unique name or UUID of document or portion of text that is being processed.
Response Parameters
The Statistics POST endpoint returns JSON of the following format:
{
"chars": 397,
"readability": 7.5, // Flesch-Kincaid readability grade
"reading_time_min": 1,
"reading_time_sec": 15.62,
"sentences": 5,
"words": 69
}