Example #1
0
TestCases::TestCases(const string &outputFile)
: m_testValidation(false),
  m_outputFile(outputFile),
  m_testFileAdded(false),
  m_aimlFileAdded(false),
  m_aimlGraphCreated(false),
  m_builder(m_aimlFacade.getGraphBuilder())
{

   /* Give the address to Rebecca for usesage.
	* Rebecca DOES NOT delete it.  
	*/
	m_builder.setCallBacks(&m_callback);

   /*
    * Get a handle to our global instance
    * of our arguments
    */
    Arguments *arguments = Arguments::getInstance();



   /* 
	* Set the schemas for the AIML XML (AIML.xsd)
	* and for Rebecca's own configuration files.
	* The schema's have to be relative to where the files
	* you are going to parse are going to be at.
	*/
    m_builder.setAIMLSchema(arguments->getAimlSchemaPath().c_str());
    m_builder.setCommonTypesSchema(arguments->getCommonTypesSchemaPath().c_str());
    m_builder.setBotConfigurationSchema(arguments->getBotConfigurationSchemaPath().c_str());

   /* 
	* Set that "yes" we do want to do XML validation on
	* both the AIML XML and Rebecca's own configuration 
	* files.
	*/
	m_builder.setAIMLValidation();
	m_builder.setBotConfigurationValidation();
	
   /*
	* Parse Rebecca's configuration files to setup 
	* Rebecca's ability to handle input subsitutions, 
	* what a sentence splitter is, and what bot properties
	* she should have.
	*/
    string substitutions_xml = arguments->getConfigurationDirectory() + "/substitutions.xml";
    m_builder.parseSubstitutionFile(substitutions_xml.c_str());

    string sentence_splitters_xml = arguments->getConfigurationDirectory() + "/sentence-splitters.xml";
    m_builder.parseSentenceSplitterFile(sentence_splitters_xml.c_str());

    string properties_xml = arguments->getConfigurationDirectory() + "/properties.xml";
    m_builder.parsePropertiesFile(properties_xml.c_str());

	m_testParser.reset(new SAXParser);
	m_testDocumentHandler.reset(new TestCasesHandler(m_outputFile, m_builder));
	
///@todo make this into its own error class
//	m_testErrorHandler.reset(new TestCasesHandler(m_outputFile, m_builder));
//	m_testParser->setErrorHandler(m_testErrorHandler.get());

	m_testParser->setDocumentHandler(m_testDocumentHandler.get());
}
Example #2
0
void AIMLEngine::initAIML()
{
    try
    {
        //Create a new AIML engine
        m_aiml = new AimlFacade;

        /*
        * Get the GraphBuilder concrete class that
        * was created inside of AimlFacade.
        * DO NOT try to delete GraphBuilder.  Let
        * AimlFacade handle that when it falls out
        * of scope.
        */
        GraphBuilder &builder = m_aiml->getGraphBuilder();

        /*
         * Give the address to Rebecca for usesage.
        * Rebecca DOES NOT delete it.
        */
        builder.setCallBacks(&m_callback);

        /*
        * Get a handle to our global instance
        * of our arguments
        */
        Arguments *arguments = Arguments::getInstance();

        /*
        * Set the schemas for the AIML XML (AIML.xsd)
        * and for Rebecca's own configuration files.
        * The schema's have to be relative to where the files
        * you are going to parse are going to be at.
        */
        builder.setAIMLSchema(arguments->getAimlSchemaPath().c_str());
        builder.setCommonTypesSchema(arguments->getCommonTypesSchemaPath().c_str());
        builder.setBotConfigurationSchema(arguments->getBotConfigurationSchemaPath().c_str());

        /*
        * Set that "yes" we do want to do XML validation on
        * both the AIML XML and Rebecca's own configuration
        * files.
        */
        builder.setAIMLValidation();
        builder.setBotConfigurationValidation();

        /*
        * Parse Rebecca's configuration files to setup
        * Rebecca's ability to handle input subsitutions,
        * what a sentence splitter is, and what bot properties
        * she should have.
        */
        string substitutions_xml = arguments->getConfigurationDirectory() + "/substitutions.xml";
        builder.parseSubstitutionFile(substitutions_xml.c_str());

        string sentence_splitters_xml = arguments->getConfigurationDirectory() + "/sentence-splitters.xml";
        builder.parseSentenceSplitterFile(sentence_splitters_xml.c_str());

        string properties_xml = arguments->getConfigurationDirectory() + "/properties.xml";
        builder.parsePropertiesFile(properties_xml.c_str());

        /*
         * Get the botName which should be Rebecca since that is
         * the name give in the configuration file properties.xml
         * which we parsed above.
         */
        string botName = builder.getBotPredicate("name").c_str();

        //Emit what the bot name is
        emit addBotName(botName.c_str());
    }
    /*
    * All the exceptions are grouped here but you
    * might not want this since it's a bit harder
    * to determine where they came from.
    */
    catch(DirectoryNotFoundException &e)
    {
        emit addText("[A Directory Was Not Found Terminating]");
        QString exception("[");
        exception += e.what();
        exception += "]";
        emit addText(exception);
    }
    catch(FileNotFoundException &e)
    {
        emit addText("[A File Was Not Found Terminating]");
        QString exception("[");
        exception += e.what();
        exception += "]";
        emit addText(exception);
    }
    catch(IllegalArgumentException &e)
    {
        emit addText("[IllegalArgument Found Terminating]");
        QString exception("[");
        exception += e.what();
        exception += "]";
        emit addText(exception);
    }
    catch(InitializationException &e)
    {
        emit addText("[Initialization Exception Found Terminating]");
        QString exception("[");
        exception += e.what();
        exception += "]";
        emit addText(exception);
    }
    catch(XMLErrorException &e)
    {
        emit addText("[XMLError Exception Found Terminating]");
        QString exception("[");
        exception += e.what();
        exception += "]";
        emit addText(exception);
    }
    catch(Exception &e)
    {
        emit addText("[An uknown exception occured, Terminating program]");
        QString exception("[");
        exception += e.what();
        exception += "]";
        emit addText(exception);
    }
}