Example #1
0
int do_ask(ai::PL::KnowledgeBase &kb, int interactive, char *buf, std::istream &in, std::ostream &out, const char *prompt)
{
    ai::PL::Symbol::State rval;
    ai::PL::KnowledgeBase question;
    char *q = 0;
    unsigned int len = strlen(prompt);

    if(strlen(buf) > len)
    {
        q = &buf[len];
    }
    else
    {
        if(interactive)
        {
            out << prompt << "> " << std::flush;
        }
        in.getline(buf, BUF_SIZE);
        q = buf;
    }
    question.AddSentence(q);
    if(!interactive)
    {
        out << prompt << " " << *(question.GetSentences()[0]) << std::endl;
    }
    if(strcmp(prompt, "dpll") == 0)
    {
        rval = kb.DPLL_Entails(question);
    }
    else if(strcmp(prompt, "ask2") == 0)
    {
        rval = kb.TT_Entails_Pruned(question);
    }
    else if(strcmp(prompt, "ask") == 0)
    {
        rval = kb.TT_Entails(question);
    }
    else
    {
        out << "Unknown ask mode: " << prompt << std::endl;
        rval = ai::PL::Symbol::UNKNOWN;
    }
    if(rval == ai::PL::Symbol::KNOWN_TRUE)
    {
        out << "YES, " << q << " is entailed." << std::endl;
    }
    else
    {
        out << "NO, " << q << " is not entailed." << std::endl;
    }
    out << kb.GetCount() << " evaluations."  << std::endl;
    return 0;
}
Example #2
0
void tt_entails_test_2_aux(ai::PL::KnowledgeBase &kb,
			   ai::PL::KnowledgeBase &alpha)
{
  ai::PL::Symbol::State rval;

  rval = kb.TT_Entails_Pruned(alpha);
  
  std::cout << "KB" << std::endl << kb 
	    << "alpha" << std::endl << alpha
	    << "result: " << rval
	    << std::endl
	    << std::endl;
}