Skip to content

Commit

Permalink
fix: non-generic Entities with different names don't have same meaning
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed Mar 8, 2021
1 parent f8b001d commit 2468f2e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
=========
0.2.2 (2021-03-08)
------------------
- fix: non-generic Entities with different names don't have same meaning

0.2.1 (2021-03-07)
------------------
- fix bug: multiple UnitRegistries conflicted
Expand Down
2 changes: 1 addition & 1 deletion nettlesome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
from .quantities import Comparison, DateRange, NumberRange, UnitRange
from .statements import Statement

__version__ = "0.2.1"
__version__ = "0.2.2"
16 changes: 16 additions & 0 deletions nettlesome/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,19 @@ def implies(
if self.generic or self.name != other.name:
return False
return super().implies(other=other, context=context)

def means(
self, other: Optional[Comparable], context: Optional[ContextRegister] = None
) -> bool:
"""
Test if ``self`` has the same meaning as ``other``.
A "generic" Entity has the same meaning as another Entity even if their
names are not the same.
"""
if isinstance(other, Entity):
if self.generic is True:
return other.generic is True
return other.generic is False and self.name == other.name

return super().means(other=other, context=context)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]

name = nettlesome
version = 0.2.1
version = 0.2.2
author= Matt Carey
author_email = [email protected]
description = simplified semantic reasoning
Expand Down
8 changes: 8 additions & 0 deletions tests/test_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ def test_same_meaning_no_terms(self):
Statement(Predicate("good morning"))
)

def test_changing_order_of_concrete_terms_changes_meaning(self):
ann = Entity("Ann", generic=False)
bob = Entity("Bob", generic=False)
parent_sentence = Predicate("$mother was ${child}'s parent")
ann_parent = Statement(parent_sentence, terms=(ann, bob))
bob_parent = Statement(parent_sentence, terms=(bob, ann))
assert not ann_parent.means(bob_parent)


class TestImplication:
def test_statement_implies_none(self):
Expand Down

0 comments on commit 2468f2e

Please sign in to comment.