def test_40_linking_overview(self): """ shows usage on general linking of objects using a Fact. Note - work in progress, none of these methods allow for any real discoverability without contrived coding / searching in datasets. """ ob_cat = mod_core.CoreDataWhat('Cat', [{'genus':'Felis', 'is_tameable':True}]) # option 1 - link via data (though difficult to autosearch) pet1 = mod_core.CoreDataWho('Tiddles', [{'obj_type':ob_cat, 'type':'animal', 'likes':'Fish'}]) self.assertEqual(pet1.name, 'Tiddles') self.assertEqual(pet1.data[0]['obj_type'], ob_cat) self.assertEqual(pet1.data[0]['obj_type'].data[0]['is_tameable'], True) # option 2 - link 2 objects with 3rd 'Fact' object pet2 = mod_core.CoreDataWho('Meatball', [{'type':'cat', 'likes':'Fish'}]) self.assertEqual(pet2.name, 'Meatball') pet2.links_to(ob_cat, 'Character') self.assertEqual(pet2.links, [[ob_cat, 'Character']]) # option 3 - link objects via parent / child ob_dog = mod_core.CoreDataWhat('Dog', [{'genus':'Canis', 'is_tameable':True}]) pet3 = mod_core.CoreDataWho('Rover', data=[{'type':'dog'}], parent=ob_dog) self.assertEqual(pet3.name, 'Rover') self.assertEqual(pet3.parent, ob_dog) self.assertEqual(pet3.parent.name, 'Dog')
def test_42_object_drilldown_detailed(self): """ demonstrate how mulitple drilldowns can work """ asset = mod_core.CoreDataWhat('Asset') f = mod_core.CoreDataWhat('Furniture', parent = asset) chair = mod_core.CoreDataWhat('Chair', parent=f) table = mod_core.CoreDataWhat('Table', parent=f) cupboard = mod_core.CoreDataWhat('Cupboard', parent=f) tradeperson = mod_core.CoreDataWho('Trade Person') carpenter = mod_core.CoreDataWho('Carpenter', parent=tradeperson) f.links_to(chair, 'Object') f.links_to(table, 'Object') f.links_to(cupboard, 'Object') f.links_to(carpenter, 'Character') self.assertEqual(str(f) , 'Furniture (type=what)') f.expand('List', [table, chair, cupboard]) wood = mod_core.CoreDataWhat('Wood', parent = mod_core.CoreDataWhat('Material')) leather = mod_core.CoreDataWhat('Leather', parent = mod_core.CoreDataWhat('Material')) wood.links_to(chair, 'Object') wood.links_to(table, 'Object') wood.links_to(cupboard, 'Object') leather.links_to(chair, 'Object') woodwork = mod_core.CoreDataHow('Woodwork') build_chair = mod_core.CoreDataHow('Build Chair', parent=woodwork) bld_assemble_legs = mod_core.CoreDataHow('Assemble Chair Legs', parent=build_chair) bld_cut_wood = mod_core.CoreDataHow('Cut Wood for chair', parent=build_chair) bld_measure = mod_core.CoreDataHow('Measure Wood for chair', parent=build_chair) build_chair.links_to(bld_assemble_legs, 'Process') build_chair.links_to(bld_cut_wood, 'Process') build_chair.links_to(bld_measure, 'Process') chair.links_to(build_chair, 'Process') self.assertEqual(str(chair.format_all()),""" --- Format all : Chair ------------- parent = Furniture (type=what) child = None links = Build Chair (type=how) sublink = Assemble Chair Legs (type=how) sublink = Cut Wood for chair (type=how) sublink = Measure Wood for chair (type=how) """) f.expand('Built via', [wood, leather]) self.assertEqual(f.drill_up() , asset) self.assertEqual(chair.drill_up() , f) print(wood.format_all())
def test_60_example_notes(self): note_pc = mod_core.CoreDataWhat('PC:Install') note_steam = mod_core.CoreDataWhat('Games:Steam', parent=note_pc) note_git = mod_core.CoreDataWhat('Programming:Git', parent=note_pc) note_pc.expand('', [note_steam.name, note_git.name]) print(note_git) print(note_steam) print(note_pc) print('child_nodes of note_pc = ', note_pc.child_nodes) #for c in note_pc.child_nodes: # print('c = ' , str(c)) res = note_pc._get_all_children() print(res) self.assertEqual(res, ' child = Games:Steam\n child = Programming:Git\n')
def test_02_object(self): f = mod_core.CoreDataWhat('Food') self.assertEqual(str(f) , 'Food (type=what)') f.expand('List', ['Apples', 'Chops', 'Cheese']) self.assertEqual(str(f.drill_down()[0]) , 'Apples') self.assertEqual(str(f.drill_down()[1]) , 'Chops') self.assertEqual(str(f.drill_down()[2]) , 'Cheese') self.assertEqual(f.drill_up() , None) # TODO - keep track of location of graph self.assertEqual(f.format_all(),""" --- Format all : Food ------------- parent = None child = Apples child = Chops child = Cheese links = None """)
def test_04_detailed_core_data_usage(self): root = mod_core.CoreDataWhat('Everything') # add the domains root.expand('List', ['Food', 'Projects', 'Software']) # define a domain and instantiate a class (example - you # dont do this in day to day usage food = root.get_child_by_name('Food') # for the Food - expand it further food.expand('List', ['Apples', 'Chops', 'Cheese']) self.assertEqual(str(food)[0:4], 'Food') self.assertEqual(str(food.parent), 'Everything (type=what)') # describe a 2nd domain proj = root.get_child_by_name('Projects') proj.expand('List', ['Install Shelf', 'AIKIF', 'Prepare Sales Report']) self.assertEqual(str(proj), 'Projects') shelf = proj.get_child_by_name('Install Shelf') self.assertEqual(str(shelf), 'Install Shelf') # try fake name rubbish = proj.get_child_by_name('Something that doesnt exist') self.assertEqual(str(rubbish), 'None') # contract self.assertEqual(str(shelf.contract('')), 'Projects') self.assertEqual(str(proj.contract('TODO - set process')), 'Everything (type=what)') self.assertEqual( proj.format_all(), """ --- Format all : Projects ------------- parent = Everything (type=what) child = Install Shelf child = AIKIF child = Prepare Sales Report links = None """)
def test_22_core_data_what(self): l = mod_core.CoreDataWhat('Apple') self.assertEqual(len(l.format_csv()) > 5, True) self.assertEqual(str(l) , 'Apple (type=what)') self.assertEqual(l.type_desc , 'Object') self.assertEqual(l.data_type , 'what')
def test_10_links_to(self): f = mod_core.CoreDataWhat('Food') r = mod_core.CoreDataWhat('Recipe') f.links_to('Recipe', 'Process') self.assertEqual(f.links, [['Recipe', 'Process']]) self.assertRaises(Exception, f.links_to, 'Recipe', 'WRONG_TYPE')