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


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

本文整理汇总了Python中philologic.OHCOVector.Record.attrib['bytes']方法的典型用法代码示例。如果您正苦于以下问题:Python Record.attrib['bytes']方法的具体用法?Python Record.attrib['bytes']怎么用?Python Record.attrib['bytes']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在philologic.OHCOVector.Record的用法示例。


在下文中一共展示了Record.attrib['bytes']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: inner_word_frequencies_per_obj

# 需要导入模块: from philologic.OHCOVector import Record [as 别名]
# 或者: from philologic.OHCOVector.Record import attrib['bytes'] [as 别名]
 def inner_word_frequencies_per_obj(loader_obj,text):
     files_path = loader_obj.destination + '/WORK/'
     try:
         os.mkdir(files_path)
     except OSError:
         ## Path was already created                                                                                                                                       
         pass
     for obj, d in obj_types.iteritems():
         file = text['name'] + '.%s.freq_counts' % obj
         output = open(files_path + file, 'w')
         old_philo_id = []
         old_word = ''
         records = {}
         for line in open(text['words']):
             type, word, id, attrib = line.split('\t')
             attrib = eval(attrib)
             ## Dismiss all irrelevant fields while making sure we still have 9 fields in the end
             philo_id = id.split()[:d] + [0 for i in range(7-d)] + [0,0]
             record = Record(type, word, philo_id)
             count_key = obj + '_token_count'
             byte = attrib['byte_start']
             del attrib['byte_start']
             record.attrib = {'token_count': attrib[count_key]}
             if philo_id[:d] != old_philo_id[:d] or word != old_word:
                 if records and old_word:
                     for w in records:
                         print >> output, records[w]
                         records = {}
             if word not in records:
                 record.attrib['bytes'] = []
                 record.attrib['bytes']= str(byte)
                 records[word] = record
             else:
                 records[word].attrib['bytes'] += ' ' + str(byte)
             old_philo_id = philo_id
             old_word = word
         for w in records:
             print >> output, records[w]
         output.close()
开发者ID:ARTFL-Project,项目名称:libphilo,代码行数:41,代码来源:LoadFilters.py

示例2: word_frequencies_per_obj

# 需要导入模块: from philologic.OHCOVector import Record [as 别名]
# 或者: from philologic.OHCOVector.Record import attrib['bytes'] [as 别名]
def word_frequencies_per_obj(loader_obj, text, depth=1):
    object_types = ['doc', 'div1', 'div2', 'div3', 'para', 'sent', 'word'][:depth]
    files_path = loader_obj.destination + '/WORK/'
    try:
        os.mkdir(files_path)
    except OSError:
        ## Path was already created                                                                                                                                       
        pass
    for d, obj in enumerate(object_types):
        file = text['name'] + '.%s.sorted' % obj
        output = open(files_path + file, 'w')
        d = d + 1
        old_philo_id = []
        records = {}
        for line in open(text['words']):
            type, word, id, attrib = line.split('\t')
            attrib = eval(attrib)
            philo_id = id.split()
            record = Record(type, word, philo_id)
            count_key = obj + '_token_count'
            byte = attrib['byte_start']
            del attrib['byte_start']
            record.attrib = {count_key: attrib[count_key]}
            if philo_id[:d] != old_philo_id[:d]:
                if records:
                    for w in records:
                        print >> output, records[w]
                        records = {}
            if word not in records:
                record.attrib['bytes'] = []
                record.attrib['bytes']= str(byte)
                records[word] = record
            else:
                records[word].attrib['bytes'] += ' ' + str(byte)
            old_philo_id = philo_id
        for w in records:
            print >> output, records[w]
        output.close()
开发者ID:waltms,项目名称:libphilo,代码行数:40,代码来源:LoadFilters.py


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