Skip to content

Commit

Permalink
Automated black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 15, 2024
1 parent 368ced6 commit 29354a8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/tests/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_meaning(self):
def test_length(self):
parsed_expression = TestGrammar.grammar.parse(TestGrammar.geq2_expr_str)
assert len(parsed_expression) == 5

def test_atom_count(self):
parsed_expression = TestGrammar.grammar.parse(TestGrammar.geq2_expr_str)
assert parsed_expression.count_atoms() == 3
Expand Down
22 changes: 16 additions & 6 deletions src/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,36 @@ class TestLanguage:
dog = Expression(
form="dog",
meaning=Meaning(
mapping=FrozenDict({ref: ref.name == "dog" for ref in uni_refs}), universe=uni
mapping=FrozenDict({ref: ref.name == "dog" for ref in uni_refs}),
universe=uni,
),
)
cat = Expression(
form="cat",
meaning=Meaning(
mapping=FrozenDict({ref: ref.name == "cat" for ref in uni_refs}), universe=uni
mapping=FrozenDict({ref: ref.name == "cat" for ref in uni_refs}),
universe=uni,
),
)
tree = Expression(
form="tree",
meaning=Meaning(
mapping=FrozenDict({ref: ref.name == "tree" for ref in uni_refs}), universe=uni
mapping=FrozenDict({ref: ref.name == "tree" for ref in uni_refs}),
universe=uni,
),
)
shroom = Expression(
form="shroom",
meaning=Meaning(
mapping=FrozenDict({ref: ref.name == "shroom" for ref in uni_refs}), universe=uni
mapping=FrozenDict({ref: ref.name == "shroom" for ref in uni_refs}),
universe=uni,
),
)
bird = Expression(
form="bird",
meaning=Meaning(
mapping=FrozenDict({ref: ref.name == "bird" for ref in uni_refs}), universe=uni
mapping=FrozenDict({ref: ref.name == "bird" for ref in uni_refs}),
universe=uni,
),
)

Expand All @@ -78,7 +83,12 @@ def test_language_universe_check(self):
Expression(
form="dog",
meaning=Meaning(
mapping=FrozenDict({ref: ref.name == "dog" for ref in TestLanguage.uni.referents}),
mapping=FrozenDict(
{
ref: ref.name == "dog"
for ref in TestLanguage.uni.referents
}
),
universe=TestLanguage.uni2,
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/ultk/language/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def to_dict(self) -> dict:
if self.children:
the_dict["children"] = tuple(child.to_dict() for child in self.children)
return the_dict

# Following function counts the total number of atoms / leaf nodes, as opposed to __len__, which counts all nodes
def count_atoms(self):
if self.children is None:
Expand Down
10 changes: 5 additions & 5 deletions src/ultk/language/semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ class Universe:
referents: tuple[Referent, ...]
prior: tuple[float, ...]

def __init__(self, referents, prior = None):
def __init__(self, referents, prior=None):
# use of __setattr__ is to work around the issues with @dataclass(frozen=True)
object.__setattr__(self, "referents", referents)
# When only referents are passed in, make the priors a unifrom distribution
object.__setattr__(
self,
"prior",
prior or tuple(1/len(referents) for _ in referents)
self, "prior", prior or tuple(1 / len(referents) for _ in referents)
)

@cached_property
Expand Down Expand Up @@ -194,4 +192,6 @@ def __bool__(self):
return bool(self.mapping) # and bool(self.universe)

def __str__(self):
return "Mapping:\n\t{0}".format('\n'.join(f"{ref}: {self.mapping[ref]}" for ref in self.mapping)) # \ \nDistribution:\n\t{self.dist}\n"
return "Mapping:\n\t{0}".format(
"\n".join(f"{ref}: {self.mapping[ref]}" for ref in self.mapping)
) # \ \nDistribution:\n\t{self.dist}\n"

0 comments on commit 29354a8

Please sign in to comment.