Created
February 13, 2025 17:18
-
-
Save steffensbola/e1f2f74b36a21ca86cb27fdb06824635 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is a hard coded implementation of a text classifier | |
| export class InstructionClassifier { | |
| private static questionWords = [ | |
| 'how', 'what', 'when', 'where', 'why', 'who', | |
| 'is', 'are', 'was', 'were', 'do', 'does', 'did', | |
| 'can', 'could', 'will', 'would', 'should', 'may', 'might' | |
| ]; | |
| private static instructionalVerbs = [ | |
| 'go', 'click', 'select', 'press', 'enter', 'do', | |
| 'navigate', 'choose', 'type', 'open', 'close', 'run', | |
| 'execute', 'follow', 'complete', 'create', 'write', | |
| 'look', 'view', 'refund', 'return', 'save' | |
| ]; | |
| private static sequenceKeywords = [ | |
| 'then', 'next', 'after', 'first', 'second', | |
| 'finally', 'lastly', 'step', 'steps', 'either', 'or' | |
| ]; | |
| private static instructionalPatterns = [ | |
| /click\s+["'].+?["']/i, | |
| /select\s+.+?\s+from/i, | |
| /enter\s+.+/i, | |
| /choose\s+.+/i, | |
| /look\s+up/i, | |
| /view\s+.+/i, | |
| /refund\s+.+/i, | |
| /return\s+.+/i | |
| ]; | |
| private static nonInstructionalIndicators = [ | |
| 'could you', 'please', 'note that', 'typically', 'depending on', | |
| 'this will', 'help me', 'provide you', 'confirm', 'before i', | |
| 'after you', 'if you', 'when you', 'as soon as' | |
| ]; | |
| public static isInstructional(input: string): boolean { | |
| const trimmed = input.trim(); | |
| if (trimmed === '') return false; | |
| if (this.isQuestion(trimmed)) return false; | |
| if (this.hasNonInstructionalIndicators(trimmed)) return false; | |
| return this.hasInstructionalStructure(trimmed); | |
| } | |
| private static isQuestion(input: string): boolean { | |
| if (input.endsWith('?')) return true; | |
| const firstWord = input.split(/\s+/)[0].toLowerCase(); | |
| return this.questionWords.includes(firstWord); | |
| } | |
| private static hasNonInstructionalIndicators(input: string): boolean { | |
| const lowerInput = input.toLowerCase(); | |
| return this.nonInstructionalIndicators.some(indicator => | |
| lowerInput.includes(indicator) | |
| ); | |
| } | |
| private static hasInstructionalStructure(input: string): boolean { | |
| const lowerInput = input.toLowerCase(); | |
| // Check for instructional patterns | |
| if (this.instructionalPatterns.some(pattern => pattern.test(input))) { | |
| return true; | |
| } | |
| // Check for imperative verbs at sentence start | |
| const startsWithVerb = this.instructionalVerbs.some(verb => | |
| new RegExp(`^${verb}\\b`, 'i').test(input) | |
| ); | |
| // Check for sequence indicators | |
| const hasSequence = this.sequenceKeywords.some(keyword => | |
| lowerInput.includes(keyword) | |
| ); | |
| // Check for command-like structure with line breaks or numbers | |
| const hasStepStructure = /(\n|\d+\.|\d+\))/.test(input); | |
| // Only return true if there's a clear instructional structure | |
| return (startsWithVerb || hasSequence || hasStepStructure) && | |
| !this.hasNonInstructionalIndicators(input); | |
| } | |
| } | |
| // Example usage: | |
| console.info('=== should be false ==='); | |
| console.log(InstructionClassifier.isInstructional('')); | |
| console.log(InstructionClassifier.isInstructional('How can I help you today')); // false | |
| console.log(InstructionClassifier.isInstructional(`Before I provide instructions on processing a refund, could you please confirm who your payment processor is? | |
| This will help me provide you with the most accurate guidance for your specific setup.`)); | |
| console.log(InstructionClassifier.isInstructional(`Note that credit card refunds typically take 2-10 business days to process depending on the processor and client's bank.`)); | |
| console.log(InstructionClassifier.isInstructional(`The ability to cancel a membership and any associated fees would be determined by the specific agreement terms set by your | |
| facility. These terms should be outlined in your membership contract. Could you check your membership agreement or contract for the cancellation policy?`)); | |
| console.log(InstructionClassifier.isInstructional(`Could you clarify whether you're asking about a client's membership at a facility, or about a Mindbody software subscription? `); | |
| console.info('=== should be true ==='); | |
| console.log(InstructionClassifier.isInstructional('Go to menu, then submenu. Click A, Do this')); // true | |
| console.log(InstructionClassifier.isInstructional(`Look up the transaction from either the client's profile or Settled Transactions report | |
| Click "View/Refund" or "Return All" | |
| Enter a reason for the return | |
| Click "Choose Refund Method" and select the client's credit card from the dropdown | |
| Enter the refund amount and click "Save"`)); | |
| console.log(InstructionClassifier.isInstructional(`Create a new service category: | |
| Go to Services & Products > Appointment Types | |
| Click "Add New Service Category" | |
| Name it "Desk Staff Schedule" or similar | |
| Ensure clients cannot book this online | |
| Set up staff availability: | |
| Go to Staff and select the staff member | |
| Check "Instructor" box in Settings | |
| Click Appointment Availability and Add New Schedule | |
| Select the service category created | |
| Set date range and times | |
| Choose privacy settings | |
| Double-check the schedule in Appointments tab and adjust as needed for breaks/lunch periods.`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment