Skip to content

Add sort pipe#131

Merged
leifj merged 2 commits intoIdentityPython:masterfrom
clarin-eric:sort-pipe
Feb 22, 2018
Merged

Add sort pipe#131
leifj merged 2 commits intoIdentityPython:masterfrom
clarin-eric:sort-pipe

Conversation

@andmor-
Copy link
Copy Markdown
Contributor

@andmor- andmor- commented Feb 20, 2018

This code implements a sort pipe as discussed in #130
By default entities are sorted by entityID but the pipe can also be configured with an xpath which specifies the value used as primary sort key (entityID will 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 xslt pipe.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 82.84% when pulling 5be0ec1 on clarin-eric:sort-pipe into 7ddc5da on IdentityPython:master.

Comment thread src/pyff/samlmd.py
return sv is None, sv, eid

container = root(t)
container[:] = sorted(container, key=lambda e: get_key(e))
Copy link
Copy Markdown
Contributor

@leifj leifj Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the lxml api guarantee that the tree behaves like a list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that is the sort of analysis I was looking for. Makes sense as a first approxmition at least!

@leifj leifj merged commit 9c9e766 into IdentityPython:master Feb 22, 2018
@andmor- andmor- deleted the sort-pipe branch February 22, 2018 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants