Skip to content

Commit

Permalink
Merge pull request #332 from singnet/bugfix/fix-count-atoms
Browse files Browse the repository at this point in the history
Fix tests after removing the MettaType links from the parser
  • Loading branch information
marcocapozzoli authored Sep 10, 2024
2 parents 51b81fc + df66a34 commit 84ec75c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 47 deletions.
38 changes: 19 additions & 19 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def load_metta_animals_base(das: DistributedAtomSpace) -> None:
das.add_node({"type": "Symbol", "name": 'Inheritance', "is_literal": False})
das.add_node({"type": "Symbol", "name": 'Symbol', "is_literal": False})
das.add_node({"type": "Symbol", "name": 'Type', "is_literal": False})
das.add_node({"type": "Symbol", "name": 'MettaType', "is_literal": False})
# das.add_node({"type": "Symbol", "name": 'MettaType', "is_literal": False})
das.add_node({"type": "Symbol", "name": 'Expression', "is_literal": False})
das.add_node({"type": "Symbol", "name": 'Concept', "is_literal": False})
das.add_node({"type": "Symbol", "name": '"human"', "is_literal": True})
Expand Down Expand Up @@ -153,23 +153,23 @@ def load_metta_animals_base(das: DistributedAtomSpace) -> None:
das.add_link({"type": "Expression", "targets": [{"type": "Symbol", "name": 'Inheritance', "is_literal": False}, {"type": "Symbol", "name": '"rhino"', "is_literal": True}, {"type": "Symbol", "name": '"mammal"', "is_literal": True}]})
das.add_link({"type": "Expression", "targets": [{"type": "Symbol", "name": 'Inheritance', "is_literal": False}, {"type": "Symbol", "name": '"vine"', "is_literal": True}, {"type": "Symbol", "name": '"plant"', "is_literal": True}]})
das.add_link({"type": "Expression", "targets": [{"type": "Symbol", "name": 'Inheritance', "is_literal": False}, {"type": "Symbol", "name": '"ent"', "is_literal": True}, {"type": "Symbol", "name": '"plant"', "is_literal": True}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": 'Similarity', "is_literal": False}, {"type": "Symbol", "name": 'Type', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": 'Concept', "is_literal": False}, {"type": "Symbol", "name": 'Type', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": 'Inheritance', "is_literal": False}, {"type": "Symbol", "name": 'Type', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"human"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"monkey"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"chimp"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"snake"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"earthworm"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"rhino"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"triceratops"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"vine"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"ent"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"mammal"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"animal"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"reptile"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"dinosaur"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"plant"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": 'Similarity', "is_literal": False}, {"type": "Symbol", "name": 'Type', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": 'Concept', "is_literal": False}, {"type": "Symbol", "name": 'Type', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": 'Inheritance', "is_literal": False}, {"type": "Symbol", "name": 'Type', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"human"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"monkey"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"chimp"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"snake"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"earthworm"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"rhino"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"triceratops"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"vine"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"ent"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"mammal"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"animal"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"reptile"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"dinosaur"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})
# das.add_link({"type": "MettaType", "targets": [{"type": "Symbol", "name": '"plant"', "is_literal": True}, {"type": "Symbol", "name": 'Concept', "is_literal": False}]})


class MettaAnimalBaseHandlesCollection:
Expand All @@ -178,7 +178,7 @@ class MettaAnimalBaseHandlesCollection:
Inheritance = AtomDB.node_handle('Symbol', 'Inheritance')
Symbol = AtomDB.node_handle('Symbol', 'Symbol')
Type = AtomDB.node_handle('Symbol', 'Type')
MettaType = AtomDB.node_handle('Symbol', 'MettaType')
# MettaType = AtomDB.node_handle('Symbol', 'MettaType')
Expression = AtomDB.node_handle('Symbol', 'Expression')
human = AtomDB.node_handle('Symbol', '"human"')
monkey = AtomDB.node_handle('Symbol', '"monkey"')
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_get_links(self, server: FunctionsClient):

def test_count_atoms(self, server: FunctionsClient):
ret = server.count_atoms()
assert ret == {'atom_count': 83}
assert ret == {'atom_count': 66}

def test_query(self, server: FunctionsClient):
server.get_links('Expression', no_iterator=True)
Expand Down Expand Up @@ -121,33 +121,33 @@ def test_get_incoming_links(self, server: FunctionsClient):
)
assert cursor is None
assert all(isinstance(handle, str) for handle in response_handles)
assert len(response_handles) == 9
assert len(response_handles) == 8
# response_handles has an extra link (named_type == MettaType) defining
# the metta type of '"human"'--> Type
# response_handles has an extra link (named_type == Expression) defining
# the metta expression (: "human" Type)
assert len(set(response_handles).difference(set(expected_handles))) == 1
# assert len(set(response_handles).difference(set(expected_handles))) == 1
cursor, response_handles = server.get_incoming_links(
metta_animal_base_handles.human, targets_document=True, handles_only=True
)
assert cursor is None
assert all(isinstance(handle, str) for handle in response_handles)
assert len(response_handles) == 9
assert len(set(response_handles).difference(set(expected_handles))) == 1
assert len(response_handles) == 8
# assert len(set(response_handles).difference(set(expected_handles))) == 1

