-
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 paths tests and similarity tests; fix path bug
The bug was that a fake root node was not inserted if there were no hypernym paths. Now the root is the sole node of the sole path in that case. Fix #64; actually this was fixed a while ago, but now it's better tested
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
import pytest | ||
|
||
import wn | ||
|
||
|
||
@pytest.mark.usefixtures('mini_db') | ||
def test_hypernym_paths(): | ||
information = wn.synsets('information')[0] | ||
example = wn.synsets('example')[0] | ||
sample = wn.synsets('sample')[0] | ||
random_sample = wn.synsets('random sample')[0] | ||
assert information.hypernym_paths() == [] | ||
assert example.hypernym_paths() == [[information]] | ||
assert sample.hypernym_paths() == [[example, information]] | ||
assert random_sample.hypernym_paths() == [[sample, example, information]] | ||
|
||
|
||
@pytest.mark.usefixtures('mini_db') | ||
def test_interlingual_hypernym_paths(): | ||
información = wn.synsets('información')[0] | ||
ejemplo = wn.synsets('ejemplo')[0] | ||
inferred = wn.Synset.empty('*INFERRED*') | ||
muestra_aleatoria = wn.synsets('muestra aleatoria')[0] | ||
assert información.hypernym_paths() == [] | ||
assert ejemplo.hypernym_paths() == [[información]] | ||
assert muestra_aleatoria.hypernym_paths() == [[inferred, ejemplo, información]] | ||
|
||
|
||
@pytest.mark.usefixtures('mini_db') | ||
def test_shortest_path(): | ||
information = wn.synsets('information')[0] | ||
example = wn.synsets('example')[0] | ||
sample = wn.synsets('sample')[0] | ||
random_sample = wn.synsets('random sample')[0] | ||
datum = wn.synsets('datum')[0] | ||
exemplify = wn.synsets('exemplify')[0] | ||
inferred_root = wn.Synset.empty('*INFERRED*') | ||
assert information.shortest_path(information) == [] | ||
assert information.shortest_path(datum) == [datum] | ||
assert information.shortest_path(sample) == [example, sample] | ||
assert sample.shortest_path(information) == [example, information] | ||
assert random_sample.shortest_path(datum) == [sample, example, information, datum] | ||
with pytest.raises(wn.Error): | ||
example.shortest_path(exemplify) | ||
assert example.shortest_path(exemplify, simulate_root=True) == [ | ||
information, inferred_root, exemplify | ||
] | ||
|
||
|
||
@pytest.mark.usefixtures('mini_db') | ||
def test_min_depth(): | ||
assert wn.synsets('information')[0].min_depth() == 0 | ||
assert wn.synsets('example')[0].min_depth() == 1 | ||
assert wn.synsets('sample')[0].min_depth() == 2 | ||
assert wn.synsets('random sample')[0].min_depth() == 3 | ||
|
||
|
||
@pytest.mark.usefixtures('mini_db') | ||
def test_max_depth(): | ||
assert wn.synsets('information')[0].max_depth() == 0 | ||
assert wn.synsets('example')[0].max_depth() == 1 | ||
assert wn.synsets('sample')[0].max_depth() == 2 | ||
assert wn.synsets('random sample')[0].max_depth() == 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import pytest | ||
|
||
import wn | ||
from wn import similarity as sim | ||
|
||
|
||
@pytest.mark.usefixtures('mini_db') | ||
def test_path(): | ||
information = wn.synsets('information')[0] | ||
example = wn.synsets('example')[0] | ||
sample = wn.synsets('sample')[0] | ||
random_sample = wn.synsets('random sample')[0] | ||
datum = wn.synsets('datum')[0] | ||
exemplify = wn.synsets('exemplify')[0] | ||
assert sim.path(information, information) == 1/1 | ||
assert sim.path(information, example) == 1/2 | ||
assert sim.path(information, sample) == 1/3 | ||
assert sim.path(information, random_sample) == 1/4 | ||
assert sim.path(random_sample, datum) == 1/5 | ||
assert sim.path(example, exemplify) == 1/4 | ||
|
||
|
||
@pytest.mark.usefixtures('mini_db') | ||
def test_wup(): | ||
information = wn.synsets('information')[0] | ||
example = wn.synsets('example')[0] | ||
sample = wn.synsets('sample')[0] | ||
random_sample = wn.synsets('random sample')[0] | ||
datum = wn.synsets('datum')[0] | ||
exemplify = wn.synsets('exemplify')[0] | ||
assert sim.wup(information, information) == (2*1) / (0+0+2*1) | ||
assert sim.wup(information, example) == (2*1) / (0+1+2*1) | ||
assert sim.wup(information, sample) == (2*1) / (0+2+2*1) | ||
assert sim.wup(information, random_sample) == (2*1) / (0+3+2*1) | ||
assert sim.wup(random_sample, datum) == (2*1) / (3+1+2*1) | ||
assert sim.wup(example, exemplify) == (2*1) / (2+1+2*1) |
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