Skip to content

Commit

Permalink
Merge pull request #52 from ngeiswei/variable-set-upgrade
Browse files Browse the repository at this point in the history
Upgrade to VariableSet
  • Loading branch information
ngeiswei authored Dec 17, 2019
2 parents cf3a19a + a8d18cb commit a89683a
Show file tree
Hide file tree
Showing 29 changed files with 57 additions and 46 deletions.
2 changes: 1 addition & 1 deletion examples/ure/contraposition/contraposition.scm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
(bky (Evaluation kp (List vB vY))))

(BindLink
(VariableList
(VariableSet
(TypedVariable
vA
(Type "ConceptNode"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define conditional-full-instantiation-meta-variables
(VariableList
(VariableSet
(TypedVariable
(Variable "$TyVs")
(TypeChoice
Expand Down
2 changes: 1 addition & 1 deletion examples/ure/no-exec-output/no-exec-output.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(vX (Variable "$X"))
(akx (Evaluation kp (List vA vX))))
(BindLink
(VariableList
(VariableSet
(TypedVariable
vA
(Type "ConceptNode"))
Expand Down
2 changes: 1 addition & 1 deletion examples/ure/rules/crisp-deduction-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

(define crisp-deduction-rule
(BindLink
(VariableList
(VariableSet
(VariableNode "$A")
(VariableNode "$B")
(VariableNode "$C")
Expand Down
2 changes: 1 addition & 1 deletion examples/ure/rules/crisp-modus-ponens-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

(define crisp-modus-ponens-rule
(BindLink
(VariableList
(VariableSet
(TypedVariable
(VariableNode "$A")
(TypeNode "PredicateNode"))
Expand Down
2 changes: 1 addition & 1 deletion examples/ure/rules/fuzzy-conjunction-introduction-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
(InheritanceT (Type "InheritanceLink"))
(type (TypeChoice EvaluationT InheritanceT))
(gen-typed-variable (lambda (x) (TypedVariable x type)))
(vardecl (VariableList (map gen-typed-variable variables)))
(vardecl (VariableSet (map gen-typed-variable variables)))
(pattern (Present variables))
(rewrite (ExecutionOutput
(GroundedSchema "scm: fuzzy-conjunction-introduction-formula")
Expand Down
2 changes: 1 addition & 1 deletion opencog/unify/Unify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ Handle Unify::substitute_vardecl(const Handle& vardecl,

HandleSeq oset;

if (t == VARIABLE_LIST) {
if (t == VARIABLE_LIST or t == VARIABLE_SET) {
for (const Handle& h : vardecl->getOutgoingSet()) {
Handle nh = substitute_vardecl(h, var2val);
if (nh)
Expand Down
20 changes: 10 additions & 10 deletions tests/ure/RuleUTest.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void RuleUTest::test_unify_target_deduction_1()

Handle rule = rules.begin()->first.get_rule(),
// Expected up to an alpha conversion
vardecl = al(VARIABLE_LIST,
vardecl = al(VARIABLE_SET,
al(TYPED_VARIABLE_LINK, X, CT),
al(TYPED_VARIABLE_LINK, V, CT)),
XV = al(INHERITANCE_LINK, X, V),
Expand Down Expand Up @@ -189,7 +189,7 @@ void RuleUTest::test_unify_target_deduction_2()

Handle rule = rules.begin()->first.get_rule(),
// Expected up to an alpha conversion
vardecl = al(VARIABLE_LIST,
vardecl = al(VARIABLE_SET,
al(TYPED_VARIABLE_LINK, X, CT),
al(TYPED_VARIABLE_LINK, V, CT)),
XV = al(INHERITANCE_LINK, X, V),
Expand Down Expand Up @@ -482,7 +482,7 @@ void RuleUTest::test_unify_target_implication_scope_to_implication_4()
" (VariableNode \"$Q-38ea0de8\")"
")");
Handle vardecl =
_eval.eval_h("(VariableList"
_eval.eval_h("(VariableSet"
" (VariableNode \"$B-2db76aad\")"
" (TypedVariableLink"
" (VariableNode \"$Q-38ea0de8\")"
Expand All @@ -502,7 +502,7 @@ void RuleUTest::test_unify_target_implication_scope_to_implication_4()
// Expected up to an alpha conversion
Handle expected =
_eval.eval_h("(BindLink"
" (VariableList"
" (VariableSet"
" (TypedVariableLink"
" (VariableNode \"$TyVs-6c74a409\")"
" (TypeChoice"
Expand Down Expand Up @@ -531,10 +531,10 @@ void RuleUTest::test_unify_target_implication_scope_to_implication_4()
" (Unquote (VariableNode \"$Q-7005b724\")))))))");

std::cout << "implication_scope_to_implication_rule = "
<< oc_to_string(implication_scope_to_implication_rule);
std::cout << "target = " << oc_to_string(target);
std::cout << "rule = " << oc_to_string(rule);
std::cout << "expected = " << oc_to_string(expected);
<< oc_to_string(implication_scope_to_implication_rule) << std::endl;
std::cout << "target = " << oc_to_string(target) << std::endl;
std::cout << "rule = " << oc_to_string(rule) << std::endl;
std::cout << "expected = " << oc_to_string(expected) << std::endl;

ScopeLinkPtr expected_sc = ScopeLinkCast(expected);

Expand Down Expand Up @@ -719,7 +719,7 @@ void RuleUTest::test_unify_target_closed_lambda_introduction_1()
Handle rule = rules.begin()->first.get_rule();
Handle expected =
_eval.eval_h("(BindLink"
" (VariableList"
" (VariableSet"
" )"
" (AndLink"
" (EvaluationLink"
Expand Down Expand Up @@ -802,7 +802,7 @@ void RuleUTest::test_unify_target_closed_lambda_introduction_2()
Handle rule = rules.begin()->first.get_rule();
Handle expected =
_eval.eval_h("(BindLink"
" (VariableList)"
" (VariableSet)"
" (AndLink"
" (EvaluationLink"
" (GroundedPredicateNode \"scm: closed-lambda-introduction-precondition\")"
Expand Down
11 changes: 6 additions & 5 deletions tests/ure/backwardchainer/BITUTest.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void BITUTest::test_expand_1()
AndBIT result = andbit.expand(leaf, rule, 1);
AndBIT expected(
_eval.eval_h("(BindLink"
" (VariableList"
" (VariableSet"
" )"
" (AndLink"
" (PresentLink"
Expand Down Expand Up @@ -422,7 +422,7 @@ void BITUTest::test_expand_2()
" (VariableNode \"$B-edaffcb\")"
")");
Handle vardecl =
_eval.eval_h("(VariableList"
_eval.eval_h("(VariableSet"
" (TypedVariableLink"
" (VariableNode \"$B-732fec2a\")"
" (TypeChoice"
Expand Down Expand Up @@ -463,7 +463,7 @@ void BITUTest::test_expand_2()
AndBIT result = andbit.expand(leaf, rule);
AndBIT expected(
_eval.eval_h("(BindLink"
" (VariableList"
" (VariableSet"
" (TypedVariableLink"
" (VariableNode \"$B-732fec2a\")"
" (TypeChoice"
Expand All @@ -479,6 +479,7 @@ void BITUTest::test_expand_2()
" (TypeChoice"
" (TypeNode \"TypedVariableLink\")"
" (TypeNode \"VariableNode\")"
" (TypeNode \"VariableSet\")"
" (TypeNode \"VariableList\")"
" )"
" )"
Expand Down Expand Up @@ -879,7 +880,7 @@ void BITUTest::test_expand_3()
" (ConceptNode \"texts\")"
" (NumberNode \"2.000000\")))");
Handle vardecl =
_eval.eval_h("(VariableList"
_eval.eval_h("(VariableSet"
" (TypedVariableLink"
" (VariableNode \"$g-2101505b\")"
" (TypeChoice"
Expand All @@ -899,7 +900,7 @@ void BITUTest::test_expand_3()
AndBIT result = andbit.expand(leaf, rule);
AndBIT expected(
_eval.eval_h("(BindLink"
" (VariableList"
" (VariableSet"
" (TypedVariableLink"
" (VariableNode \"$f-53364b8c\")"
" (TypeChoice"
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/backwardchainer/BackwardChainerUTest.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void BackwardChainerUTest::test_conditional_instantiation_tv_query()
// thus having the type itself be a variable, like
//
// BindLink
// VariableList
// VariableSet
// TypedVariable
// Variable "$XVar"
// Type "VariableNode"
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/backwardchainer/scm/no-exec-output.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(vX (Variable "$X"))
(akx (Evaluation kp (List vA vX))))
(BindLink
(VariableList
(VariableSet
(TypedVariable
vA
(Type "ConceptNode"))
Expand Down
4 changes: 2 additions & 2 deletions tests/ure/forwardchainer/scm/dfc-tests.scm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; Substitution case where $A = Cat and $B = Animal
(define deduction-ab-substitute-1
(BindLink
(VariableList
(VariableSet
(TypedVariableLink
(VariableNode "$C")
(TypeNode "ConceptNode")))
Expand Down Expand Up @@ -34,7 +34,7 @@
; Substitution case where $B = Cat and $C = Animal
(define deduction-ab-substitute-2
(BindLink
(VariableList
(VariableSet
(TypedVariableLink
(VariableNode "$A")
(TypeNode "ConceptNode")))
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/forwardchainer/scm/fc-unsatisfied-premise.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(define rule
(BindLink

(VariableList
(VariableSet
(TypedVariable (Variable "$a") (Type "ConceptNode"))
(TypedVariable (Variable "$b") (Type "ConceptNode")))

Expand Down
2 changes: 1 addition & 1 deletion tests/ure/forwardchainer/scm/negation-conflict.scm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
(bky (Evaluation kp (List vB vY)))
)
(BindLink
(VariableList
(VariableSet
(TypedVariable
vA
(Type "ConceptNode"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define conditional-full-instantiation-meta-variables
(VariableList
(VariableSet
(TypedVariable
(Variable "$TyVs")
(TypeChoice
(Type "TypedVariableLink")
(Type "VariableSet")
(Type "VariableList")))
(Variable "$P")
(Variable "$Q")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@
(P (Variable "$P"))
(Q (Variable "$Q"))
;; Meta rule variable declaration
(meta-vardecl (VariableList
(meta-vardecl (VariableSet
TypedV1 TypedV2 TypedV3
TypedV1Type TypedV2Type TypedV3Type
P Q))
;; Meta rule main clause
(implication (Quote
(ImplicationScope
;; Support VariableSet
(Unquote (VariableList
(TypedVariable V1 V1Type)
(TypedVariable V2 V2Type)
Expand All @@ -69,7 +70,7 @@
(meta-pattern (And implication meta-precondition))
;; Produced rule variable declaration. V2 and V3 are to be
;; substituted.
(produced-vardecl (VariableList
(produced-vardecl (VariableSet
(TypedVariable V2 V2Type)
(TypedVariable V3 V3Type)))
;; Produced rule pattern. Just look for groundings of V2 and V3
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/rules/bc-deduction-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(BC (Inheritance B C))
(AC (Inheritance A C))
(Concept (Type "ConceptNode"))
(vardecl (VariableList
(vardecl (VariableSet
(TypedVariable A Concept)
(TypedVariable B Concept)
(TypedVariable C Concept)))
Expand Down
3 changes: 2 additions & 1 deletion tests/ure/rules/closed-lambda-introduction-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
;; ----------------------------------------------------------------------

(define closed-lambda-introduction-vardecl
(VariableList
(VariableSet
(TypedVariableLink
(VariableNode "$V")
(TypeChoice
(TypeNode "TypedVariableLink")
(TypeNode "VariableSet")
(TypeNode "VariableList")
(TypeNode "VariableNode")))
(VariableNode "$B")))
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/rules/crisp-deduction-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(AB (link-type A B))
(BC (link-type B C))
(AC (link-type A C))
(vardecl (VariableList A B C))
(vardecl (VariableSet A B C))
(precon1 (Evaluation (GroundedPredicate "scm: true-enough") AB))
(precon2 (Evaluation (GroundedPredicate "scm: true-enough") BC))
(precon3 (Not (Identical A C)))
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/rules/crisp-modus-ponens-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(AB (Implication A B))
(LambdaT (Type "LambdaLink"))
(PredicateT (Type "PredicateNode"))
(vardecl (VariableList
(vardecl (VariableSet
(TypedVariable A (TypeChoice LambdaT PredicateT))
(TypedVariable B (TypeChoice LambdaT PredicateT))))
(precon1 (Evaluation (GroundedPredicate "scm: true-enough") A))
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/rules/fc-deduction-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

(define fc-deduction-rule
(BindLink
(VariableList
(VariableSet
(TypedVariableLink
(VariableNode "$A")
(TypeNode "ConceptNode"))
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/rules/fuzzy-conjunction-introduction-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
(InheritanceT (Type "InheritanceLink"))
(type (TypeChoice EvaluationT InheritanceT))
(gen-typed-variable (lambda (x) (TypedVariable x type)))
(vardecl (VariableList (map gen-typed-variable variables)))
(vardecl (VariableSet (map gen-typed-variable variables)))
(pattern (Present variables))
(rewrite (ExecutionOutput
(GroundedSchema "scm: fuzzy-conjunction-introduction-formula")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
;; -----------------------------------------------------------------------

(define implication-and-lambda-factorization-vardecl
(VariableList
(VariableSet
(TypedVariableLink
(VariableNode "$TyVs")
(TypeChoice
(TypeNode "TypedVariableLink")
(TypeNode "VariableNode")
(TypeNode "VariableSet")
(TypeNode "VariableList")))
;; We intensionally restrict $A1 and $A2 to be EvaluationLink to
;; ensure that we don't produce indefinitely nested AndLinks
Expand Down
9 changes: 6 additions & 3 deletions tests/ure/rules/implication-instantiation-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
;;;;;;;;;;;;;;;;;;;;;;;

(define implication-full-instantiation-variables
(VariableList
(VariableSet
(TypedVariableLink
(VariableNode "$TyVs")
(TypeChoice
(TypeNode "TypedVariableLink")
(TypeNode "VariableSet")))
(TypeNode "VariableList")))
(VariableNode "$P")
(VariableNode "$Q")))
Expand Down Expand Up @@ -104,9 +105,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define implication-partial-instantiation-variables
(VariableList
(VariableSet
(TypedVariableLink
(VariableNode "$TyVs")
(TypeNode "VariableSet")
(TypeNode "VariableList"))
(VariableNode "$P")
(VariableNode "$Q")))
Expand Down Expand Up @@ -158,7 +160,8 @@
; variable
(TyV (list-ref TyVs-outgoings rnd-index))
; Build a VariableList of the
; remaining variables
; remaining variables. TODO:
; support VariableSet as well.
(TyVs-remain-list (rm-list-ref TyVs-outgoings rnd-index))
(TyVs-remain-len (length TyVs-remain-list))
(TyVs-remain (apply cog-new-link 'VariableList TyVs-remain-list)))
Expand Down
2 changes: 1 addition & 1 deletion tests/ure/rules/implication-introduction-rule.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
;; ----------------------------------------------------------------------

(define implication-introduction-variables
(VariableList
(VariableSet
(TypedVariableLink
(VariableNode "$P")
(TypeChoice
Expand Down
Loading

0 comments on commit a89683a

Please sign in to comment.