/*
* BITUTest.cxxtest
*
* Created on: Oct 20, 2014
* Authors: misgana
^ : Nil Geisweiller (2015-2016)
*/
#include <opencog/ure/backwardchainer/BIT.h>
#include <opencog/guile/SchemeEval.h>
#include <opencog/atomspace/AtomSpace.h>
#include <cxxtest/TestSuite.h>
using namespace std;
using namespace opencog;
//#define DEBUG 1
#define al _as->add_link
#define an _as->add_node
class BITUTest: public CxxTest::TestSuite
{
private:
AtomSpacePtr _as;
SchemeEval _eval;
Handle closed_lambda_introduction_rule_h;
Handle implication_and_lambda_factorization_rule_h;
Handle unary_specialization_rule_h;
public:
BITUTest() : _as(createAtomSpace()), _eval(_as)
{
logger().set_level(Logger::DEBUG);
logger().set_timestamp_flag(false);
// logger().set_sync_flag(true);
logger().set_print_to_stdout_flag(true);
string cur_pp_dir = string(PROJECT_SOURCE_DIR),
cur_p_dir = cur_pp_dir + "/tests",
cur_dir = cur_p_dir + "/ure",
rule_dir = cur_dir + "/rules",
backwardchainer_dir = cur_dir + "/backwardchainer",
scm_dir = backwardchainer_dir + "/scm";
vector<string> load_paths = {cur_pp_dir,
cur_p_dir,
rule_dir,
backwardchainer_dir,
scm_dir};
for (string& p : load_paths)
{
string eval_str = string("(add-to-load-path \"") + p + string("\")");
_eval.eval(eval_str);
}
_eval.eval("(use-modules (opencog))");
// _eval.eval("(use-modules (opencog ure))");
// Load closed-lambda-introduction-rule
std::string eval_result = _eval.eval("(load-from-path \"closed-lambda-introduction-rule.scm\")");
closed_lambda_introduction_rule_h =
_eval.eval_h("(MemberLink (stv 1 1)"
" closed-lambda-introduction-rule-name"
" (ConceptNode \"URE\"))");
// Load implication-and-lambda-factorization-rule
eval_result = _eval.eval("(load-from-path \"implication-and-lambda-factorization-rule.scm\")");
implication_and_lambda_factorization_rule_h =
_eval.eval_h("(MemberLink (stv 1 1)"
" implication-and-lambda-factorization-rule-name"
" (ConceptNode \"URE\"))");
// Load implication-and-lambda-factorization-rule
eval_result = _eval.eval("(load-from-path \"unary-specialization-rule.scm\")");
unary_specialization_rule_h =
_eval.eval_h("(MemberLink (stv 1 1)"
" unary-specialization-rule-name"
" (ConceptNode \"URE\"))");
// Load bit.scm
eval_result = _eval.eval("(load-from-path \"bit.scm\")");
}
~BITUTest()
{
_as->clear();
}
void setUp();
void tearDown();
void test_abbreviate();
void test_get_leaves();
void test_expand_1();
void test_expand_2();
void test_expand_3();
void test_has_cycle();
};
void BITUTest::setUp()
{
}
void BITUTest::tearDown()
{
}
void BITUTest::test_abbreviate()
{
logger().info("BEGIN TEST: %s", __FUNCTION__);
size_t tg_size = 20;
std::string rule_name = "back-predictive-implication-direct-introduction";
std::string abbr_rule_name = AndBIT::abbreviate(rule_name, tg_size);
logger().debug() << "rule_name = " << rule_name;
logger().debug() << "abbr_rule_name = " << abbr_rule_name;
TS_ASSERT_EQUALS(abbr_rule_name.size(), tg_size);
}
void BITUTest::test_get_leaves()
{
logger().info("BEGIN TEST: %s", __FUNCTION__);
AndBIT andbit(_eval.eval_h("fcs-1"));
HandleSet result;
for (const auto& el : andbit.leaf2bitnode)
result.insert(el.first);
HandleSet expected = {
_eval.eval_h("(LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
")"),
_eval.eval_h("(LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")"
" )"
" )"
")")};
logger().debug() << "result = " << oc_to_string(result);
logger().debug() << "expected = " << oc_to_string(expected);
TS_ASSERT_EQUALS(result, expected);
}
void BITUTest::test_expand_1()
{
logger().info("BEGIN TEST: %s", __FUNCTION__);
AndBIT andbit(_eval.eval_h("fcs-2"));
Handle leaf = _eval.eval_h("(LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\"))))");
Rule closed_lambda_introduction_rule(closed_lambda_introduction_rule_h);
RuleTypedSubstitutionMap rules =
closed_lambda_introduction_rule.unify_target(leaf);
RuleTypedSubstitutionPair rule = *rules.begin();
AndBIT result = andbit.expand(leaf, rule, 1);
AndBIT expected(
_eval.eval_h("(BindLink"
" (VariableSet"
" )"
" (AndLink"
" (NotLink"
" (IdenticalLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (AndLink"
" (EvaluationLink (stv 1.000000 1.000000)"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")"
" )"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" )"
" )"
" )"
" (EvaluationLink"
" (GroundedPredicateNode \"scm-eager: closed-lambda-introduction-precondition\")"
" (EvaluationLink (stv 1.000000 1.000000)"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")"
" )"
" )"
" )"
" (NotLink"
" (EqualLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink (stv 1.000000 1.000000)"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")"
" )"
" )"
" )"
" )"
" )"
" )"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: deduction\")"
" (ListLink"
" (ImplicationLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\"))))"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (AndLink"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")))"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\"))))))"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: implication-implicant-distribution\")"
" (ListLink"
" (ImplicationLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\"))))"
" (AndLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\"))))"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\"))))))"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: implication-introduction\")"
" (ListLink"
" (ImplicationLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\"))))"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")))))"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\"))))"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: closed-lambda-introduction\")"
" (ListLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\"))))"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")))))))))"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: implication-and-lambda-factorization\")"
" (ImplicationLink"
" (AndLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\"))))"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")))))"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\"))"
" (AndLink"
" (EvaluationLink"
" (PredicateNode \"contain\")"
" (ListLink"
" (ConceptNode \"treatment-1\")"
" (ConceptNode \"compound-A\")))"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\"))))))))))"));
logger().debug() << "result = " << oc_to_string(result);
logger().debug() << "expected = " << oc_to_string(expected);
TS_ASSERT_EQUALS(result, expected);
}
void BITUTest::test_expand_2()
{
logger().info("BEGIN TEST: %s", __FUNCTION__);
AndBIT andbit(_eval.eval_h("fcs-3"));
Handle leaf = _eval.eval_h("(ImplicationLink"
" (VariableNode \"$B-531e6c5d\")"
" (VariableNode \"$B-edaffcb\")"
")");
Handle vardecl =
_eval.eval_h("(VariableSet"
" (TypedVariableLink"
" (VariableNode \"$B-732fec2a\")"
" (TypeChoice"
" (TypeNode \"OrLink\")"
" (TypeNode \"AndLink\")"
" (TypeNode \"LambdaLink\")"
" (TypeNode \"NotLink\")"
" (TypeNode \"PredicateNode\")"
" )"
" )"
" (TypedVariableLink"
" (VariableNode \"$B-edaffcb\")"
" (TypeChoice"
" (TypeNode \"OrLink\")"
" (TypeNode \"AndLink\")"
" (TypeNode \"LambdaLink\")"
" (TypeNode \"NotLink\")"
" (TypeNode \"PredicateNode\")"
" )"
" )"
" (TypedVariableLink"
" (VariableNode \"$B-531e6c5d\")"
" (TypeChoice"
" (TypeNode \"OrLink\")"
" (TypeNode \"AndLink\")"
" (TypeNode \"LambdaLink\")"
" (TypeNode \"NotLink\")"
" (TypeNode \"PredicateNode\")"
" )"
" )"
")");
Rule implication_and_lambda_factorization_rule(implication_and_lambda_factorization_rule_h);
RuleTypedSubstitutionMap rules =
implication_and_lambda_factorization_rule.unify_target(leaf, vardecl);
RuleTypedSubstitutionPair rule = *rules.begin();
AndBIT result = andbit.expand(leaf, rule);
AndBIT expected(
_eval.eval_h("(BindLink"
" (VariableSet"
" (TypedVariableLink"
" (VariableNode \"$B-732fec2a\")"
" (TypeChoice"
" (TypeNode \"OrLink\")"
" (TypeNode \"AndLink\")"
" (TypeNode \"LambdaLink\")"
" (TypeNode \"NotLink\")"
" (TypeNode \"PredicateNode\")"
" )"
" )"
" (TypedVariableLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" (TypeChoice"
" (TypeNode \"TypedVariableLink\")"
" (TypeNode \"VariableNode\")"
" (TypeNode \"VariableSet\")"
" (TypeNode \"VariableList\")"
" )"
" )"
" (TypedVariableLink"
" (VariableNode \"$A1-6e7827f6\")"
" (TypeNode \"EvaluationLink\")"
" )"
" (TypedVariableLink"
" (VariableNode \"$A2-485f68e9\")"
" (TypeNode \"EvaluationLink\")"
" )"
" )"
" (AndLink"
" (ImplicationLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (AndLink"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (VariableNode \"$A2-485f68e9\")"
" )"
" )"
" )"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" )"
" (NotLink"
" (IdenticalLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"compound-A\")"
" )"
" )"
" )"
" )"
" )"
" (NotLink"
" (IdenticalLink"
" (VariableNode \"$B-732fec2a\")"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" )"
" )"
" (ImplicationLink"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (AndLink"
" (VariableNode \"$A2-485f68e9\")"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" (VariableNode \"$B-732fec2a\")"
" )"
" (ImplicationLink"
" (VariableNode \"$B-732fec2a\")"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"compound-A\")"
" )"
" )"
" )"
" )"
" (PresentLink"
" (AndLink"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (VariableNode \"$A2-485f68e9\")"
" )"
" )"
" )"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" )"
" (NotLink"
" (IdenticalLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (AndLink"
" (VariableNode \"$A2-485f68e9\")"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" )"
" )"
" )"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: deduction\")"
" (ListLink"
" (ImplicationLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"compound-A\")"
" )"
" )"
" )"
" )"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: deduction\")"
" (ListLink"
" (ImplicationLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (VariableNode \"$B-732fec2a\")"
" )"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: deduction\")"
" (ListLink"
" (ImplicationLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (AndLink"
" (VariableNode \"$A2-485f68e9\")"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" )"
" (ImplicationLink"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"treatment-1\")"
" )"
" )"
" )"
" (AndLink"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (VariableNode \"$A2-485f68e9\")"
" )"
" )"
" )"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" )"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: implication-and-lambda-factorization\")"
" (ImplicationLink"
" (AndLink"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (VariableNode \"$A2-485f68e9\")"
" )"
" )"
" )"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (AndLink"
" (VariableNode \"$A2-485f68e9\")"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" )"
" )"
" )"
" )"
" (ImplicationLink"
" (QuoteLink"
" (LambdaLink"
" (UnquoteLink"
" (VariableNode \"$TyVs-5c1f7467\")"
" )"
" (UnquoteLink"
" (AndLink"
" (VariableNode \"$A2-485f68e9\")"
" (VariableNode \"$A1-6e7827f6\")"
" )"
" )"
" )"
" )"
" (VariableNode \"$B-732fec2a\")"
" )"
" )"
" )"
" (ImplicationLink"
" (VariableNode \"$B-732fec2a\")"
" (LambdaLink"
" (TypedVariableLink"
" (VariableNode \"$X\")"
" (TypeNode \"ConceptNode\")"
" )"
" (EvaluationLink"
" (PredicateNode \"take\")"
" (ListLink"
" (VariableNode \"$X\")"
" (ConceptNode \"compound-A\")"
" )"
" )"
" )"
" )"
" )"
" )"
")"));
logger().debug() << "result = " << oc_to_string(result);
logger().debug() << "expected = " << oc_to_string(expected);
TS_ASSERT_EQUALS(result, expected);
}
void BITUTest::test_expand_3()
{
logger().info("BEGIN TEST: %s", __FUNCTION__);
AndBIT andbit(_eval.eval_h("fcs-5"));
Handle leaf = _eval.eval_h("(EvaluationLink"
" (PredicateNode \"minsup\")"
" (ListLink"
" (VariableNode \"$g-2101505b\")"
" (ConceptNode \"texts\")"
" (NumberNode \"2.000000\")))");
Handle vardecl =
_eval.eval_h("(VariableSet"
" (TypedVariableLink"
" (VariableNode \"$g-2101505b\")"
" (TypeChoice"
" (TypeNode \"LambdaLink\")"
" (TypeNode \"PutLink\")))"
" (TypedVariableLink"
" (VariableNode \"$f-53364b8c\")"
" (TypeChoice"
" (TypeNode \"ConceptNode\")"
" (TypeNode \"LambdaLink\"))))");
Rule unary_specialization_rule(unary_specialization_rule_h);
RuleTypedSubstitutionMap rules =
unary_specialization_rule.unify_target(leaf, vardecl);
RuleTypedSubstitutionPair rule = *rules.begin();
AndBIT result = andbit.expand(leaf, rule);
AndBIT expected(
_eval.eval_h("(BindLink"
" (VariableSet"
" (TypedVariableLink"
" (VariableNode \"$f-53364b8c\")"
" (TypeChoice"
" (TypeNode \"ConceptNode\")"
" (TypeNode \"LambdaLink\")"
" )"
" )"
" (TypedVariableLink"
" (VariableNode \"$g-6566b25f\")"
" (TypeChoice"
" (TypeNode \"LambdaLink\")"
" (TypeNode \"PutLink\")"
" )"
" )"
" (TypedVariableLink"
" (VariableNode \"$f-72fe9f60\")"
" (TypeChoice"
" (TypeNode \"ConceptNode\")"
" (TypeNode \"LambdaLink\")"
" )"
" )"
" )"
" (AndLink"
" (PresentLink"
" (VariableNode \"$f-72fe9f60\"))"
" (VariableNode \"$f-53364b8c\")"
" (EvaluationLink"
" (GroundedPredicateNode \"scm-eager: has-arity\")"
" (ListLink"
" (VariableNode \"$g-6566b25f\")"
" (NumberNode \"1.000000\")"
" )"
" )"
" (EvaluationLink"
" (PredicateNode \"minsup\")"
" (ListLink"
" (VariableNode \"$g-6566b25f\")"
" (ConceptNode \"texts\")"
" (NumberNode \"2.000000\")"
" )"
" )"
" (EvaluationLink"
" (GroundedPredicateNode \"scm-eager: absolutely-true\")"
" (EvaluationLink"
" (PredicateNode \"minsup\")"
" (ListLink"
" (VariableNode \"$g-6566b25f\")"
" (ConceptNode \"texts\")"
" (NumberNode \"2.000000\")"
" )"
" )"
" )"
" (EvaluationLink"
" (GroundedPredicateNode \"scm-eager: has-arity\")"
" (ListLink"
" (QuoteLink"
" (PutLink"
" (UnquoteLink"
" (VariableNode \"$g-6566b25f\")"
" )"
" (UnquoteLink"
" (VariableNode \"$f-72fe9f60\")"
" )"
" )"
" )"
" (NumberNode \"2.000000\")"
" )"
" )"
" )"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: specialization\")"
" (ListLink"
" (EvaluationLink"
" (PredicateNode \"minsup\")"
" (ListLink"
" (QuoteLink"
" (PutLink"
" (PutLink"
" (UnquoteLink"
" (VariableNode \"$g-6566b25f\")"
" )"
" (UnquoteLink"
" (VariableNode \"$f-72fe9f60\")"
" )"
" )"
" (UnquoteLink"
" (ListLink"
" (VariableNode \"$f-53364b8c\")"
" (VariableNode \"$spe-arg-1\")"
" )"
" )"
" )"
" )"
" (ConceptNode \"texts\")"
" (NumberNode \"2.000000\")"
" )"
" )"
" (ExecutionOutputLink"
" (GroundedSchemaNode \"scm-eager: specialization\")"
" (ListLink"
" (EvaluationLink"
" (PredicateNode \"minsup\")"
" (ListLink"
" (QuoteLink"
" (PutLink"
" (UnquoteLink"
" (VariableNode \"$g-6566b25f\")"
" )"
" (UnquoteLink"
" (VariableNode \"$f-72fe9f60\")"
" )"
" )"
" )"
" (ConceptNode \"texts\")"
" (NumberNode \"2.000000\")"
" )"
" )"
" (EvaluationLink"
" (PredicateNode \"minsup\")"
" (ListLink"
" (VariableNode \"$g-6566b25f\")"
" (ConceptNode \"texts\")"
" (NumberNode \"2.000000\")"
" )"
" )"
" (VariableNode \"$f-72fe9f60\")"
" )"
" )"
" (VariableNode \"$f-53364b8c\")"
" )"
" )"
")"));
logger().debug() << "result = " << oc_to_string(result);
logger().debug() << "expected = " << oc_to_string(expected);
TS_ASSERT_EQUALS(result, expected);
}
void BITUTest::test_has_cycle()
{
logger().info("BEGIN TEST: %s", __FUNCTION__);
AndBIT andbit_1(_eval.eval_h("fcs-1"));
TS_ASSERT(not andbit_1.has_cycle());
AndBIT andbit_2(_eval.eval_h("fcs-2"));
TS_ASSERT(not andbit_2.has_cycle());
AndBIT andbit_3(_eval.eval_h("fcs-3"));
TS_ASSERT(not andbit_3.has_cycle());
AndBIT andbit_4(_eval.eval_h("fcs-4"));
TS_ASSERT(andbit_4.has_cycle());
}