-
Notifications
You must be signed in to change notification settings - Fork 98
/
catchunked.py
112 lines (86 loc) · 4.6 KB
/
catchunked.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from nltk.corpus.reader import CategorizedCorpusReader, ChunkedCorpusReader
from nltk.corpus.reader import ConllCorpusReader, ConllChunkCorpusReader
class CategorizedChunkedCorpusReader(CategorizedCorpusReader, ChunkedCorpusReader):
"""
A reader for chunked corpora whose documents are divided into categories
based on their file identifiers.
"""
# code adapted from CategorizedTaggedCorpusReader
def __init__(self, *args, **kwargs):
CategorizedCorpusReader.__init__(self, kwargs)
ChunkedCorpusReader.__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 ChunkedCorpusReader.raw(self, self._resolve(fileids, categories))
def words(self, fileids=None, categories=None):
return ChunkedCorpusReader.words(self, self._resolve(fileids, categories))
def sents(self, fileids=None, categories=None):
return ChunkedCorpusReader.sents(self, self._resolve(fileids, categories))
def paras(self, fileids=None, categories=None):
return ChunkedCorpusReader.paras(self, self._resolve(fileids, categories))
def tagged_words(self, fileids=None, categories=None):
return ChunkedCorpusReader.tagged_words(self, self._resolve(fileids, categories))
def tagged_sents(self, fileids=None, categories=None):
return ChunkedCorpusReader.tagged_sents(self, self._resolve(fileids, categories))
def tagged_paras(self, fileids=None, categories=None):
return ChunkedCorpusReader.tagged_paras(self, self._resolve(fileids, categories))
def chunked_words(self, fileids=None, categories=None):
return ChunkedCorpusReader.chunked_words(
self, self._resolve(fileids, categories))
def chunked_sents(self, fileids=None, categories=None):
return ChunkedCorpusReader.chunked_sents(
self, self._resolve(fileids, categories))
def chunked_paras(self, fileids=None, categories=None):
return ChunkedCorpusReader.chunked_paras(
self, self._resolve(fileids, categories))
class CategorizedConllChunkCorpusReader(CategorizedCorpusReader, ConllChunkCorpusReader):
"""
A reader for conll chunked corpora whose documents are divided into
categories based on their file identifiers.
"""
def __init__(self, *args, **kwargs):
# NOTE: in addition to cat_pattern, ConllChunkCorpusReader also requires
# chunk_types as third argument, which defaults to ('NP','VP','PP')
CategorizedCorpusReader.__init__(self, kwargs)
ConllChunkCorpusReader.__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 ConllCorpusReader.raw(self, self._resolve(fileids, categories))
def words(self, fileids=None, categories=None):
return ConllCorpusReader.words(self, self._resolve(fileids, categories))
def sents(self, fileids=None, categories=None):
return ConllCorpusReader.sents(self, self._resolve(fileids, categories))
def tagged_words(self, fileids=None, categories=None):
return ConllCorpusReader.tagged_words(self, self._resolve(fileids, categories))
def tagged_sents(self, fileids=None, categories=None):
return ConllCorpusReader.tagged_sents(self, self._resolve(fileids, categories))
def chunked_words(self, fileids=None, categories=None, chunk_types=None):
return ConllCorpusReader.chunked_words(
self, self._resolve(fileids, categories), chunk_types)
def chunked_sents(self, fileids=None, categories=None, chunk_types=None):
return ConllCorpusReader.chunked_sents(
self, self._resolve(fileids, categories), chunk_types)
def parsed_sents(self, fileids=None, categories=None, pos_in_tree=None):
return ConllCorpusReader.parsed_sents(
self, self._resolve(fileids, categories), pos_in_tree)
def srl_spans(self, fileids=None, categories=None):
return ConllCorpusReader.srl_spans(self, self._resolve(fileids, categories))
def srl_instances(self, fileids=None, categories=None, pos_in_tree=None, flatten=True):
return ConllCorpusReader.srl_instances(
self, self._resolve(fileids, categories), pos_in_tree, flatten)
def iob_words(self, fileids=None, categories=None):
return ConllCorpusReader.iob_words(self, self._resolve(fileids, categories))
def iob_sents(self, fileids=None, categories=None):
return ConllCorpusReader.iob_sents(self, self._resolve(fileids, categories))