Skip to content

Commit

Permalink
core.py: + is_true(subj, pred, obj) + test
Browse files Browse the repository at this point in the history
  • Loading branch information
cknoll committed Dec 12, 2023
1 parent bb84c2d commit 49f35bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/pyerk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,14 @@ def rule(self):
return self._rule


def is_true(subject: Entity, predicate: Relation, object) -> (bool, None):
assert isinstance(subject, Entity)
assert isinstance(predicate, Relation)

res = subject.get_relations(predicate, return_obj=True)
IPS()


def format_entity_html(e: Entity):
short_txt = f'<span class="entity">{e.R1}</span>'
detailed_txt = f'<span class="entity">{e.short_key}["{e.R1}"]</span>'
Expand Down
4 changes: 4 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,10 @@ def test_e01__I14_subclass_scopes(self):
)
scp1 = I1001.scope("setting")

def test_e02__is_true(self):
ma = p.erkloader.load_mod_from_path(TEST_DATA_PATH_MA, prefix="ma")
p.is_true(ma.I5359, p.R4, ma.I4895)
p.is_true(ma.I5359["determinant"], p.R4["is instance of"], ma.I4895["mathematical operator"])

class Test_02_ruleengine(HousekeeperMixin, unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 49f35bf

Please sign in to comment.