当前位置: 首页>>代码示例>>Python>>正文


Python Record.attrib['word_count']方法代码示例

本文整理汇总了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'])
开发者ID:mbwolff,项目名称:PhiloLogic4,代码行数:22,代码来源:LoadFilters.py

示例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'])
开发者ID:clovis,项目名称:PhiloLogic4,代码行数:23,代码来源:LoadFilters.py


注:本文中的philologic.OHCOVector.Record.attrib['word_count']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。