@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
300 lines • 7.78 kB
JavaScript
/**
* Language Pattern Definitions for AI Agent and Human Variations
*
* IMPLEMENTATION STATUS:
* COMPLETE: All 4 language pattern categories
*
* Last Updated: July 3, 2025
*/
/**
* AI Agent verbose patterns - common AI phrasing to simplify
*/
export const AI_AGENT_PATTERNS = [
// Polite/verbose introductions
{
pattern: /(?:could you |can you |would you |please |kindly |i would like to |i want to |i need to )/gi,
replacement: '',
type: 'normalize',
category: 'ai_verbose'
},
// Verbose connectors
{
pattern: /(?:in order to |for the purpose of |with the intention of )/gi,
replacement: 'to',
type: 'normalize',
category: 'ai_verbose'
},
// Redundant clarifications
{
pattern: /(?:that are |which are |that have been |which have been )/gi,
replacement: 'that',
type: 'normalize',
category: 'ai_verbose'
},
// Verbose time expressions
{
pattern: /(?:during the period of |throughout the time of |in the timeframe of )/gi,
replacement: 'during',
type: 'normalize',
category: 'ai_verbose'
},
// AI uncertainty markers
{
pattern: /(?:it seems that |it appears that |apparently |presumably |possibly )/gi,
replacement: '',
type: 'normalize',
category: 'ai_verbose'
},
// Verbose entity references
{
pattern: /(?:entities of type |items that are |objects which are )/gi,
replacement: '',
type: 'normalize',
category: 'ai_verbose'
}
];
/**
* Human casual language patterns
*/
export const HUMAN_CASUAL_PATTERNS = [
// Casual abbreviations
{
pattern: /\bfigs\b/gi,
replacement: 'flags',
type: 'normalize',
category: 'human_casual'
},
{
pattern: /\bexps?\b/gi,
replacement: 'experiments',
type: 'normalize',
category: 'human_casual'
},
{
pattern: /\benvs?\b/gi,
replacement: 'environments',
type: 'normalize',
category: 'human_casual'
},
// Casual phrasing
{
pattern: /\bgrab\b/gi,
replacement: 'get',
type: 'normalize',
category: 'human_casual'
},
{
pattern: /\bpull up\b/gi,
replacement: 'show',
type: 'normalize',
category: 'human_casual'
},
{
pattern: /\bcheck out\b/gi,
replacement: 'show',
type: 'normalize',
category: 'human_casual'
},
// Slang and informal
{
pattern: /\bstuff\b/gi,
replacement: 'items',
type: 'normalize',
category: 'human_casual'
},
{
pattern: /\bthingies?\b/gi,
replacement: 'entities',
type: 'normalize',
category: 'human_casual'
},
// Informal time references
{
pattern: /\ba bit ago\b/gi,
replacement: 'recently',
type: 'normalize',
category: 'human_casual'
},
{
pattern: /\bages ago\b/gi,
replacement: 'long ago',
type: 'normalize',
category: 'human_casual'
}
];
/**
* Technical jargon patterns
*/
export const TECHNICAL_PATTERNS = [
// Technical abbreviations
{
pattern: /\bA\/B\b/gi,
replacement: 'AB',
type: 'normalize',
category: 'technical'
},
{
pattern: /\bCTR\b/gi,
replacement: 'click through rate',
type: 'normalize',
category: 'technical'
},
{
pattern: /\bMAU\b/gi,
replacement: 'monthly active users',
type: 'normalize',
category: 'technical'
},
// Technical terms
{
pattern: /\bprod\b/gi,
replacement: 'production',
type: 'normalize',
category: 'technical'
},
{
pattern: /\bdev\b/gi,
replacement: 'development',
type: 'normalize',
category: 'technical'
},
{
pattern: /\bQA\b/gi,
replacement: 'quality assurance',
type: 'normalize',
category: 'technical'
},
// SQL-like syntax in natural language
{
pattern: /\bSELECT\s+\*\s+FROM\b/gi,
replacement: 'show all from',
type: 'normalize',
category: 'technical'
},
{
pattern: /\bWHERE\b/gi,
replacement: 'where',
type: 'normalize',
category: 'technical'
},
{
pattern: /\bGROUP BY\b/gi,
replacement: 'grouped by',
type: 'normalize',
category: 'technical'
}
];
/**
* Question word patterns
*/
export const QUESTION_PATTERNS = [
// Question starters
{
pattern: /^(?:what|which|where|when|who|how|why)\s+/i,
replacement: '',
type: 'extract',
category: 'question'
},
// Question endings
{
pattern: /\?+$/,
replacement: '',
type: 'normalize',
category: 'question'
},
// Embedded questions
{
pattern: /\bcan you tell me\b/gi,
replacement: 'show',
type: 'normalize',
category: 'question'
},
{
pattern: /\bdo you know\b/gi,
replacement: 'find',
type: 'normalize',
category: 'question'
},
// Indirect questions
{
pattern: /\bi(?:'m| am) (?:wondering|curious|interested in)\b/gi,
replacement: 'show',
type: 'normalize',
category: 'question'
}
];
/**
* Apply all language patterns to normalize query
*/
export function applyLanguagePatterns(query) {
let normalized = query;
const appliedPatterns = [];
const allPatterns = [
...AI_AGENT_PATTERNS,
...HUMAN_CASUAL_PATTERNS,
...TECHNICAL_PATTERNS,
...QUESTION_PATTERNS
];
for (const langPattern of allPatterns) {
if (langPattern.pattern.test(normalized)) {
if (langPattern.type === 'normalize' && langPattern.replacement !== undefined) {
normalized = normalized.replace(langPattern.pattern, langPattern.replacement);
appliedPatterns.push({
pattern: langPattern.pattern.source,
category: langPattern.category
});
}
}
}
// Clean up extra spaces
normalized = normalized.trim().replace(/\s+/g, ' ');
return { normalized, appliedPatterns };
}
/**
* Detect query style
*/
export function detectQueryStyle(query) {
const scores = {
ai_verbose: 0,
human_casual: 0,
technical: 0,
standard: 0
};
// Check AI patterns
for (const pattern of AI_AGENT_PATTERNS) {
if (pattern.pattern.test(query)) {
scores.ai_verbose += 1;
}
}
// Check human casual patterns
for (const pattern of HUMAN_CASUAL_PATTERNS) {
if (pattern.pattern.test(query)) {
scores.human_casual += 1;
}
}
// Check technical patterns
for (const pattern of TECHNICAL_PATTERNS) {
if (pattern.pattern.test(query)) {
scores.technical += 1;
}
}
// Find dominant style
let maxScore = 0;
let dominantStyle = 'standard';
for (const [style, score] of Object.entries(scores)) {
if (score > maxScore) {
maxScore = score;
dominantStyle = style;
}
}
// Calculate confidence based on pattern matches
const totalPatterns = AI_AGENT_PATTERNS.length +
HUMAN_CASUAL_PATTERNS.length +
TECHNICAL_PATTERNS.length;
const confidence = maxScore > 0 ? Math.min(maxScore / 3, 1.0) : 0.5;
return {
style: dominantStyle,
confidence
};
}
//# sourceMappingURL=LanguagePatterns.js.map