From 330fc56f3938f736a31c8bdb320fa1e749e66514 Mon Sep 17 00:00:00 2001 From: Alexey Potapov Date: Thu, 28 Sep 2023 10:57:02 +0300 Subject: [PATCH] conjunction queries --- python/sandbox/das_gate/dasgate.py | 5 ++++- python/sandbox/das_gate/test_das.metta | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/sandbox/das_gate/dasgate.py b/python/sandbox/das_gate/dasgate.py index a92ec9799..57661dc55 100644 --- a/python/sandbox/das_gate/dasgate.py +++ b/python/sandbox/das_gate/dasgate.py @@ -38,8 +38,11 @@ def _atom2dict(self, atom): def _atom2query(self, atom): if isinstance(atom, ExpressionAtom): + targets = atom.get_children() + if isinstance(targets[0], SymbolAtom) and targets[0].get_name() == ',': + return And([self._atom2query(ch) for ch in targets[1:]]) return Link("Expression", ordered=True, - targets=[self._atom2query(ch) for ch in atom.get_children()]) + targets=[self._atom2query(ch) for ch in targets]) else: if isinstance(atom, VariableAtom): return Variable(repr(atom)) diff --git a/python/sandbox/das_gate/test_das.metta b/python/sandbox/das_gate/test_das.metta index 766a188de..c76a2abcd 100644 --- a/python/sandbox/das_gate/test_das.metta +++ b/python/sandbox/das_gate/test_das.metta @@ -3,8 +3,19 @@ !(bind! &das (new-das)) !(add-atom &das (Test (Test 2))) +!(add-atom &das (Best (Test 2))) !(add-atom &das Test) +; The simplest match with grounding the variable in the node !(match &das ($v1 (Test 2)) (This $v1 works)) +; The simplest match with grounding the variable in the link !(match &das (Test $v2) (This $v2 works)) + +!(add-atom &das (Rest (Test 3))) +!(add-atom &das (Test (Test 3))) + +; Compositional (And) query test +!(match &das (, (Best $x) ($v $x)) ($v $x)) +; !(match &das (, ($v1 $x) (Test $x)) ($v1 Test $x)) + ; !(match &das ($v1 ($v2 2)) (This $v1 works))