本文整理汇总了Python中xml.dom.minidom.Document.length方法的典型用法代码示例。如果您正苦于以下问题:Python Document.length方法的具体用法?Python Document.length怎么用?Python Document.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Document
的用法示例。
在下文中一共展示了Document.length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preprocessing
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import length [as 别名]
def preprocessing(self):
'''
:function 执行数据预处理操作
:return:
'''
print (u'载入数据......')
# 打开文件读入数据
with codecs.open(trainfile, 'r', 'utf-8') as f:
docs = f.readlines()
print (u"载入完成,准备生成字典对象和统计文本数据...")
# 记录某个词的下标
items_idx = 0
# 读取文档的每一行
for line in docs:
if line != "":
tmp = line.strip().split()
# 生成一个文档对象
doc = Document()
# 遍历所有的词汇
for item in tmp:
# 判断是否已经包含了该词汇
if self.word2id.has_key(item):
# 如果已经包含则直接添加
doc.words.append(self.word2id[item])
else:
# 否则将该词汇的下标设置为items_idx
self.word2id[item] = items_idx
# 将该单词下标添加到文档列表
doc.words.append(items_idx)
# 单词下标加1
items_idx += 1
# 设置文档长度
doc.length = len(tmp)
self.docs.append(doc)
else:
pass
self.docs_count = len(self.docs)
self.words_count = len(self.word2id)
print (u"共有%s个文档" % self.docs_count)
self.cachewordidmap()
print (u"词与序号对应关系已保存到%s" % wordidmapfile)