Skip to content

Commit

Permalink
Update tests in test_language.py
Browse files Browse the repository at this point in the history
- Fix declaration of `Expressions`
- Update tests to not error or for newer versions of `Mapping` class
  - `test_language_universe_check` simply had its delcaration of a `Meaning` object updated
  - `test_langauge_degree` had to have the `isAnimal` function edited
    - I believe this is the correct implementation, but I need to double check
- All tests in `test_language.py` and `test_grammar.py` are passing
  • Loading branch information
Ashvin-Ranjan committed Nov 20, 2024
1 parent 471547d commit 80d0a99
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from ultk.language.language import Expression, Language
from ultk.language.semantics import Referent, Universe, Meaning
from ultk.util.frozendict import FrozenDict


class TestLanguage:
Expand All @@ -25,36 +26,34 @@ class TestLanguage:

meaning = Meaning(mapping=uni_refs, universe=uni)

uni.referents

dog = Expression(
form="dog",
meaning=Meaning(
mapping=tuple([Referent("dog", {"phylum": "animal"})]), universe=uni
mapping=FrozenDict({ref: ref.name == "dog" for ref in uni_refs}), universe=uni
),
)
cat = Expression(
form="cat",
meaning=Meaning(
mapping=tuple([Referent("cat", {"phylum": "animal"})]), universe=uni
mapping=FrozenDict({ref: ref.name == "cat" for ref in uni_refs}), universe=uni
),
)
tree = Expression(
form="tree",
meaning=Meaning(
mapping=tuple([Referent("tree", {"phylum": "plant"})]), universe=uni
mapping=FrozenDict({ref: ref.name == "tree" for ref in uni_refs}), universe=uni
),
)
shroom = Expression(
form="shroom",
meaning=Meaning(
mapping=tuple([Referent("shroom", {"phylum": "fungus"})]), universe=uni
mapping=FrozenDict({ref: ref.name == "shroom" for ref in uni_refs}), universe=uni
),
)
bird = Expression(
form="bird",
meaning=Meaning(
mapping=tuple([Referent("bird", {"phylum": "animal"})]), universe=uni
mapping=FrozenDict({ref: ref.name == "bird" for ref in uni_refs}), universe=uni
),
)

Expand All @@ -81,7 +80,7 @@ def test_language_universe_check(self):
Expression(
form="dog",
meaning=Meaning(
referents=tuple([Referent("dog", {"phylum": "animal"})]),
mapping=FrozenDict({ref: ref.name == "dog" for ref in TestLanguage.uni.referents}),
universe=TestLanguage.uni2,
),
),
Expand All @@ -90,8 +89,11 @@ def test_language_universe_check(self):

def test_language_degree(self):
def isAnimal(exp: Expression) -> bool:
print("checking phylum of " + str(exp.meaning.referents[0]))
return exp.meaning.referents[0].phylum == "animal"
print("checking phylum of " + str(exp))
for k, v in exp.meaning.mapping.items():
if v and k.phylum != "animal":
return False
return True

assert TestLanguage.lang.degree_property(isAnimal) == 0.5

Expand Down

0 comments on commit 80d0a99

Please sign in to comment.