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
- Lowercase + tokenize each review's
comment(ortext) on non-letter chars - Drop tokens shorter than
minLengthchars - Drop tokens in the
STOPWORDSset (common English function words) - Drop pure-number tokens
- Count remaining tokens
- Sort by count desc, then alphabetically
- 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.
useDomain
Builds and returns typed API endpoint methods for all restaurant data resources plus domain/site config.
Schema.org JSON-LD & Site Meta
Schema composables — emit Article, Review, Product, ItemList, BreadcrumbList JSON-LD for Google rich results, plus a useSiteMeta helper that consolidates title/description/OG/Twitter Card boilerplate.
