def grapher(): graph = Graph('foo') def cleanup(): #@IgnorePep8 graph._db.shutdown() import shutil try: shutil.rmtree('foo') except OSError: pass graph.on_anyway(cleanup) with graph.transaction(): gn = graph.nodes gn.w.create_index('roots') gn.w.create_index('questions') gn.w.create_index('question_text', fts=True) gn.w.create_index('ideas') gn.w.create_index('idea_text', fts=True) gn.w.create_index('pros') gn.w.create_index('pro_text', fts=True) gn.w.create_index('cons') gn.w.create_index('con_text', fts=True) gn.w.create_index('tags') root = gn.root() # question base create question = gn.create(text='question reference node') question.index_under('roots', 'reference', 'question') question.link('QUESTION_REFERENCE_FOR', root) # idea base create idea = gn.create(text='idea reference node') idea.index_under('roots', 'reference', 'idea') idea.link('IDEA_REFERENCE_FOR', root) # pro base create pro = gn.create(text='pro reference node') pro.index_under('roots', 'reference', 'pro') pro.link('PRO_REFERENCE_FOR', root) # con base create con = gn.create(text='con reference node') con.link('CON_REFERENCE_FOR', root) con.index_under('roots', 'reference', 'con') # tag base create tag = gn.create(text='tag reference node') tag.link('TAG_REFERENCE_FOR', root) tag.index_under('roots', 'reference', 'tag') # example tags tag_1 = gn.create( _model='tag', _status=1, text='wicked problem', user=1, ) tag_1.index_under('tags', 'name', 'wicked problem') tag_1.link('TAG_NODE_OF', tag, user=1) tag_2 = gn.create(text='avoid', user=1, _model='tag', _status=1) tag_2.index_under('tags', 'name', 'avoid') tag_2.link('TAG_NODE_OF', tag, user=1) # prime question question_0 = gn.create( _model='root_question', text='What is the prime question?', user=1, ) question_0.link('QUESTION_NODE_OF', question, user=1) question_0.index_under('roots', 'root', 'question') # root example question question_1 = gn.create( _model='question', _status=1, down=0, text='How do you avoid the wicked problem?', up=0, user=1, ) question_1.index_by('questions', '_created', 'user') question_1.index_by('question_text', 'text') question_1.link('QUESTION_NODE_OF', question, user=1) question_1.link('QUESTION_ROOTED_IN', question_0, user=1) # tag example question question_1.index_under('questions', 'tag', 'wicked problem') tag_1.link('TAGGED', question_1) question_1.index_under('questions', 'tag', 'avoid') tag_2.link('TAGGED', question_1) question_1.index_under('questions', 'prime', True) question_2 = gn.create( _model='question', _status=1, down=0, text="How do you even know it's a wicked problem?", up=0, user=1, ) question_2.index_by('questions', '_created', 'user') question_2.index_by('question_text', 'text') question_2.link('QUESTION_NODE_OF', question, user=1) question_2.link('QUESTION_ABOUT', question_1, user=1) idea_2 = gn.create( _model='idea', _status=1, down=0, text="You are confused", up=0, user=1, ) idea_2.index_by('ideas', '_created', 'user') idea_2.index_by('idea_text', 'text') idea_2.link('IDEA_NODE_OF', idea, user=1) idea_2.link('IDEA_ABOUT', question_2, user=1) pro_1 = gn.create( _model='pro', _status=1, down=0, text="I'd certainly feel confused", up=0, user=1, ) pro_1.index_by('pros', '_created', 'user') pro_1.index_by('pro_text', 'text') pro_1.link('PRO_NODE_OF', pro, user=1) pro_1.link('PRO_FOR', idea_2, user=1) con_1 = gn.create( _model='con', _status=1, down=0, text="I don't feel confused", up=0, user=1, ) con_1.index_by('cons', '_created', 'user') con_1.index_by('con_text', 'text') con_1.link('CON_NODE_OF', con, user=1) con_1.link('CON_AGAINST', idea_2, user=1) idea_3 = gn.create( _model='idea', _status=1, down=0, text="You are flummoxed", up=0, user=1, ) idea_3.index_by('ideas', '_created', 'user') idea_3.index_by('idea_text', 'text') idea_3.link('IDEA_NODE_OF', idea, user=1) idea_3.link('IDEA_ABOUT', question_2, user=1) question_3 = gn.create( _model='question', _status=1, down=0, text="Isn't that the same as confusion?", up=0, user=1, ) question_3.index_by('questions', '_created', 'user') question_3.index_by('question_text', 'text') question_3.link('QUESTION_NODE_OF', question, user=1) question_3.link('QUESTION_ABOUT', idea_3, user=1,) idea_4 = gn.create( _model='idea', _status=1, down=0, text="No", up=0, user=1, ) idea_4.index_by('ideas', '_created', 'user') idea_4.index_by('idea_text', 'text') idea_4.link('IDEA_NODE_OF', idea, user=1) idea_4.link('IDEA_ABOUT', question_3, user=1) idea_5 = gn.create( _model='idea', _status=1, down=0, text='Yes, but faster!', up=0, user=1, ) idea_5.index_by('ideas', '_created', 'user') idea_5.index_by('idea_text', 'text') idea_5.link('IDEA_NODE_OF', idea, user=1) idea_5.link('IDEA_ABOUT', question_3, user=1) con_3 = gn.create( _model='con', _status=1, down=0, text="Spans both positions", up=0, user=1, ) con_3.index_by('cons', '_created', 'user') con_3.index_by('con_text', 'text') con_3.link('CON_NODE_OF', con, user=1) con_3.link('CON_AGAINST', idea_5, user=1) idea_6 = gn.create( _model='idea', _status=1, down=0, text="You are surrounded by hellfire", up=0, user=1, ) idea_6.index_by('ideas', '_created', 'user') idea_6.index_by('idea_text', 'text') idea_6.link('IDEA_NODE_OF', idea, user=1) idea_6.link('IDEA_ABOUT', question_2, user=1) question_4 = gn.create( _model='question', _status=1, down=0, text="Is there no appeal from hellfire?", up=0, user=1, ) question_4.index_by('questions', '_created', 'user') question_4.index_by('question_text', 'text') question_4.link('QUESTION_NODE_OF', question, user=1) question_4.link('QUESTION_ABOUT', idea_6, user=1) idea_7 = gn.create( _model='idea', _status=1, down=0, text="You better hope there's an appeal", up=0, user=1, ) idea_7.index_by('ideas', '_created', 'user') idea_7.index_by('idea_text', 'text') idea_7.link('IDEA_NODE_OF', idea, user=1) idea_7.link('IDEA_ABOUT', question_4, user=1) # idea 1 "DUCK" idea_1 = gn.create( _model='idea', _status=1, down=0, text='DUCK!', up=0, user=1, ) idea_1.index_by('ideas', '_created', 'user') idea_1.index_by('idea_text', 'text') idea_1.link('IDEA_NODE_OF', idea, user=1) idea_1.link('IDEA_ABOUT', question_1, user=1) question_5 = gn.create( _model='pro', _status=1, down=0, text="Isn't that a simple problem?", up=0, user=1, ) question_5.index_by('questions', '_created', 'user') question_5.index_by('question_text', 'text') question_5.link('QUESTION_NODE_OF', question, user=1) question_5.link('QUESTION_ABOUT', idea_7, user=1) # pros against idea 1 pro_2 = gn.create( _model='pro', _status=1, down=0, text="It's simple", up=0, user=1, ) pro_2.index_by('pros', '_created', 'user') pro_2.index_by('pro_text', 'text') pro_2.link('PRO_NODE_OF', pro, user=1) pro_2.link('PRO_FOR', idea_1, user=1) pro_3 = gn.create( _model='pro', _status=1, down=0, text='It avoids wicked problems shaped like projectiles', up=0, user=1, ) pro_3.index_by('pros', '_created', 'user') pro_3.index_by('pro_text', 'text') pro_3.link('PRO_NODE_OF', pro, user=1) pro_3.link('PRO_FOR', idea_1, user=1) con_4 = gn.create( _model='con', _status=1, down=0, text="It may not actually avoid the problem", up=0, user=1, ) con_4.index_by('cons', '_created', 'user') con_4.index_by('con_text', 'text') con_4.link('CON_NODE_OF', con, user=1) con_4.link('CON_AGAINST', idea_1, user=1) con_5 = gn.create( _model='con', _status=1, down=0, text='Harder to do while asleep', up=0, user=1, ) con_5.index_by('cons', '_created', 'user') con_5.index_by('con_text', 'text') con_5.link('CON_NODE_OF', con, user=1) con_5.link('CON_AGAINST', idea_1, user=1)