Permalink
Browse files

Simple refactor introducing the addRecord function

  • Loading branch information...
1 parent b9110c2 commit 9c3864258f2aa2ce8deec11a668980ed0a3ac37c Zack Maril committed Jul 1, 2014
Showing with 19 additions and 22 deletions.
  1. +12 −3 bokonon/being.py
  2. +7 −19 bokonon/load.py
View
@@ -1,9 +1,18 @@
from collections import defaultdict
import copy
from networkx import nx
+import uuid
-being = {"label": "Being", "shape":"rectangle", "type": "Being"}
-represents = {"label":"represents", "relation":"represents"}
+being = lambda : {"type": "Being"}
+represents = lambda : {"relation":"represents"}
+
+def addRecord(universe,record):
+ rid = str(uuid.uuid1())
+ bid = str(uuid.uuid1())
+ universe.add_node(bid,being())
+ universe.add_node(rid,record)
+ universe.add_edge(rid,bid,represents())
+ return rid
def findBeing(universe,l):
beings = []
@@ -23,7 +32,7 @@ def mergeTheirBeings(universe,al,bl):
b = findBeing(universe,bl)
if a != b:
for v in nx.neighbors(universe,b):
- universe.add_edge(v,a,copy.copy(represents))
+ universe.add_edge(v,a,represents())
universe.remove_edge(v,b)
av = universe.node[a]
bv = universe.node[b]
View
@@ -1,15 +1,14 @@
import codecs
-import copy
import json
from glob import glob
import multiprocessing
import networkx as nx
import os
import pickle
-import uuid
+
from text import preProcess
-from being import being, represents
+from being import addRecord
processed_files = 'processed_files'
processed_graph = 'processed_graph'
@@ -127,9 +126,8 @@ def loadData():
print("Loading and processing files now")
p = multiprocessing.Pool(8)
data = p.map(loadForm1,glob(os.environ["HOUSEXML"]+"/LD1/*/*/*.json"),10)
- data += p.map(loadForm2,glob(os.environ["HOUSEXML"]+"/LD2/*/*/*.json"),10)
+ #data += p.map(loadForm2,glob(os.environ["HOUSEXML"]+"/LD2/*/*/*.json"),10)
-
print("Starting from {} records".format(len(data)))
print("Building universe")
for col in data:
@@ -138,21 +136,11 @@ def loadData():
(client,firm,employs) = col
if client["name"] == "":
continue
-
- cnode = str(uuid.uuid1())
- fnode = str(uuid.uuid1())
- cbeing = str(uuid.uuid1())
- fbeing = str(uuid.uuid1())
- universe.add_node(cbeing,copy.copy(being))
- universe.add_node(cnode,client)
- universe.add_edge(cnode,cbeing,copy.copy(represents))
-
- universe.add_node(fbeing,copy.copy(being))
- universe.add_node(fnode,firm)
- universe.add_edge(fnode,fbeing,copy.copy(represents))
-
- universe.add_edge(fnode,cnode,employs)
+ cid = addRecord(universe,client)
+ fid = addRecord(universe,firm)
+ universe.add_edge(fid,cid,employs)
+
print("Universe loaded and built, saving now")
with open(processed_graph,"w") as f:
pickle.dump(universe,f,2)

0 comments on commit 9c38642

Please sign in to comment.