Example #1
0
    def test_networks(self):
        self.assertTrue(os.path.exists('test_dynetml/files_2014022423.xml'))

        with self.assertRaises(TypeError):
            dynetml2other(1, 'yes')
            dynetml2other('yes', 1)

        with self.assertRaises(ValueError):
            dynetml2other('test_string', 'test_string_two')
            dynetml2other(working_path('test_dynetml', 'files_2014022423.xml'), 'test_string_two')

        with self.assertRaises(IOError):
            dynetml2other('bad_path', 'networkx')

        for network_format in ('networkx', 'igraph'):
            self.eval_format(network_format)
Example #2
0
    def eval_format(self, network_format):
        self.assertTrue(network_format in ('networkx', 'igraph'))
        #if network_format == 'networkx':
        #    import MetaNetworkNetworkX as MetaNetwork
        #else:
        #    import MetaNetworkIGraph as MetaNetwork

        dmn = dynetml2other(working_path('test_dynetml', 'files_2014022423.xml'), network_format)
        self.assertTrue(isinstance(dmn, DynamicMetaNetwork))
        self.assertEqual(len(dmn.metanetworks), 23)

        for mn in dmn.metanetworks[:5]:
            self.assertTrue(isinstance(mn, (MetaNetworkIG, MetaNetworkNX)))

            self.eval_node_tree(mn.get_node_tree(), [('Agent', 'Agent', 1), ('Event', 'Tweet', 1)])
            self.eval_networks(mn.networks, [('Agent x Tweet - Sender', 1, 2)], network_format)

        mn = dmn.metanetworks[-1]
        self.assertEqual(mn.attributes['id'], '2014-02-24 11 PM')
        self.eval_node_tree(mn.get_node_tree(), [('Agent', 'Agent', 923), ('Knowledge', 'Concept', 103),
                                            ('Location', 'Location', 201), ('Event', 'Tweet', 870)])
        self.eval_networks(mn.networks, [('Agent x Tweet - Sender', 870, 1566),
                                         ('Tweet x Agent - Mentions', 590, 806),
                                         ('Tweet x Concept', 211, 245),
                                         ('Tweet x Location', 250, 451),
                                         ('Tweet x Tweet - Retweeted-By', 131, 201)], network_format)

        with self.assertRaises(TypeError):
            dmn.convert_to_dynetml('blah')
            dmn.write_dynetml(1)

        with self.assertRaises(IOError):
            dmn.write_dynetml(self.test_dir_name)

        with self.assertRaises(TypeError):
            mn.convert_to_dynetml('blah')
            mn.write_dynetml(1)

        with self.assertRaises(IOError):
            mn.write_dynetml(self.test_dir_name)
Example #3
0
def import_dynetmeta_data(filename):
    # The following module is pretty useless.
    # The uselessness of the code is matched only by the uselessness
    # of the "documentation" at
    # http://pythonhosted.org/dynetml2other/

    from dynetml2other import dynetml2other

    # Now wrestle with the religious implications of the
    # dynetml data structure [these folks are a little unclear on
    # the concept of "importing" something into networkx]
    mn = dynetml2other(filename, 'networkx').metanetworks[0]
    # Yes finally an nx graph.  But guess what, no node attributes have been included...
    nx_graph = mn.networks['Agent x Agent']

    # Now we need to add the attributes to the graph.
    # You'd think the mn_node_dict would be what we need, but no not quite....
    _properties, mn_node_dict = mn._MetaNetwork__node_tree['Agent']['Agent']
    node_dict = dict(nx_graph.nodes(data=True))
    for (n, (meta_dict, prop_dict)) in list(mn_node_dict.items()):
        if n in node_dict:
            node_dict[n].update(prop_dict)
    return nx_graph