X Enterprises
Composables

useMentionedTerms

Extract top-N most-mentioned meaningful terms from a list of reviews using word-frequency analysis with stopword filtering.

useMentionedTerms

Pure function (no reactive state) that extracts the top-N most-mentioned meaningful terms from a list of reviews. Underpins the XRDProfileMentionedTerms component but is exported for general use.

Usage

import { useMentionedTerms } from '#imports'

const reviews = [
  { comment: 'The pasta was incredible! Best Italian food...' },
  { comment: 'Great pasta, wonderful ambiance.' },
]

const { terms } = { terms: useMentionedTerms(reviews, 8) }
// terms = [
//   { word: 'pasta', count: 2 },
//   { word: 'wonderful', count: 1 },
//   ...
// ]

Signature

function useMentionedTerms(
  reviews: any[],
  limit?: number,    // default 8
  minLength?: number // default 4
): Array<{ word: string; count: number }>

Algorithm

  1. Lowercase + tokenize each review's comment (or text) on non-letter chars
  2. Drop tokens shorter than minLength chars
  3. Drop tokens in the STOPWORDS set (common English function words)
  4. Drop pure-number tokens
  5. Count remaining tokens
  6. Sort by count desc, then alphabetically
  7. Return top limit

Customization

To change the stopword list, edit the STOPWORDS set in app/composables/useMentionedTerms.ts. The default list covers the most common English function words; extend as needed for domain-specific filtering.

Notes

  • Case-insensitive ("Pasta" and "pasta" merge into one count)
  • Punctuation stripped (commas, periods, etc.)
  • Apostrophes preserved (so "don't" stays one token)
  • Hyphens split tokens (so "high-quality" becomes "high" and "quality")
  • Pure numbers excluded (avoid "2024" showing up as a "term")

AI Context

composable: useMentionedTerms
package: "@xenterprises/nuxt-x-restaurants"
use-when: >
  Building any "what reviewers mention" / tag cloud feature on restaurant
  reviews. Pure function, no reactive state. Tokenizes, lowercases,
  filters stopwords + short words, returns top N by frequency.
Copyright © 2026