當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。