示例#1
0
 def kw_num(self):
     nums = []
     for file in os.listdir(self.filepath):
         filename = os.path.join(self.filepath, file)
         kws = FileUtil.readupkws(filename)
         nums.append(len(kws))
     return nums
示例#2
0
    def key2loc(self, keywords, filename='.'):
        col_bits = self.col_bits
        n = pow(2, col_bits)
        _url = FileUtil.readurl(filename)
        text_kws = FileUtil.readupkws(filename)
        row, col, p = self.location(keywords=keywords, text_list=text_kws)  # 得到每个关键词的坐标(x,y)
        row_bits = len(self._dec2bin(len(text_kws) // n))  # 总行数的二进制表示所需的比特数
        s = ''
        print('location information: ')
        for r, c in zip(row, col):
            loc = self._dec2bin(num=r, bits=row_bits) + \
                self._dec2bin(num=c, bits=col_bits)
            print(loc)
            s = s + loc
        num_add_col_bits = self._dec2bin(col_bits, 5)  # col_bits作为密钥,5位补全二进制流
        _res = ''
        if len(s) % 8 == 0:
            _res = '000' + num_add_col_bits + s
        else:
            num = 8 - len(s) % 8     # 补0的个数
            num_add = self._dec2bin(num, 3)
            _res = num_add + num_add_col_bits + s + '0' * num

        return _url, _res, p