-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a28d256
commit 70015f7
Showing
3 changed files
with
44 additions
and
5 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,38 @@ | ||
import pytest | ||
|
||
from nltk.data import find | ||
from nltk.parse.bllip import BllipParser | ||
from nltk.tree import Tree | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def parser(): | ||
model_dir = find("models/bllip_wsj_no_aux").path | ||
return BllipParser.from_unified_model_dir(model_dir) | ||
|
||
|
||
class TestBllipParser: | ||
def test_parser_loads_a_valid_tree(self, parser): | ||
parsed = parser.parse("I saw the man with the telescope") | ||
tree = next(parsed) | ||
|
||
assert isinstance(tree, Tree) | ||
assert ( | ||
tree.pformat() | ||
== """ | ||
(S1 | ||
(S | ||
(NP (PRP I)) | ||
(VP | ||
(VBD saw) | ||
(NP (DT the) (NN man)) | ||
(PP (IN with) (NP (DT the) (NN telescope)))))) | ||
""".strip() | ||
) | ||
|
||
def test_tagged_parse_finds_matching_element(self, parser): | ||
parsed = parser.parse("I saw the man with the telescope") | ||
tagged_tree = next(parser.tagged_parse([("telescope", "NN")])) | ||
|
||
assert isinstance(tagged_tree, Tree) | ||
assert tagged_tree.pformat() == "(S1 (NP (NN telescope)))" |