/** * @fileoverview Main orchestrator for the SEEKTOPIC keyphrase extraction pipeline. * Coordinates cleaning, segmentation, LLM extraction, and fallback n-gram ranking. */ import type { NgramMap, KeyphraseEntry, SentenceEntry, SEEKTOPICOptions, SEEKTOPICResult, } from "./types"; import { splitTextToSentences } from "../tokenize/text-to-sentences"; import { convertTextToTokens } from "../tokenize/text-to-topic-tokens"; import { extractNounEdgeGrams } from "./ngrams"; import { foldSubphrases } from "./fold-keyphrases"; import { weightKeyphrasesBySpecificity } from "./weight-keyphrases"; import { rankSentencesCentralToKeyphrase } from "./rank-sentences-keyphrases"; import { weighRelevanceConceptVectorMultiple } from "./vector-search"; /** * ### SEEKTOPIC \u2014 Keyphrase & Sentence Extraction * * Pulls the most important phrases and sentences out of any document. * Given raw text, it returns a ranked list of key concepts (e.g. "neural * network", "climate change") and, optionally, the sentences that best * summarise the document around those concepts. * * * * **How it works \u2014 8-step pipeline:** * * 1. **Clean** \u2014 strip HTML tags and entities. * 2. **Split** \u2014 break text into sentences, respecting abbreviations and URLs. * 3. **Topic Extraction** *(LLM Path)* \u2014 sends the first 5000 words to an LLM * to extract the most descriptive key topic phrases labeling the document. * 4. **Vector Search** *(LLM Path)* \u2014 calculates cosine similarity embeddings * for all sentences vs topic phrases, finding the top relevant sentences per topic. * 5. **Tokenise & Extract** *(Fallback)* \u2014 if LLM fails, identify noun-anchored * n-grams (1-N words). * 6. **Score & Fold** *(Fallback)* \u2014 weight phrases and merge subsumed phrases. * 7. **Re-weight** *(Fallback)* \u2014 boost Wikipedia entities and rare domain terms. * 8. **TextRank** *(Fallback)* \u2014 build sentence similarity graph and run random walk. * *