-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Relation class and .relation_map() methods (#227)
* Change _DatabaseEntity._ENTITY_TYPE to enum * Add Relation class * Add Sense.relation_map() and Synset.relation_map() methods, which is like .relations(), but the keys are Relation objects and map 1-to-1 to targets. * Add unique_list() utility function for code clarity
- Loading branch information
Showing
10 changed files
with
414 additions
and
115 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
from wn._util import flatten, unique_list | ||
|
||
|
||
def test_flatten(): | ||
assert flatten([]) == [] | ||
assert flatten([[]]) == [] | ||
assert flatten([[], []]) == [] | ||
assert flatten([[[], []], [[], []]]) == [[], [], [], []] | ||
assert flatten([[1]]) == [1] | ||
assert flatten([[1, 2], [3, 4]]) == [1, 2, 3, 4] | ||
assert flatten(["AB", "CD"]) == ["A", "B", "C", "D"] | ||
|
||
|
||
def test_unique_list(): | ||
assert unique_list([]) == [] | ||
assert unique_list([1]) == [1] | ||
assert unique_list([1, 1, 1, 1, 1]) == [1] | ||
assert unique_list([1, 1, 2, 2, 1]) == [1, 2] | ||
assert unique_list([2, 1, 2, 2, 1]) == [2, 1] | ||
assert unique_list("A") == ["A"] | ||
assert unique_list("AAA") == ["A"] | ||
assert unique_list("ABABA") == ["A", "B"] | ||
assert unique_list([(1, 2), (1, 2), (2, 3)]) == [(1, 2), (2, 3)] |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.