Text Analysis

Generate Ngrams

Extracts n-grams (sequential word combinations) from text for linguistic analysis and feature extraction. Use via MCP in Cursor or Windsurf, or call GET /v1/text/ngrams directly. Example: "the quick brown fox" → bigrams ["the quick", "quick brown", "brown fox"]. Returns structured JSON with configurable n-gram size and preprocessing options.

API Endpoint

GET /v1/text/ngrams

Code Examples

curl "https://tinyfn.io/v1/text/ngrams" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/text/ngrams', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/text/ngrams',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's text analysis tools:

{
  "mcpServers": {
    "tinyfn-text": {
      "url": "https://tinyfn.io/mcp/text",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

What are n-grams and how are they useful in text analysis?

N-grams are contiguous sequences of n words from text. Unigrams are single words, bigrams are word pairs, trigrams are three-word sequences. They're essential for language modeling, feature extraction, and text similarity analysis.

How do I generate bigrams and trigrams using the MCP tool?

Specify the n parameter (2 for bigrams, 3 for trigrams) when calling the tool. The API processes your text and returns all sequential word combinations of the specified length as a structured array.

Does the n-gram generator handle punctuation and case sensitivity?

Yes, the tool includes preprocessing options to normalize case, remove punctuation, and handle special characters. Configure these settings to match your analysis requirements.

What's the maximum n-gram size supported by this tool?

The tool supports n-gram sizes from 1 (unigrams) up to reasonable limits based on text length. Larger n-grams become increasingly sparse and less useful for most applications.

Can I use n-grams for text similarity comparison in AI workflows?

Absolutely. N-grams create feature vectors for comparing document similarity, detecting plagiarism, or training language models. Many AI agents use n-gram features for text classification tasks.

Try Generate Ngrams Now

Get your free API key and start using Generate Ngrams in seconds.

Get Free API Key