Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unique atomic agents #105

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Testing/objects_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# structure
s1 = StructureAgent("B", {a1})
s2 = StructureAgent("D", set())
s3 = StructureAgent("K", {a1, a3, a5})
s3 = StructureAgent("K", {a1, a3, a11})
s4 = StructureAgent("B", {a4})
s5 = StructureAgent("D", {a5, a6})
s6 = StructureAgent("K", set())
Expand Down
13 changes: 11 additions & 2 deletions Testing/parsing/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ def test_parser():
assert ret.success
assert ret.data.children[0] == objects.c1

ret = objects.rate_complex_parser.parse("B(T{s}).D().K(T{s},S{s},S{_})::cell")
ret = objects.rate_complex_parser.parse("B(T{s}).D().K(T{s},S{s},U{a})::cell")
assert ret.success
assert ret.data.children[0] == objects.c2

ret = objects.rate_complex_parser.parse(
"B(T{s}).K(T{s}, S{s}, S{_}).D(S{_},T{p})::cyt"
"B(T{s}).K(T{s}, S{s}, U{a}).D(S{_},T{p})::cyt"
)
assert ret.success
assert ret.data.children[0] == objects.c3
Expand Down Expand Up @@ -58,3 +58,12 @@ def test_parser():

ret = objects.rate_complex_parser.parse("B(T{s})::")
assert not ret.success

ret = objects.rate_complex_parser.parse("B(T{s}, T{_})::cell")
assert not ret.success

ret = objects.rate_complex_parser.parse("B(T{s}, T{s})::cell")
assert not ret.success

ret = objects.rate_complex_parser.parse("B(T{s}, T{a})::cell")
assert not ret.success
10 changes: 8 additions & 2 deletions Testing/parsing/test_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def test_parser():
assert ret.data.to_side() == objects.side2

ret = objects.side_parser.parse(
"B(T{s})::cell + B(T{s}).D().K(T{s},S{s},S{_})::cell + B(T{s}).D().K(T{s},S{s},S{_})::cell"
"B(T{s})::cell + B(T{s}).D().K(T{s},S{s},U{a})::cell + B(T{s}).D().K(T{s},S{s},U{a})::cell"
)
assert ret.success
assert ret.data.to_side() == objects.side3

ret = objects.side_parser.parse(
"B(T{s})::cell + 2 B(T{s}).D().K(T{s},S{s},S{_})::cell"
"B(T{s})::cell + 2 B(T{s}).D().K(T{s},S{s},U{a})::cell"
)
assert ret.success
assert ret.data.to_side() == objects.side3
Expand Down Expand Up @@ -48,3 +48,9 @@ def test_parser():

ret = objects.side_parser.parse("B(T{s}")
assert not ret.success

# not unique atomics in structure
ret = objects.side_parser.parse(
"B(T{s})::cell + B(T{s}).D().K(T{s},S{s},S{_})::cell + B(T{s}).D().K(T{s},S{s},S{_})::cell"
)
assert not ret.success
5 changes: 4 additions & 1 deletion Testing/parsing/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def test_parser():
assert objects.structure_parser.parse("B(T{s})").data == objects.s1
assert objects.structure_parser.parse("D()").data == objects.s2
assert objects.structure_parser.parse("K(T{s}, S{s}, S{_})").data == objects.s3
assert objects.structure_parser.parse("K(T{s}, S{s}, U{a})").data == objects.s3
assert objects.structure_parser.parse("B(T{_})").data == objects.s4
assert objects.structure_parser.parse("D(S{_},T{p})").data == objects.s5
assert objects.structure_parser.parse("K()").data == objects.s6
Expand All @@ -18,3 +18,6 @@ def test_parser():
assert not objects.structure_parser.parse("[B(T{s})]").success
assert not objects.structure_parser.parse("").success
assert not objects.structure_parser.parse("B({s})").success
assert not objects.structure_parser.parse("B(S{s}, S{a})").success
assert not objects.structure_parser.parse("B(S{a}, S{a})").success
assert not objects.structure_parser.parse("B(S{_}, S{a})").success
16 changes: 12 additions & 4 deletions eBCSgen/Parsing/ParseBCSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,19 @@ def atomic(self, matches):

def structure(self, matches):
name = str(matches[0].children[0])
if len(matches) > 1:
composition = set(matches[1].children)
return StructureAgent(name, composition)
else:
if len(matches) <= 1:
return StructureAgent(name, set())
atomic_names = set()
composition = set()
for atomic in matches[1].children:
if atomic.name in atomic_names:
raise ComplexParsingError(
f"Duplicate atomic agent in structure: {atomic.name}", matches
)
atomic_names.add(atomic.name)
composition.add(atomic)

return StructureAgent(name, composition)

def rate_complex(self, matches):
sequence = []
Expand Down
Loading