-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgraph_reducer.py
More file actions
30 lines (27 loc) · 812 Bytes
/
graph_reducer.py
File metadata and controls
30 lines (27 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
"""
This code reduces input to generate all distinct items and their counts
"""
import sys
from ConfigParser import *
current_node = None
current_item = None
item = None
node = None
config = ConfigParser()
config.read('config.ini')
for line in sys.stdin:
line = line.strip()
node,item = line.split(config.get('counting','separator'), 1)
if current_node == node:
if current_item == None:
current_item = item
else:
current_item = current_item + config.get('counting','delimiter') + item
else:
if current_node:
print current_node + config.get('counting','separator') + str(current_item)
current_item = item
current_node = node
if current_node == node:
print current_node + config.get('counting','separator') + str(current_item)