Global

Methods

calculateKeywordFrequencyScore(sentence, keywords) → {number}

Calculates a score for a sentence based on the presence of targeted keywords.
Parameters:
Name Type Description
sentence string The sentence to be scored.
keywords Array.<string> An array of keywords to score against.
Source:
Returns:
A score representing the number of keywords found in the sentence.
Type
number
Example
const sentence = "This sentence includes important keywords.";
const keywords = ['sentence', 'important', 'keywords'];
const score = calculateKeywordFrequencyScore(sentence, keywords);
console.log(score); // Output: 3

calculateKeywordFrequencyScore(sentence, keywords) → {number}

Calculates a score for a sentence based on the presence of targeted keywords.
Parameters:
Name Type Description
sentence string The sentence to be scored.
keywords Array.<string> An array of keywords to score against.
Source:
Returns:
A score representing the number of keywords found in the sentence.
Type
number

calculateThreshold(similarityMatrix) → {number}

Calculates a similarity threshold for building the LexRank graph.
Parameters:
Name Type Description
similarityMatrix Array.<Array.<number>> A matrix representing the cosine similarities between sentences.
Source:
Returns:
The average similarity score, used as a threshold.
Type
number

extractKeywords(text, numKeywordsopt) → {Array.<string>}

Extracts the most relevant keywords from a given text.
Parameters:
Name Type Attributes Default Description
text string The input text to extract keywords from.
numKeywords number <optional>
10 The desired number of keywords to extract.
Source:
Returns:
An array of the top 'numKeywords' keywords.
Type
Array.<string>
Example
const document = "Natural language processing is awesome for text analysis.";
const keywords = extractKeywords(document, 5);
console.log(keywords); // Output: ['natural', 'language', 'processing', 'awesome', 'text']

extractKeywords(text, numKeywordsopt) → {Array.<string>}

Extracts the most frequent keywords from a given text.
Parameters:
Name Type Attributes Default Description
text string The input text to extract keywords from.
numKeywords number <optional>
10 The number of keywords to extract.
Source:
Returns:
An array of the top 'numKeywords' keywords, sorted by frequency.
Type
Array.<string>

getConfig() → {object}

Returns a copy of the current global configuration object.
Source:
Returns:
A copy of the configuration object.
Type
object

(async) getHuggingFace(text, model) → {number}

Calculates a sentiment score for the provided text using a Hugging Face sentiment analysis model. Loads the model dynamically and normalizes the output score.
Parameters:
Name Type Description
text string The input text to analyze.
model string The name of the Hugging Face model.
Source:
Throws:
If there are issues loading or using the Hugging Face model.
Type
Error
Returns:
A sentiment score between -1 (most negative) and 1 (most positive).
Type
number

getModel(modelName) → {object}

Retrieves a specific model's details by its name from the list of available models.
Parameters:
Name Type Description
modelName string The name of the model to search for.
Source:
Throws:
If the requested model is not found.
Type
Error
Returns:
The model object containing 'name' and 'URL'.
Type
object

getModelPath(modelName) → {string}

Retrieves a model path of a specific model by its name.
Parameters:
Name Type Description
modelName string The name of the model to search for.
Source:
Throws:
If the requested model is not found.
Type
Error
Returns:
A relative model path.
Type
string

getModelUrl(modelName) → {string}

Retrieves the URL of a specific model by its name.
Parameters:
Name Type Description
modelName string The name of the model to search for.
Source:
Throws:
If the requested model is not found.
Type
Error
Returns:
The URL where the model is hosted.
Type
string

getModels(typeopt) → {Array.<object>}

Retrieves a list of available sentiment analysis models, optionally filtered by type. Includes descriptions and type tags to aid in model selection. Results are cached for efficiency.
Parameters:
Name Type Attributes Default Description
type string <optional>
"" Filter models by a specific type (e.g., 'finance', 'news').
Source:
Returns:
An array of model objects with the structure: * name: The model's name (e.g., "sentiment-roberta-large-english") * path: Relative path suitable for TensorFlow.js * URL: Link to the model on Hugging Face. * description: A short explanation of the model. * type: The category of the model (e.g., "finance," "general")
Type
Array.<object>

getNatural(text) → {number}

Calculates a sentiment score using the Natural Node.js library with an AFINN-based analyzer. Normalizes the score to the standard [-1, 1] range.
Parameters:
Name Type Description
text string The input text to analyze.
Source:
Returns:
A sentiment score between -1 (most negative) and 1 (most positive).
Type
number

