本文整理汇总了Python中trie.Trie.in_trie方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.in_trie方法的具体用法?Python Trie.in_trie怎么用?Python Trie.in_trie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.in_trie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Pruner
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import in_trie [as 别名]
class Pruner(object):
def __init__(self, **kwargs):
self.file_a = kwargs.get('file_a')
self.file_b = kwargs.get('file_b')
self.file_c = kwargs.get('file_c')
self.file_d = kwargs.get('file_d', 'junk_out.csv')
# self.number_of_lines = kwargs.get('number_of_lines', 800000)
self.trie = Trie()
def prune(self):
input_file_a = open(self.file_a, 'rU')
data = csv.reader((line.replace('\0', '') for line in input_file_a),
delimiter=",")
i = 0
j = 0
for line in data:
i += 1
if (len(line) < 1):
j += 1
else:
line = self.parse_string(line[0])
self.trie.insert_trie(line)
print 'Total Number of lines inserted in input'+str(i)
print 'Total Number of lines skipped while inserting'+str(j)
input_file_a.close()
input_file_b = open(self.file_b, 'rU')
data = csv.reader((line.replace('\0', '') for line in input_file_b),
delimiter=",")
output_file_c = open(self.file_c, 'w')
output_file_d = open(self.file_d, 'w')
csv_writer_file_c = csv.writer(output_file_c, delimiter=",")
csv_writer_file_d = csv.writer(output_file_d, delimiter=",")
j = 0
k = 0
for line in data:
if (len(line) < 1):
continue
line = self.parse_string(line[0])
if self.trie.in_trie(line):
j += 1
csv_writer_file_d.writerow(line)
else:
k += 1
csv_writer_file_c.writerow(line)
print str(j) + ' in junk'
print str(k) + ' in output'
output_file_c.close()
output_file_d.close()
print 'Done'
def parse_string(self, input_str=''):
return str(input_str)