Add sort pipe#131
Merged
leifj merged 2 commits intoIdentityPython:masterfrom Feb 22, 2018
Merged
Conversation
Merge changes from upstream repo
leifj
requested changes
Feb 21, 2018
| return sv is None, sv, eid | ||
|
|
||
| container = root(t) | ||
| container[:] = sorted(container, key=lambda e: get_key(e)) |
Contributor
There was a problem hiding this comment.
does the lxml api guarantee that the tree behaves like a list?
Contributor
Author
There was a problem hiding this comment.
Not strictly, but it claims to "mimic the behaviour of normal Python lists as closely as possible" [1].
Anyway for sorting purposes, as much as I can understand they behave exactly the same, since they are both iterables [2][3]. Or am I missing something here?
References
[1] - http://lxml.de/tutorial.html#elements-are-lists
[2] - https://docs.python.org/2/library/functions.html#sorted
[3] - http://lxml.de/api.html#iteration
Contributor
There was a problem hiding this comment.
I guess that is the sort of analysis I was looking for. Makes sense as a first approxmition at least!
leifj
approved these changes
Feb 22, 2018
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.
This code implements a sort pipe as discussed in #130
By default entities are sorted by
entityIDbut the pipe can also be configured with an xpath which specifies the value used as primary sort key (entityIDwill still be used as secondary sort key).Tests include some implementation knowledge to avoid false positives as much as possible. i.e. sorting 3 elements originally in a random order, has a non-negligible probability to pass by chance.
One possible improvement could be to use input arguments instead of optional parameters for the xpath specification, allowing an arbitrary number of sort criteria.
Note: I am not so familiar with pyFF design nor python, so please verify that the new code is inserted in the right places and follows project and language conventions.
I believe this could also have been accomplished by the inclusion of an XSLT sort template, to be used by the existing
xsltpipe.