MCPcopy
hub / github.com/Doorman11991/smallcode / extractKeywords

Function extractKeywords

src/compiled/features/context_retriever.js:67–101  ·  view source on GitHub ↗

* Extract search keywords from a user message. * Filters stop words, returns camelCase and PascalCase words preferentially.

(message)

Source from the content-addressed store, hash-verified

65 * Filters stop words, returns camelCase and PascalCase words preferentially.
66 */
67function extractKeywords(message) {
68 const STOP = new Set([
69 'the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
70 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could', 'should',
71 'may', 'might', 'shall', 'can', 'need', 'dare', 'ought', 'used', 'it', 'its',
72 'this', 'that', 'these', 'those', 'i', 'me', 'my', 'we', 'our', 'you', 'your',
73 'he', 'she', 'they', 'them', 'their', 'what', 'which', 'who', 'whom', 'when',
74 'where', 'why', 'how', 'all', 'both', 'each', 'few', 'more', 'most', 'other',
75 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too',
76 'very', 'just', 'in', 'on', 'at', 'by', 'for', 'with', 'about', 'against',
77 'to', 'from', 'up', 'down', 'of', 'off', 'out', 'over', 'under', 'into', 'and',
78 'or', 'but', 'if', 'then', 'else', 'file', 'files', 'code', 'function', 'class',
79 'please', 'make', 'show', 'tell', 'give', 'get', 'set', 'run', 'use', 'add',
80 'fix', 'find', 'look', 'check', 'help', 'want', 'need', 'try', 'let', 'create',
81 ]);
82
83 const words = message.split(/[\s,.\-_/\\()[\]{}'"`!?;:]+/);
84 const keywords = [];
85
86 // Prefer CamelCase/PascalCase first (likely symbol names)
87 for (const w of words) {
88 if (w.length >= 3 && /[A-Z]/.test(w) && !STOP.has(w.toLowerCase())) {
89 keywords.push(w);
90 }
91 }
92
93 // Then add other meaningful lowercase words
94 for (const w of words) {
95 if (w.length >= 4 && !/[A-Z]/.test(w) && !STOP.has(w.toLowerCase()) && !keywords.includes(w)) {
96 keywords.push(w.toLowerCase());
97 }
98 }
99
100 return keywords.slice(0, 5);
101}
102
103module.exports = { retrieveContext, extractKeywords };

Callers 1

retrieveContextFunction · 0.85

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected