Skip to content

Commit

Permalink
conjunction queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Necr0x0Der committed Sep 28, 2023
1 parent e927a76 commit 330fc56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/sandbox/das_gate/dasgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions python/sandbox/das_gate/test_das.metta
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 330fc56

Please sign in to comment.