cursor, response_atoms = server.get_incoming_links(
metta_animal_base_handles.human, targets_document=False, handles_only=False
)
assert cursor is None
assert len(response_atoms) == 9
assert len(response_atoms) == 8
for atom in response_atoms:
assert isinstance(atom, dict), f"Each item in body must be a dict. Received: {atom}"
if len(atom["targets"]) == 3:
assert atom in expected_atoms

cursor, response_atoms = server.get_incoming_links(metta_animal_base_handles.human)
assert cursor is None
assert len(response_atoms) == 9
assert len(response_atoms) == 8
for atom in response_atoms:
assert isinstance(atom, dict), f"Each item in body must be a dict. Received: {atom}"
if len(atom["targets"]) == 3:
Expand All @@ -157,7 +157,7 @@ def test_get_incoming_links(self, server: FunctionsClient):
metta_animal_base_handles.human, targets_document=True, handles_only=False
)
assert cursor is None
assert len(response_atoms_targets) == 9
assert len(response_atoms_targets) == 8
for atom in response_atoms_targets:
assert isinstance(atom, dict), f"Each item in body must be a dict. Received: {atom}"
atom_targets = atom.pop('targets_document')
Expand Down
19 changes: 10 additions & 9 deletions tests/integration/test_iterators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Union

import pytest
from hyperon_das_atomdb.utils.expression_hasher import ExpressionHasher as hasher

from hyperon_das import DistributedAtomSpace
from hyperon_das.cache import QueryAnswerIterator
Expand All @@ -24,6 +23,8 @@
)
from tests.integration.remote_das_info import remote_das_host, remote_das_port

# from hyperon_das_atomdb.utils.expression_hasher import ExpressionHasher as hasher


@pytest.fixture
def database_fixture():
Expand Down Expand Up @@ -71,13 +72,13 @@ def _human_incoming_links(self):
metta_animal_base_handles.similarity_ent_human,
metta_animal_base_handles.inheritance_human_mammal,
metta_animal_base_handles.human_typedef,
hasher.expression_hash(
hasher.named_type_hash('MettaType'),
[
hasher.terminal_hash('Symbol', '"human"'),
hasher.terminal_hash('Symbol', 'Concept'),
],
),
# hasher.expression_hash(
# hasher.named_type_hash('MettaType'),
# [
# hasher.terminal_hash('Symbol', '"human"'),
# hasher.terminal_hash('Symbol', 'Concept'),
# ],
# ),
]
)

Expand All @@ -89,7 +90,7 @@ def _check_asserts(
assert isinstance(current_value, dict)
assert iterator.is_empty() is False
link_handles = sorted([item['handle'] for item in iterator])
assert len(link_handles) == 9
assert len(link_handles) == 8
assert link_handles == self._human_incoming_links()
assert iterator.is_empty() is True
with pytest.raises(StopIteration):
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_remote_das.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_get_incoming_links(self, remote_das: DistributedAtomSpace):

def test_count_atoms(self, remote_das: DistributedAtomSpace):
response = remote_das.count_atoms(parameters={})
assert response == {'atom_count': 83, 'node_count': 0, 'link_count': 0}
assert response == {'atom_count': 66, 'node_count': 0, 'link_count': 0}
response_local = remote_das.count_atoms({'context': 'local'})
assert response_local == {'atom_count': 0, 'node_count': 0, 'link_count': 0}

Expand Down Expand Up @@ -323,9 +323,9 @@ def test_fetch_all_data(self, remote_das):
}
remote_das.fetch()
assert remote_das.backend.count_atoms() == {
'atom_count': 83,
'atom_count': 66,
'node_count': 23,
'link_count': 60,
'link_count': 43,
}

def test_create_context(self, remote_das):
Expand Down
17 changes: 9 additions & 8 deletions tests/integration/test_traverse_engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from hyperon_das_atomdb.utils.expression_hasher import ExpressionHasher as hasher

from hyperon_das.das import DistributedAtomSpace

Expand All @@ -14,6 +13,8 @@
)
from .remote_das_info import remote_das_host, remote_das_port

# from hyperon_das_atomdb.utils.expression_hasher import ExpressionHasher as hasher


class TestTraverseEngine:
@pytest.fixture(scope="session")
Expand Down Expand Up @@ -52,13 +53,13 @@ def _check_asserts(self, das: DistributedAtomSpace):
metta_animal_base_handles.similarity_chimp_human,
metta_animal_base_handles.inheritance_human_mammal,
metta_animal_base_handles.human_typedef,
hasher.expression_hash(
hasher.named_type_hash('MettaType'),
[
hasher.terminal_hash('Symbol', '"human"'),
hasher.terminal_hash('Symbol', 'Concept'),
],
),
# hasher.expression_hash(
# hasher.named_type_hash('MettaType'),
# [
# hasher.terminal_hash('Symbol', '"human"'),
# hasher.terminal_hash('Symbol', 'Concept'),
# ],
# ),
]
)

Expand Down

0 comments on commit 84ec75c

Please sign in to comment.