-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support symlinking to a full installation of the Penn Treebank via th…
…e ptb module (and companion modules propbank_ptb and nombank_ptb).
- Loading branch information
Showing
4 changed files
with
74 additions
and
6 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 |
---|---|---|
|
@@ -103,6 +103,63 @@ def _tag(self, t, simplify_tags=False): | |
def _word(self, t): | ||
return WORD.findall(self._normalize(t)) | ||
|
||
class CategorizedBracketParseCorpusReader(CategorizedCorpusReader, | ||
BracketParseCorpusReader): | ||
""" | ||
A reader for parsed corpora whose documents are | ||
divided into categories based on their file identifiers. | ||
@author: Nathan Schneider <[email protected]> | ||
""" | ||
def __init__(self, *args, **kwargs): | ||
""" | ||
Initialize the corpus reader. Categorization arguments | ||
(C{cat_pattern}, C{cat_map}, and C{cat_file}) are passed to | ||
the L{CategorizedCorpusReader constructor | ||
<CategorizedCorpusReader.__init__>}. The remaining arguments | ||
are passed to the L{BracketParseCorpusReader constructor | ||
<BracketParseCorpusReader.__init__>}. | ||
""" | ||
CategorizedCorpusReader.__init__(self, kwargs) | ||
BracketParseCorpusReader.__init__(self, *args, **kwargs) | ||
|
||
def _resolve(self, fileids, categories): | ||
if fileids is not None and categories is not None: | ||
raise ValueError('Specify fileids or categories, not both') | ||
if categories is not None: | ||
return self.fileids(categories) | ||
else: | ||
return fileids | ||
def raw(self, fileids=None, categories=None): | ||
return BracketParseCorpusReader.raw( | ||
self, self._resolve(fileids, categories)) | ||
def words(self, fileids=None, categories=None): | ||
return BracketParseCorpusReader.words( | ||
self, self._resolve(fileids, categories)) | ||
def sents(self, fileids=None, categories=None): | ||
return BracketParseCorpusReader.sents( | ||
self, self._resolve(fileids, categories)) | ||
def paras(self, fileids=None, categories=None): | ||
return BracketParseCorpusReader.paras( | ||
self, self._resolve(fileids, categories)) | ||
def tagged_words(self, fileids=None, categories=None, simplify_tags=False): | ||
return BracketParseCorpusReader.tagged_words( | ||
self, self._resolve(fileids, categories), simplify_tags) | ||
def tagged_sents(self, fileids=None, categories=None, simplify_tags=False): | ||
return BracketParseCorpusReader.tagged_sents( | ||
self, self._resolve(fileids, categories), simplify_tags) | ||
def tagged_paras(self, fileids=None, categories=None, simplify_tags=False): | ||
return BracketParseCorpusReader.tagged_paras( | ||
self, self._resolve(fileids, categories), simplify_tags) | ||
def parsed_words(self, fileids=None, categories=None): | ||
return BracketParseCorpusReader.parsed_words( | ||
self, self._resolve(fileids, categories)) | ||
def parsed_sents(self, fileids=None, categories=None): | ||
return BracketParseCorpusReader.parsed_sents( | ||
self, self._resolve(fileids, categories)) | ||
def parsed_paras(self, fileids=None, categories=None): | ||
return BracketParseCorpusReader.parsed_paras( | ||
self, self._resolve(fileids, categories)) | ||
|
||
class AlpinoCorpusReader(BracketParseCorpusReader): | ||
""" | ||
Reader for the Alpino Dutch Treebank. | ||
|
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