-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add count_atoms
to GrammaticalExpression
#48
Conversation
- Adds the method `count_atoms` to `GrammaticalExpression` - This also adds a proper test for the method in `test_grammar.py`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Ash! Much appreciated. One small change requested, just for readability :)
Re your point about testing: the tests are indeed quite outdated (we made some breaking changes to (at least) Universe
and Meaning
since they were written). If you're interested in digging more into ULTK, going through and cleaning up the test suite would be very welcome!
src/ultk/language/grammar.py
Outdated
length = 0 | ||
if self.children is not None: | ||
length += sum(child.count_atoms() for child in self.children) | ||
return length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This can be streamlined slightly: after the original if
statement on line 177, can just do return sum(child.count_atoms() for child in self.children)
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! I copied the code over from __len__
without realizing that it was a if
statement, not a for
loop, I have pushed a correction. Thank you for pointing it out.
Thank you for looking over the PR! I have implemented the suggestion you have made. Regarding unit tests, I would be more than happy to look into them and clean them up as a way to familiarize myself more with ULTK as a whole. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome; thanks for this and for taking a look at the tests next!
Add `count_atoms` to `GrammaticalExpression`
count_atoms
to the classGrammaticalExpression
, as suggested by GrammaticalExpression _len_ does not return number of atoms / leaf nodes #42.test_atom_count
totest_grammar.py
.Notes
test_grammar.py
, numerous issues with testing came uptest_grammar.py
andtest_language.py
both have issues withUniverse
expecting a tuple ofprior
stest_language.py
also has some issues with aMeaning
being initialized incorrectlytest_meaning
intest_grammar.py
fails (even after changes are reverted)test_atom_count
does passcount_atoms
can also be moved to a helper method ingrammar.py
, I simply felt it was more in line with the current project structure to make it a method of theGrammaticalExpression
class