Bnewm0609/layer slice#44
Open
bnewm0609 wants to merge 2 commits into
Open
Conversation
bnewm0609
commented
Aug 16, 2023
| self.assertSequenceEqual(doc.chunks[0].tokens, tokens[0:3]) | ||
| self.assertSequenceEqual(doc.chunks[1].tokens, tokens[3:5]) | ||
| self.assertSequenceEqual(doc.chunks[2].tokens, [tokens[5]]) | ||
|
|
Contributor
Author
There was a problem hiding this comment.
assertListEqual enforces that both arguments are list, while assertSequenceEqual does not. Because the first argument is a Layer, we use assertSequenceEqual.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Begins an implementation of
Layerto wrap theList[Entities]and allow for more intuitive slicing (e.g.doc.sentences[:3].textinstead of[sent.text for sent in doc.sentences]. This addresses #24 .The new data structure is implemented in
papermage/magelib/layer.pyand inherits from python'sUserList. The changes into integrateLayerwere mainly made in theDocumentdata structure.One design decision to consider is what to do with chained access: e.g.
doc.pages.paragraphs.sentences.tokens. Currently, each access creates a new layer, so doing the above would create a four-dimensionallist. Two consequences of this decision:doc.pages.paragraphs.sentences.tokens[0][0][0][0], which is a bit ugly.doc.pages.paragraphs.pagesdoes not return the originalLayerof pages., which is a bit uninutitiveThe main question is: "Should chained accessing return the union of all of the entities in a single layer or should it return the entities in the shape of the chained accessing?"
As another example, if the doc is
Which should
doc.paragraphs.sentences.textreturn?