pt-client v1.0.1
pt-client
A Node.js app used to interact with the Perfect Tense API.
All asynchronous operations are performed using Promises.
Installing
Using npm:
$ npm install pt-client --save
Examples
Initializing pt-client
const ptClient = require('pt-client')
// Configure app key (will be sent in the Header during all interactions with API)
ptClient.setAppKey([your registered app key])
// Configure verbose console output (useful for debugging)
ptClient.setVerbose(true)
// Configure persisting correction statuses (allows Perfect Tense to learn and develop over time)
ptClient.setPersistCorrections(true)
Submit a job to Perfect Tense
function ptSuccess(result) {
// operate on successful result
}
function ptFailure(error) {
// operate on error
}
ptClient.submitJob([text], [user's API Key]).then(ptSuccess, ptFailure)
Interaction with a Perfect Tense result
// Create an interactive editor Object
const intEditor = ptClient.interactiveEditor(result, [user's API Key])
// Ignore all suggestions that are pure comments ("This sentence is a fragment", etc.)
intEditor.setIgnoreNoReplacement(true)
// Iterate through all transformations in the response
while (intEditor.hasNextTransform()) {
// Get the next available transformation
const nextTransform = intEditor.getNextTransform()
if (...) {
// Accept the correction
intEditor.acceptCorrection(nextTransform)
} else {
// Reject the correction
intEditor.rejectCorrection(nextTransform)
}
// Re-construct the current state of the job (considering accepted/rejected corrections)
const currentText = intEditor.getCurrentText()
console.log(currentText)
}
The interactive editor is the recommended way use a Perfect Tense result.
If the interactive editor's API is not sufficient for your use case, there are additional utilities provides directly through the pt-client.
When operating independently on the result object, please note that not all corrections are available at all times. Some corrections are dependent on others.
For example:
Input: "He hzve be there before"
Transformation 1: "hzve" -> "have" (spelling error)
Transformation 2: "have be" -> "has been" (verb agreement error)
Transformation 2 is not available until Transformation 1 has been accepted. If Transformation 1 is rejected, Transformation 2 will be lost.
When in doubt, there is a utility function to determine if a transformation is currently available or not:
// Returns true if the transform is currently available in the sentence, else false
ptClient.transformIsAvailable(transform, sentence)
API Documentation
See our API documentation for more information.