Here is the screenshot for turtles (which apparently have lots of fans):
It was interesting to me how many of the supposed attributes showed up repeatedly across entities. This gave me an idea: I should turn this procrastination/time-wasting into something more useful, which was to learn how to make graph/network plots with the python package networkx (code below). Here is the result, using the top 4 auto-suggests for cats, children, cows, dogs, frogs, goldfish, hamsters, mice, turtles and pigs. Entities are in blue, attributes in red. Edges are drawn if that attribute was auto-suggested for that entity.
Some observations
I'm guessing the "addicting" and"good" attributes of goldfish refers to the cheesy snack cracker and not the actual fish. People seem to be rather ambivalent about children. I'm kind of surprised that people were not wondering why dogs are smart. Finally, are pigs actually salty (this seems unlikely), or this just how pork is usually prepared?
The code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import matplotlib.pyplot as plt | |
relationships = { | |
'cats':['cute', 'clean', 'curious', 'lazy'], | |
'children':['cruel', 'happy', 'mean', 'stupid'], | |
'cows':['fat', 'sacred to hindus', 'stupid', 'sacred'], | |
'dogs':['loyal', 'cute', 'loving', 'happy'], | |
'frogs':['happy', 'slimy', 'important', 'sensitive to pollution'], | |
'goldfish':['dirty', 'good', 'addicting', 'hard to keep alive'], | |
'hamsters':['cute', 'stupid', 'little'], | |
'mice':['cute', 'scary', 'smart', 'small'], | |
'turtles':['slow', 'awesome', 'cool', 'important'], | |
'pigs':['smart', 'fat', 'similar to humans', 'salty'], | |
} | |
G = nx.Graph() | |
G.type = {} | |
# add entities | |
for r in relationships: | |
G.add_node(r) | |
G.type[r] = "Entity" | |
# add attributes | |
_attributes = [] | |
for attr in relationships.values(): | |
_attributes.extend(attr) | |
attributes = list(set(_attributes)) | |
for a in attributes: | |
G.add_node(a) | |
G.type[a] = "Attribute" | |
# add all the edges | |
for key, attrs in relationships.items(): | |
for a in attrs: | |
G.add_edge(key, a) | |
node_color = [] | |
node_size = [] | |
for n in G.nodes(): | |
node_color.append(.1 if G.type[n] == 'Entity' else .8) | |
node_size.append(600 if G.type[n] == 'Entity' else 100) | |
pos = nx.graphviz_layout(G) | |
nx.draw(G, | |
pos, | |
node_size=node_size, | |
node_color = node_color, | |
edge_color='black', | |
font_size=8, | |
alpha = .2) | |
plt.savefig("relationships.png",dpi=200) | |
plt.show() | |
nice coding: short, sweet, does the job.
ReplyDeleteThanks JC - how have you been?
Delete