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
refactor: refactor prettyprinter to be more readable #2893
Changes from 3 commits
b806f15
2d8ad63
efd801b
dc31b2c
3eb6d41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -75,7 +75,7 @@ def __init__(self, tree, sentence=None, highlight=()): | |||||
leaves = tree.leaves() | ||||||
if ( | ||||||
leaves | ||||||
and not any(len(a) == 0 for a in tree.subtrees()) | ||||||
and any(len(a) > 0 for a in tree.subtrees()) | ||||||
and all(isinstance(a, int) for a in leaves) | ||||||
): | ||||||
sentence = [str(a) for a in leaves] | ||||||
|
@@ -207,7 +207,7 @@ def dumpmatrix(): | |||||
raise ValueError("All leaves must be integer indices.") | ||||||
if len(leaves) != len(set(leaves)): | ||||||
raise ValueError("Indices must occur at most once.") | ||||||
if not all(0 <= n < len(sentence) for n in leaves): | ||||||
if not all(n in range(0, len(sentence)) for n in leaves): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey mohaned! this actually felt a bit better before. plus now it's constructing a list for each element in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right. Thanks. |
||||||
raise ValueError( | ||||||
"All leaves must be in the interval 0..n " | ||||||
"with n=len(sentence)\ntokens: %d indices: " | ||||||
|
@@ -291,7 +291,7 @@ def dumpmatrix(): | |||||
matrix[rowidx][i] = ids[m] | ||||||
nodes[ids[m]] = tree[m] | ||||||
# add column to the set of children for its parent | ||||||
if m != (): | ||||||
if len(m) > 0: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agree, but like you said There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understandable! |
||||||
childcols[m[:-1]].add((rowidx, i)) | ||||||
assert len(positions) == 0 | ||||||
|
||||||
|
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.
The replacement contains a logical error. NB:
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.
Yeah right, my bad.
I believe it should be replaced with all instead of any.
Considering the below test cases:-