(async) getSentiment(text, engineopt, modelopt) → {number}

Calculates a sentiment score for the provided text using the selected sentiment analysis engine. Supports multiple engines: VADER, Hugging Face, Sentiment (AFINN-165), wink-sentiment, sentiment-analysis (AFINN-111), Natural Node, and ml-sentiment.
Parameters:
Name Type Attributes Default Description
text string The input text to analyze.
engine string <optional>
"vader" The engine to use. Options include: * 'vader', 'hugging-face', 'sentiment'(AFINN-165), 'wink-sentiment', * 'sentiment-analysis' (AFINN-111), 'natural'
model string <optional>
"" Name of the Hugging Face model (if 'hugging-face' engine selected).
Source:
Returns:
A sentiment score between -1 (most negative) and 1 (most positive).
Type
number

getSentimentAnalysis(text) → {number}

Calculates a sentiment score using the 'sentiment-analysis' npm module (AFINN-111 based).
Parameters:
Name Type Description
text string The input text to analyze.
Source:
Returns:
A sentiment score in a range specific to the 'sentiment-analysis' module. Output may need normalization to the [-1, 1] range.
Type
number

getSentimentNPM(text) → {number}

Calculates a sentiment score using the 'sentiment' npm module (AFINN-165 based).
Parameters:
Name Type Description
text string The input text to analyze.
Source:
Returns:
A sentiment score between -1 (most negative) and 1 (most positive).
Type
number

getVader(text) → {number}

Calculates a sentiment score for the provided text using the VADER sentiment analysis library.
Parameters:
Name Type Description
text string The input text to analyze.
Source:
Returns:
A sentiment score between -1 (most negative) and 1 (most positive).
Type
number

getWinkSentiment(text) → {number}

Calculates a sentiment score using the 'wink-sentiment' npm module. Normalizes score from the module's output range to the standard [-1, 1] range.
Parameters:
Name Type Description
text string The input text to analyze.
Source:
Returns:
A sentiment score between -1 (most negative) and 1 (most positive).
Type
number

(async) getWordEmbeddings(sentence) → {Promise.<Array>}

Get word embeddings for each word in a sentence using ALBERT.
Parameters:
Name Type Description
sentence string The sentence to process.
Source:
Returns:
A promise that resolves to an array of vectors, one for each word.
Type
Promise.<Array>

lexRankSentences(sentences) → {Array.<object>}

Computes LexRank scores for sentences to determine their importance within a text.
Parameters:
Name Type Description
sentences Array.<string> An array of sentences from the input text.
Source:
Returns:
Array of objects, each containing: * sentence: The original sentence. * rank: The calculated LexRank importance score.
Type
Array.<object>

manageErrors(text, numberOfSentences, positiveSentimentThreshold, negativeSentimentThreshold, positiveRankBoost, negativeRankBoost, lambdaopt)

Validates input parameters for text summarization functions, throwing errors for invalid input.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization.
numberOfSentences number The desired number of sentences in the summary.
positiveSentimentThreshold number The threshold for considering a sentiment as positive.
negativeSentimentThreshold number The threshold for considering a sentiment as negative.
positiveRankBoost number Multiplier for boosting the rank of positive sentences.
negativeRankBoost number Multiplier for boosting the rank of negative sentences.
lambda number <optional>
false An optional parameter.
Source:
Throws:
If any of the input parameters are invalid.
Type
Error
Example
manageErrors("This is a sample text", 3, 0.2, -0.1, 1.5, 1.2);

powerMethod(matrix, degrees, dampingopt, maxIteropt) → {Array.<number>}

Approximates the principal eigenvector (representing sentence importance) of a graph using the power iteration method.
Parameters:
Name Type Attributes Default Description
matrix Array.<Array.<number>> Represents a graph, often an adjacency or similarity matrix.
degrees Array.<number> Represents the out-degrees of each node in the graph.
damping number <optional>
0.85 Damping factor to prevent oscillations (probability of a 'random jump').
maxIter number <optional>
100 Maximum number of iterations for convergence.
Source:
Returns:
An array of scores approximating the importance of each node (sentence).
Type
Array.<number>

(async) sentimentExtractiveSummary(text, numberOfSentencesopt, positiveSentimentThresholdopt, negativeSentimentThresholdopt, positiveRankBoostopt, negativeRankBoostopt) → {string}

