A CFML wrapper for the SMMRY API. Utilize the SMMRY API to summarize articles, text, PDFs, etc. by extracting the most important sentences.
Feel free to use the issue tracker to report bugs or suggest improvements!
This project borrows heavily from the API frameworks built by jcberquist, such as xero-cfml and aws-cfml. Because it draws on those projects, it is also licensed under the terms of the MIT license.
The following is a minimal example of summarizing a webpage:
smmry = new path.to.smmrize.smmry( apiKey = 'xxx' );
summary = smmry.web( 'https://en.wikipedia.org/wiki/Fred_Rogers' );
writeDump( var='#summary#' );
To get started with SMMRY, you'll need an API key. You can get this by registering and following the instructions on the SMMRY website.
Once you have an API key, you can provide it to this wrapper manually, as in the Quick Start example above, or via an environment variable named SMMRY_API_KEY
.
The API can summarize either web-based content or text, via the web()
and text()
methods, respectively. Both these functions take an optional, second argument, which contains the settings for your summarization. The easiest way to provide these is via the helpers.options
component, which provides a fluent interface for setting them. Here's an example:
smmry = new path.to.smmrize.smmry( apiKey = 'xxx' );
options = new path.to.smmrize.helpers.options()
.sentences( 3 )
.keywords( 3 )
.withBreak()
.withEncode()
.avoidQuestions();
webpage = 'https://en.wikipedia.org/wiki/Eiffel_Tower';
summary = smmry.web( webpage, options );
writeDump( var='#summary#' );
If you prefer, options can be provided manually, as a struct, using the parameters outlined in the SMMRY documentation- the options defined in the previous example, using this approach, would be structured like this:
options = {
'SM_LENGTH': 3,
'SM_KEYWORD_COUNT': 3,
'SM_WITH_BREAK': true,
'SM_WITH_ENCODE': true,
'SM_QUESTION_AVOID': true
};
Summarize the content of a webpage. The options
argument must be either an instance of the helpers.options
component or a struct defining the summarization options.
Summarize a body of text. The options
argument must be either an instance of the helpers.options
component or a struct defining the summarization options.
This section documents every public method in the helpers/options.cfc
file. All of these methods are chainable, enabling you to fluently build your summarization options.
Sets the number of sentences returned (default 7)
Included to provide a more fluent interface; delegates to length()
Sets the the number of keywords to return
Included to provide a more fluent interface; delegates to keywordCount()
Inserts the string [BREAK] between sentences.
Converts HTML entities to their applicable chars.
Returns summary regardless of quality or length.
Excludes sentences with quotations.
Excludes sentences that are questions.
Excludes sentences with exclamation marks.
The function that puts it all together and builds the options
struct for use in the API operations.