import { IntentSchema } from "./intent-schema" ; import { SampleUtterances } from "./sample-utterances" ; import { UtteredIntent } from "./sample-utterances" ; /**
 * Parses and interprets an interaction model
 * Takes in intentName schema and sample utterances from files
 * Then can take a phrase and create an intentName request based on it
 */ export class InteractionModel { public static fromFiles ( intentSchemaFile , sampleUtterancesFile , callback ) { let callbackCount = 0 ; let callbackError = null ; let intentSchema = null ; let sampleUtterances = null ; let done = function ( schema , utterances , error ) { callbackCount ++ ; if ( schema !== undefined && schema !== null ) { intentSchema = schema ; } if ( utterances !== undefined && utterances !== null ) { sampleUtterances = utterances ; } if ( error !== undefined && error !== null ) { callbackError = error ; } if ( callbackCount === 2 ) { if ( callbackError !== null ) { callback ( null , callbackError ) ; } else { callback ( new InteractionModel ( intentSchema , sampleUtterances ) ) ; } } } ; IntentSchema . fromFile ( intentSchemaFile , function ( schema , error ) { if ( error !== undefined && error !== null ) { console . error ( "Error loading Intent Schema!" ) ; console . error ( "Cause: " + error ) ; console . error ( ) ; } done ( schema , null , error ) ; } ) ; SampleUtterances . fromFile ( sampleUtterancesFile , function ( utterances , error ) { if ( error !== undefined && error !== null ) { console . error ( "Error loading Sample Utterances!" ) ; console . error ( "Cause: " + error ) ; console . error ( ) ; } done ( null , utterances , error ) ; } ) ; } public constructor ( public intentSchema , public sampleUtterances ) { } public intentForUtterance ( utterance ) { return this . sampleUtterances . intentForUtterance ( utterance ) ; } public hasIntent ( intent ) { return this . intentSchema . hasIntent ( intent ) ; } }