|
26 | 26 | from .context_resolver import ContextResolver |
27 | 27 | from c14n.Canonicalize import canonicalize |
28 | 28 | from cachetools import LRUCache |
29 | | -from collections import namedtuple |
30 | | -from functools import cmp_to_key |
31 | 29 | import lxml.html |
32 | 30 | from numbers import Integral, Real |
33 | 31 | from frozendict import frozendict |
34 | 32 | from pyld.__about__ import (__copyright__, __license__, __version__) |
35 | 33 | from .iri_resolver import resolve, unresolve |
36 | 34 |
|
37 | | -def cmp(a, b): |
38 | | - return (a > b) - (a < b) |
39 | | - |
40 | 35 | __all__ = [ |
41 | 36 | '__copyright__', '__license__', '__version__', |
42 | 37 | 'compact', 'expand', 'flatten', 'frame', 'link', 'from_rdf', 'to_rdf', |
@@ -4663,7 +4658,7 @@ def _compact_iri( |
4663 | 4658 | # lexicographically less than the current choice |
4664 | 4659 | if (is_usable_curie and ( |
4665 | 4660 | candidate is None or |
4666 | | - _compare_shortest_least(curie, candidate) < 0)): |
| 4661 | + (len(curie), curie) < (len(candidate), candidate))): |
4667 | 4662 | candidate = curie |
4668 | 4663 |
|
4669 | 4664 | # return curie candidate |
@@ -5353,8 +5348,8 @@ def _get_inverse_context(self, active_ctx): |
5353 | 5348 | # create term selections for each mapping in the context, ordered by |
5354 | 5349 | # shortest and then lexicographically least |
5355 | 5350 | for term, mapping in sorted( |
5356 | | - active_ctx['mappings'].items(), |
5357 | | - key=cmp_to_key(_compare_shortest_least)): |
| 5351 | + active_ctx['mappings'].items(), |
| 5352 | + key=lambda kv: (len(kv[0]), kv[0])): |
5358 | 5353 | if mapping is None or not mapping.get('@id'): |
5359 | 5354 | continue |
5360 | 5355 |
|
@@ -5649,8 +5644,7 @@ def main(self, dataset, options): |
5649 | 5644 |
|
5650 | 5645 | # 6.3) For each result in the hash path list, |
5651 | 5646 | # lexicographically-sorted by the hash in result: |
5652 | | - cmp_hashes = cmp_to_key(lambda x, y: cmp(x['hash'], y['hash'])) |
5653 | | - for result in sorted(hash_path_list, key=cmp_hashes): |
| 5647 | + for result in sorted(hash_path_list, key=lambda r: r['hash']): |
5654 | 5648 | # 6.3.1) For each blank node identifier, existing identifier, |
5655 | 5649 | # that was issued a temporary identifier by identifier issuer |
5656 | 5650 | # in result, issue a canonical identifier, in the same order, |
@@ -6060,19 +6054,7 @@ def permutations(elements): |
6060 | 6054 | left[elements[i]] = not left[elements[i]] |
6061 | 6055 |
|
6062 | 6056 |
|
6063 | | -def _compare_shortest_least(a, b): |
6064 | | - """ |
6065 | | - Compares two strings first based on length and then lexicographically. |
6066 | | -
|
6067 | | - :param a: the first string. |
6068 | | - :param b: the second string. |
6069 | 6057 |
|
6070 | | - :return: -1 if a < b, 1 if a > b, 0 if a == b. |
6071 | | - """ |
6072 | | - rval = cmp(len(a), len(b)) |
6073 | | - if rval == 0: |
6074 | | - rval = cmp(a, b) |
6075 | | - return rval |
6076 | 6058 |
|
6077 | 6059 |
|
6078 | 6060 | def _is_keyword(v): |
|
0 commit comments