Generates a sentiment-aware extractive summary of a given text.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization.
numberOfSentences number <optional>
5 Desired number of sentences in the summary.
positiveSentimentThreshold number <optional>
0 Minimum sentiment score to consider a sentence positive.
negativeSentimentThreshold number <optional>
0 Maximum sentiment score to consider a sentence negative.
positiveRankBoost number <optional>
0 Boost applied to the ranking of positive sentences.
negativeRankBoost number <optional>
0 Boost applied to the ranking of negative sentence.
Source:
Throws:
If any input parameters are invalid.
Type
Error
Returns:
The generated summary.
Type
string
Example
const review = "This product is amazing! I have some minor issues, but overall, I would highly recommend it.";
const summary = await sentimentExtractiveSummary(review, 2);
console.log(summary); // Output: "This product is amazing! I would highly recommend it."

(async) sentimentExtractiveWeightedSummary(text, numberOfSentencesopt, positiveSentimentThresholdopt, negativeSentimentThresholdopt, positiveRankBoostopt, negativeRankBoostopt) → {string}

Generates a summary based on keyword frequency, emphasizing words in the document's "title". Also adjusts sentence importance based on their sentiment.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization.
numberOfSentences number <optional>
5 The desired number of sentences in the summary.
positiveSentimentThreshold number <optional>
0 Minimum sentiment score for positive sentiment consideration.
negativeSentimentThreshold number <optional>
0 Maximum sentiment score for negative sentiment consideration.
positiveRankBoost number <optional>
0 Boost applied to the ranking of positive sentences.
negativeRankBoost number <optional>
0 Boost applied to the ranking of negative sentences.
Source:
Throws:
If any input parameters are invalid.
Type
Error
Returns:
The generated summary.
Type
string

(async) sentimentLSASummary(text, numberOfSentencesopt, positiveSentimentThresholdopt, negativeSentimentThresholdopt, positiveRankBoostopt, negativeRankBoostopt) → {string}

Generates a sentiment-aware summary using Latent Semantic Analysis (LSA). Emphasizes sentences with strong positive or negative sentiments.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization.
numberOfSentences number <optional>
5 Desired number of sentences in the summary.
positiveSentimentThreshold number <optional>
0.1 Minimum sentiment score to consider a sentence positive.
negativeSentimentThreshold number <optional>
-0.1 Maximum sentiment score to consider a sentence negative.
positiveRankBoost number <optional>
2 Boost applied to the ranking of positive sentences.
negativeRankBoost number <optional>
2 Boost applied to the ranking of negative sentences.
Source:
Throws:
If any input parameters are invalid.
Type
Error
Returns:
The generated summary.
Type
string
Example
const article = "The new movie was terrible! The plot was confusing, and the acting was subpar. However, I really enjoyed the special effects.";
const summary = await sentimentLSASummary(article, 3);
console.log(summary);

(async) sentimentLexRankSummary(text, numberOfSentencesopt, positiveSentimentThresholdopt, negativeSentimentThresholdopt, positiveRankBoostopt, negativeRankBoostopt) → {string}

Generates a sentiment-aware summary using the LexRank algorithm. Prioritizes sentences with strong positive or negative sentiment.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization.
numberOfSentences number <optional>
5 Desired number of sentences in the summary.
positiveSentimentThreshold number <optional>
0 Minimum sentiment score to consider a sentence positive.
negativeSentimentThreshold number <optional>
0 Maximum sentiment score to consider a sentence negative.
positiveRankBoost number <optional>
0 Boost applied to the ranking of positive sentences.
negativeRankBoost number <optional>
0 Boost applied to the ranking of negative sentences.
Source:
Throws:
If any input parameters are invalid (delegated to 'manageErrors').
Type
Error
Returns:
The generated summary.
Type
string
Example
const review = "The food was delicious! The service was slow, but overall it was a great experience.";
const summary = await sentimentLexRankSummary(review, 2);
console.log(summary);

(async) sentimentMMRSummary(text, numberOfSentencesopt, lambdaopt, positiveSentimentThresholdopt, negativeSentimentThresholdopt, positiveRankBoostopt, negativeRankBoostopt) → {string}

Generates a sentiment-aware summary using the Maximum Marginal Relevance (MMR) algorithm. Emphasizes sentences with strong sentiment while ensuring diversity in the summary.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization.
numberOfSentences number <optional>
5 Desired number of sentences in the summary.
lambda number <optional>
0.7 Balances relevance and diversity in summary (higher lambda prioritizes relevance).
positiveSentimentThreshold number <optional>
0 Minimum sentiment score to consider a sentence positive.
negativeSentimentThreshold number <optional>
0 Maximum sentiment score to consider a sentence negative.
positiveRankBoost number <optional>
0 Boost applied to the ranking of positive sentences.
negativeRankBoost number <optional>
0 Boost applied to the ranking of negative sentences.
Source:
Throws:
If any input parameters are invalid (delegated to 'manageErrors').
Type
Error
Returns:
The generated summary.
Type
string
Example
const article = "The product has innovative features and works well. However, it is quite expensive, and the customer support could be better.";
const summary = await sentimentMMRSummary(article, 3);
console.log(summary);

(async) sentimentSummary(text, optionsopt) → {string}

Generates a summary based on a provided text, applying sentiment analysis. Prioritizes configuration settings and supports multiple summarization and sentiment engines.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization and analysis.
options object <optional>
{} Configuration options with the following properties: * summarizationEngine (string): The summarization engine to use (e.g., 'extractiveText'). * sentimentEngine (string): The sentiment engine to use (e.g., 'vader', 'hugging-face'). * sentimentEngineModel (string): Model name, if using the 'hugging-face' sentiment engine. * numberOfSentences (number): Desired number of sentences in the summary. * positiveSentimentThreshold (number): Minimum score to consider a sentence positive. * negativeSentimentThreshold (number): Maximum score to consider a sentence negative. * positiveRankBoost (number): Adjustment applied to the ranking of positive sentences. * negativeRankBoost (number): Adjustment applied to the ranking of negative sentences. * lambda (number): Parameter for certain summarization algorithms (like MMR).
Source:
Throws:
Potentially if configuration issues arise.
Type
Error
Returns:
The generated sentiment-aware summary.
Type
string

(async) sentimentTextRankSummary(text, numberOfSentencesopt, positiveSentimentThresholdopt, negativeSentimentThresholdopt, positiveRankBoostopt, negativeRankBoostopt) → {string}

Generates a sentiment-aware summary using the TextRank algorithm. Prioritizes sentences containing important words/phrases and those with strong sentiments.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization.
numberOfSentences number <optional>
5 Desired number of sentences in the summary.
positiveSentimentThreshold number <optional>
0 Minimum sentiment score to consider a sentence positive.
negativeSentimentThreshold number <optional>
0 Maximum sentiment score to consider a sentence negative.
positiveRankBoost number <optional>
0 Boost applied to the ranking of positive sentences.
negativeRankBoost number <optional>
0 Boost applied to the ranking of negative sentences.
Source:
Throws:
If any input parameters are invalid (delegated to 'manageErrors').
Type
Error
Returns:
The generated summary.
Type
string
Example
const review = "The scenery was beautiful but the hotel room was cramped. I really enjoyed the food though!";
const summary = await sentimentTextRankSummary(review, 2);
console.log(summary);

(async) sentimentTextRankWithWordEmbeddingsSummary(text, numberOfSentencesopt, positiveSentimentThresholdopt, negativeSentimentThresholdopt, positiveRankBoostopt, negativeRankBoostopt) → {string}

Generates a sentiment-aware summary using TextRank with word embeddings. Emphasizes sentences with semantically important words and strong sentiment.
Parameters:
Name Type Attributes Default Description
text string The input text for summarization.
numberOfSentences number <optional>
5 Desired number of sentences in the summary.
positiveSentimentThreshold number <optional>
0 Minimum sentiment score to consider a sentence positive.
negativeSentimentThreshold number <optional>
0 Maximum sentiment score to consider a sentence negative.
positiveRankBoost number <optional>
0 Boost applied to the ranking of positive sentences.
negativeRankBoost number <optional>
0 Boost applied to the ranking of negative sentences.
Source:
Throws:
If any input parameters are invalid (delegated to 'manageErrors').
Type
Error
Returns:
The generated summary.
Type
string
Example
const article = "The new technology is amazing but expensive. I love the design of the product!";
const summary = await sentimentTextRankWithWordEmbeddingsSummary(article, 2);
console.log(summary);

setup(options)

Updates the global configuration object by merging the provided options.
Parameters:
Name Type Description
options object An object containing configuration key-value pairs to add or override.
Source: