本文整理汇总了Python中philologic.OHCOVector.Record.attrib['word_count']方法的典型用法代码示例。如果您正苦于以下问题:Python Record.attrib['word_count']方法的具体用法?Python Record.attrib['word_count']怎么用?Python Record.attrib['word_count']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类philologic.OHCOVector.Record
的用法示例。
在下文中一共展示了Record.attrib['word_count']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_word_counts
# 需要导入模块: from philologic.OHCOVector import Record [as 别名]
# 或者: from philologic.OHCOVector.Record import attrib['word_count'] [as 别名]
def make_word_counts(loader_obj, text, depth=5):
object_types = ['doc', 'div1', 'div2', 'div3', 'para', 'sent', 'word']
counts = [0 for i in range(depth)]
temp_file = text['raw'] + '.tmp'
output_file = open(temp_file, 'w')
for line in open(text['raw']):
type, word, id, attrib = line.split('\t')
id = id.split()
record = Record(type, word, id)
record.attrib = eval(attrib)
for d,count in enumerate(counts):
if type == 'word':
counts[d] += 1
elif type == object_types[d]:
record.attrib['word_count'] = counts[d]
counts[d] = 0
print >> output_file, record
output_file.close()
os.remove(text['raw'])
os.rename(temp_file, text['raw'])
示例2: make_word_counts
# 需要导入模块: from philologic.OHCOVector import Record [as 别名]
# 或者: from philologic.OHCOVector.Record import attrib['word_count'] [as 别名]
def make_word_counts(loader_obj, text, depth=5):
object_types = ['doc', 'div1', 'div2', 'div3', 'para', 'sent', 'word']
counts = [0 for i in range(depth)]
temp_file = text['raw'] + '.tmp'
output_file = open(temp_file, 'w')
with open(text['raw']) as filehandle:
for line in filehandle:
philo_type, word, philo_id, attrib = line.split('\t')
philo_id = philo_id.split()
record = Record(philo_type, word, philo_id)
record.attrib = loads(attrib)
for d, count in enumerate(counts):
if philo_type == 'word':
counts[d] += 1
elif philo_type == object_types[d]:
record.attrib['word_count'] = counts[d]
counts[d] = 0
print(record, file=output_file)
output_file.close()
os.remove(text['raw'])
os.rename(temp_file, text['raw'])