Socket
Book a DemoInstallSign in
Socket

@apto-space/moving-ngrams

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apto-space/moving-ngrams

A utility package for generating all possible n-gram combinations from a sequence of words, useful for search engine query analysis and natural language processing tasks.

0.0.1
latest
npmnpm
Version published
Maintainers
0
Created
Source

moving-ngrams

A utility package for generating all possible n-gram combinations from a sequence of words, useful for search engine query analysis and natural language processing tasks.

Description

moving-ngrams helps you analyze text by generating all possible meaningful combinations of consecutive words. This is particularly useful for:

  • Search engine query analysis
  • Automatic keyphrase extraction
  • Faceted search implementation
  • Natural language understanding

Installation

# Using bun
bun add moving-ngrams

# Using npm
npm install moving-ngrams

# Using yarn
yarn add moving-ngrams

Usage

import { movingNgrams } from 'moving-ngrams';

// Example 1: Simple phrase analysis
const result = movingNgrams(['hello', 'world']);
console.log(result);
/* Output:
[
  [['hello'], ['world']],      // Individual words
  [['hello', 'world']]         // Combined phrase
]
*/

// Example 2: Search query analysis
const searchQuery = movingNgrams(['elon', 'musk', 'san', 'francisco']);
console.log(searchQuery);
/* Output will include all possible combinations like:
- [['elon'], ['musk'], ['san'], ['francisco']]
- [['elon', 'musk'], ['san'], ['francisco']]
- [['elon'], ['musk', 'san'], ['francisco']]
- [['elon'], ['musk'], ['san', 'francisco']]
... and more combinations
*/

Use Cases

1. Search Query Analysis

When users enter a search query like "Elon Musk San Francisco", the package helps you analyze all possible meaningful combinations:

  • Individual terms: "Elon", "Musk", "San", "Francisco"
  • Compound terms: "Elon Musk", "San Francisco"
  • Mixed combinations: ["Elon Musk", "San Francisco"], ["Elon", "Musk San Francisco"], etc.

This is particularly useful for:

  • Improving search relevance
  • Understanding user intent
  • Supporting multi-term matching

2. Keyphrase Extraction

When analyzing text content, you can use this to:

  • Extract potential keyphrases
  • Identify compound terms
  • Generate search indices

API

function movingNgrams(words: string[]): string[][][]
  • Input: Array of words
  • Output: Array of all possible combinations where each combination is an array of word groups

License

MIT

This project was created using Bun v1.1.41.

FAQs

Package last updated on 09 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.