本文整理汇总了Python中nltk.corpus.reader.XMLCorpusView方法的典型用法代码示例。如果您正苦于以下问题:Python reader.XMLCorpusView方法的具体用法?Python reader.XMLCorpusView怎么用?Python reader.XMLCorpusView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.corpus.reader
的用法示例。
在下文中一共展示了reader.XMLCorpusView方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _buildrelationindex
# 需要导入模块: from nltk.corpus import reader [as 别名]
# 或者: from nltk.corpus.reader import XMLCorpusView [as 别名]
def _buildrelationindex(self):
#print('building relation index...', file=sys.stderr)
freltypes = PrettyList(x for x in XMLCorpusView(self.abspath("frRelation.xml"),
'frameRelations/frameRelationType',
self._handle_framerelationtype_elt))
self._freltyp_idx = {}
self._frel_idx = {}
self._frel_f_idx = defaultdict(set)
self._ferel_idx = {}
for freltyp in freltypes:
self._freltyp_idx[freltyp.ID] = freltyp
for frel in freltyp.frameRelations:
supF = frel.superFrame = frel[freltyp.superFrameName] = Future((lambda fID: lambda: self.frame_by_id(fID))(frel.supID))
subF = frel.subFrame = frel[freltyp.subFrameName] = Future((lambda fID: lambda: self.frame_by_id(fID))(frel.subID))
self._frel_idx[frel.ID] = frel
self._frel_f_idx[frel.supID].add(frel.ID)
self._frel_f_idx[frel.subID].add(frel.ID)
for ferel in frel.feRelations:
ferel.superFrame = supF
ferel.subFrame = subF
ferel.superFE = Future((lambda fer: lambda: fer.superFrame.FE[fer.superFEName])(ferel))
ferel.subFE = Future((lambda fer: lambda: fer.subFrame.FE[fer.subFEName])(ferel))
self._ferel_idx[ferel.ID] = ferel
#print('...done building relation index', file=sys.stderr)
示例2: _lu_file
# 需要导入模块: from nltk.corpus import reader [as 别名]
# 或者: from nltk.corpus.reader import XMLCorpusView [as 别名]
def _lu_file(self, lu, ignorekeys=[]):
"""
Augment the LU information that was loaded from the frame file
with additional information from the LU file.
"""
fn_luid = lu.ID
fname = "lu{0}.xml".format(fn_luid)
locpath = os.path.join("{0}".format(self._root), self._lu_dir, fname)
#print(locpath, file=sys.stderr)
if not self._lu_idx:
self._buildluindex()
try:
elt = XMLCorpusView(locpath, 'lexUnit')[0]
except IOError:
raise FramenetError('Unknown LU id: {0}'.format(fn_luid))
lu2 = self._handle_lexunit_elt(elt, ignorekeys)
lu.subCorpus = lu2.subCorpus
return lu.subCorpus
示例3: _buildframeindex
# 需要导入模块: from nltk.corpus import reader [as 别名]
# 或者: from nltk.corpus.reader import XMLCorpusView [as 别名]
def _buildframeindex(self):
# The total number of Frames in Framenet is fairly small (~1200) so
# this index should not be very large
if not self._frel_idx:
self._buildrelationindex() # always load frame relations before frames,
# otherwise weird ordering effects might result in incomplete information
self._frame_idx = {}
for f in XMLCorpusView(self.abspath("frameIndex.xml"),
'frameIndex/frame', self._handle_elt):
self._frame_idx[f['ID']] = f
示例4: _buildcorpusindex
# 需要导入模块: from nltk.corpus import reader [as 别名]
# 或者: from nltk.corpus.reader import XMLCorpusView [as 别名]
def _buildcorpusindex(self):
# The total number of fulltext annotated documents in Framenet
# is fairly small (~90) so this index should not be very large
self._fulltext_idx = {}
for doclist in XMLCorpusView(self.abspath("fulltextIndex.xml"),
'fulltextIndex/corpus',
self._handle_fulltextindex_elt):
for doc in doclist:
self._fulltext_idx[doc.ID] = doc
示例5: _buildluindex
# 需要导入模块: from nltk.corpus import reader [as 别名]
# 或者: from nltk.corpus.reader import XMLCorpusView [as 别名]
def _buildluindex(self):
# The number of LUs in Framenet is about 13,000 so this index
# should not be very large
self._lu_idx = {}
for lu in XMLCorpusView(self.abspath("luIndex.xml"),
'luIndex/lu', self._handle_elt):
self._lu_idx[lu['ID']] = lu # populate with LU index entries. if any of these
# are looked up they will be replaced by full LU objects.
示例6: _lu_file
# 需要导入模块: from nltk.corpus import reader [as 别名]
# 或者: from nltk.corpus.reader import XMLCorpusView [as 别名]
def _lu_file(self, lu, ignorekeys=[]):
"""
Augment the LU information that was loaded from the frame file
with additional information from the LU file.
"""
fn_luid = lu.ID
fname = "lu{0}.xml".format(fn_luid)
locpath = os.path.join("{0}".format(self._root), self._lu_dir, fname)
#print(locpath, file=sys.stderr)
if not self._lu_idx:
self._buildluindex()
try:
elt = XMLCorpusView(locpath, 'lexUnit')[0]
except IOError:
raise FramenetError('Unknown LU id: {0}'.format(fn_luid))
lu2 = self._handle_lexunit_elt(elt, ignorekeys)
lu.URL = self._fnweb_url + '/' + self._lu_dir + '/' + fname
lu.subCorpus = lu2.subCorpus
lu.exemplars = SpecialList('luexemplars',
[sent for subc in lu.subCorpus for sent in subc.sentence])
for sent in lu.exemplars:
sent['LU'] = lu
sent['frame'] = lu.frame
for aset in sent.annotationSet:
aset['LU'] = lu
aset['frame'] = lu.frame
return lu