Exemple #1
0
    def test_remove_if_redundant_with_multiple_edges_same_citations(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator()
        nid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='neighbor-of')

        net.set_edge_attribute(nid,
                               RedundantEdgeAdjudicator.CITATION,
                               ['pubmed:4', 'pubmed:123'],
                               type='list_of_string')

        cid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='controls-state-change-of')

        net.set_edge_attribute(cid,
                               RedundantEdgeAdjudicator.CITATION,
                               ['pubmed:555', 'pubmed:4'],
                               type='list_of_string')

        cidtwo = net.create_edge(edge_source=0,
                                 edge_target=1,
                                 edge_interaction='controls-state-change-of')

        net.set_edge_attribute(cidtwo,
                               RedundantEdgeAdjudicator.CITATION,
                               ['pubmed:4', 'pubmed:123'],
                               type='list_of_string')

        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        adjud._remove_if_redundant(net, nid, [cid, cidtwo])
        self.assertEqual(None, net.get_edge(nid))
Exemple #2
0
    def test_basic_network_where_neighbor_of_citations_merges(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator()
        nid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='neighbor-of')

        net.set_edge_attribute(nid,
                               RedundantEdgeAdjudicator.CITATION, ['pubmed:5'],
                               type='list_of_string')
        cid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='controls-state-change-of')

        oid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='someother')

        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        self.assertEqual('controls-state-change-of', net.get_edge(cid)['i'])
        self.assertEqual('someother', net.get_edge(oid)['i'])

        self.assertEqual([], adjud.update(net))
        self.assertEqual(None, net.get_edge(nid))
        self.assertEqual(None, net.get_edge(cid))
        self.assertEqual('someother', net.get_edge(oid)['i'])
        res = net.get_edge_attribute(oid, RedundantEdgeAdjudicator.CITATION)
        res['v'].sort()
        self.assertEqual(['pubmed:5'], res['v'])
    def test_remove_edge(self):
        collapser = RedundantEdgeCollapser()
        net = NiceCXNetwork()

        # test remove on non existant edge
        collapser._remove_edge(net, 10)

        # test removing edge with no attributes
        eid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='needs')
        self.assertEqual('needs', net.get_edge(eid)['i'])
        collapser._remove_edge(net, eid)
        self.assertEqual(None, net.get_edge(eid))

        # test removing edge with attributes
        eid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='needs')

        net.set_edge_attribute(eid, 'foo', 'someval')
        net.set_edge_attribute(eid, 'foo2', 'someval2')

        self.assertEqual('needs', net.get_edge(eid)['i'])
        self.assertEqual('someval', net.get_edge_attribute(eid, 'foo')['v'])
        self.assertEqual('someval2', net.get_edge_attribute(eid, 'foo2')['v'])
        collapser._remove_edge(net, eid)
        self.assertEqual(None, net.get_edge(eid))
        self.assertEqual((None, None), net.get_edge_attribute(eid, 'foo'))
        self.assertEqual((None, None), net.get_edge_attribute(eid, 'foo2'))
Exemple #4
0
 def test_remove_edge_no_attributes(self):
     adjud = RedundantEdgeAdjudicator()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='foo')
     self.assertEqual('foo', net.get_edge(edgeid)['i'])
     adjud._remove_edge(net, edgeid)
     self.assertEqual(None, net.get_edge(edgeid))
Exemple #5
0
 def test_remove_edge_with_attributes(self):
     adjud = RedundantEdgeAdjudicator()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='foo')
     net.set_edge_attribute(edgeid, 'attr1', 'someval')
     self.assertEqual('someval',
                      net.get_edge_attribute(edgeid, 'attr1')['v'])
     self.assertEqual('foo', net.get_edge(edgeid)['i'])
     adjud._remove_edge(net, edgeid)
     self.assertEqual(None, net.get_edge(edgeid))
     self.assertEqual((None, None), net.get_edge_attribute(edgeid, 'attr1'))
Exemple #6
0
    def test_remove_if_redundant_with_no_citation_on_edge(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator()
        nid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='neighbor-of')
        cid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='controls-state-change-of')

        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        adjud._remove_if_redundant(net, nid, [cid])

        self.assertEqual(None, net.get_edge(nid))
Exemple #7
0
 def test_create_edge_with_int_for_edge_ids(self):
     net = NiceCXNetwork()
     net.create_edge(edge_source=0, edge_target=1)
     res = net.get_edge(0)
     self.assertEqual(0, res[constants.EDGE_ID])
     self.assertEqual(0, res[constants.EDGE_SOURCE])
     self.assertEqual(1, res[constants.EDGE_TARGET])
Exemple #8
0
    def test_create_edge_with_interaction(self):
        net = NiceCXNetwork()
        edge_id = net.create_edge(edge_source=10, edge_target=20, edge_interaction='blah')

        res = net.get_edge(edge_id)
        self.assertEqual(edge_id, res[constants.EDGE_ID])
        self.assertEqual(10, res[constants.EDGE_SOURCE])
        self.assertEqual(20, res[constants.EDGE_TARGET])
        self.assertEqual('blah', res[constants.EDGE_INTERACTION])
Exemple #9
0
    def test_remove_if_redundant_with_citation_and_other_lacks_citation(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator()
        nid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='neighbor-of')

        net.set_edge_attribute(nid,
                               RedundantEdgeAdjudicator.CITATION,
                               ['pubmed:123'],
                               type='list_of_string')

        cid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='controls-state-change-of')

        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        adjud._remove_if_redundant(net, nid, [cid])
        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
Exemple #10
0
    def test_create_edge_with_node_dict_passed_in_for_edge_ids(self):
        net = NiceCXNetwork()

        nodeone = net.get_node(net.create_node('node1'))
        nodetwo = net.get_node(net.create_node('node2'))
        edge_id = net.create_edge(edge_source=nodeone,
                                  edge_target=nodetwo)
        res = net.get_edge(edge_id)
        self.assertEqual(edge_id, res[constants.EDGE_ID])
        self.assertEqual(0, res[constants.EDGE_SOURCE])
        self.assertEqual(1, res[constants.EDGE_TARGET])
Exemple #11
0
    def test_remove_if_redundant_mergecitations_true(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator()
        nid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='neighbor-of')

        net.set_edge_attribute(nid,
                               RedundantEdgeAdjudicator.CITATION,
                               ['pubmed:4', 'pubmed:123'],
                               type='list_of_string')

        cid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='controls-state-change-of')

        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        adjud._remove_if_redundant(net, nid, [cid], mergecitations=True)
        self.assertEqual(None, net.get_edge(nid))
        res = net.get_edge_attribute(cid, RedundantEdgeAdjudicator.CITATION)
        res['v'].sort()
        self.assertEqual(['pubmed:123', 'pubmed:4'], res['v'])