Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Work on improving the API
Browse files Browse the repository at this point in the history
  • Loading branch information
Zack Maril committed Jul 1, 2014
1 parent 1b74fe4 commit 9ed6fd5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
20 changes: 13 additions & 7 deletions bokonon/being.py
Expand Up @@ -82,12 +82,14 @@ def groupMerge(universe, pred,extract, description=None,logging=None):
print(txt)
print("")

def windowMerge(universe, pred, extract, windowSize, maxDistance, description=None):
def windowMerge(universe, selector, extract, windowSize, maxDistance,
pred = lambda x,y: True, description=None,logging=None):

if description != None:
print(description)
start = countTypes(universe)

nodes = filter(lambda t: pred(t[1]),universe.nodes(data=True))
nodes = filter(lambda t: selector(t[1]),universe.nodes(data=True))
d = {}
for k,v in nodes:
for s in extract(v):
Expand All @@ -100,11 +102,15 @@ def windowMerge(universe, pred, extract, windowSize, maxDistance, description=No
b = items[i+j]
dQ = distance(a[0],b[0]) <= maxDistance
bQ = findBeing(universe,a[1]) != findBeing(universe,b[1])
lQ = len(a[0]) > 5 and len(b[0]) > 5
if dQ and bQ and lQ:
# print(a[0])
# print(b[0])
# print("\n")
lQ = len(a[0]) > 5 and len(b[0]) > 5

an = universe.node[a[1]]
bn = universe.node[b[1]]
if dQ and bQ and lQ and pred(an,bn):
if logging != None:
print(logging(an))
print(logging(bn))
print("")
mergeTheirBeings(universe,a[1],b[1])

cullHermits(universe)
Expand Down
29 changes: 20 additions & 9 deletions bokonon/graph.py
Expand Up @@ -13,32 +13,43 @@ def main():
print("Loading universe...")
universe = loadData()

#Solid matching
groupMerge(universe,
matchTypeAndHasFields("client",["name"]),
lambda v: [v["name"]],
description="Merged clients based on exact name match")

#Surprisingly solid
groupMerge(universe,
matchTypeAndHasFields("client",["name"]),
lambda v: extractNames(v["name"]),
description="Merged clients based on extracted and cleaned name match")
lambda v: [re.sub(" ","",v["name"])],
description="Merged clients based on exact match without spaces")

#Solid
groupMerge(universe,
matchTypeAndHasFields("client",["name"]),
lambda v: [re.sub(" ","",v["name"])],
description="Merged clients based on exact match without spaces",
logging=represent)

lambda v: [re.sub("'","",v["name"])],
description="Merged clients based on exact match without 's")

#Most likely solid
groupMerge(universe,
matchTypeAndHasFields("client",["name"]),
lambda v: extractNames(v["name"]),
description="Merged clients based on extracted and cleaned name match"
)

#Not great
windowMerge(universe,
matchTypeAndHasFields("client",["name"]),
lambda v: extractNames(v["name"]),
5,
1,
description="Merged clients based on windowed extracted name matchs")
pred=lambda v,w: v["state"] == w["state"] and v["city"] == w["city"] and v["address"] == w["address"],
description="Merged clients based on windowed extracted name matchs",
logging=represent)

project(universe,"clientnames.txt", lambda v: v["type"] == "client", represent)


if __name__ == "__main__":
main()

main()

0 comments on commit 9ed6fd5

Please sign in to comment.