def read_graphml(file):

    parser = gml.GraphMLParser()

    g = parser.parse(file)
    edges = g.edges()

    wg = Graph()
    for e in edges:
        # Creation of a new graph with constant edge weight 1
        wg.add_edge(e.node1.id, e.node2.id, 1)

    return wg
Exemple #2
0
    def test_OutputFile(self):
        """ Tests if the gardener can write into an output file.

        The test expects that there is at least one node.
        """
        temp = tempfile.NamedTemporaryFile()
        self.graphml_gardener_call(['-o', temp.name])
        parser = pgml.GraphMLParser()

        # get the result from the system call:
        g = parser.parse(temp.name)
        temp = None
        self.assertNotEqual(len(g.nodes()), 0)
Exemple #3
0
    def gardener_call(self, options):

        p_args = [self.G_PATH, self.T_PATH, "-c", self.C_PATH] + options
        print(p_args)
        pipe = Popen(p_args, stdout=PIPE)
        graphml_str = pipe.communicate()[0]
        temp = tempfile.NamedTemporaryFile()
        temp.write(graphml_str)
        temp.flush()
        parser = pgml.GraphMLParser()

        # get the result from the system call:
        return parser.parse(temp.name)
Exemple #4
0
    def graphml_gardener_call(self, options):
        """
        Runs the include_gardener with the xml option,
        extracts the result and returns the graph.
        """
        result_str = self.gardener_call(['-f', 'xml'] + options)
        if len(result_str) == 0:
            return None
        temp = tempfile.NamedTemporaryFile()
        temp.write(result_str)
        temp.flush()
        parser = pgml.GraphMLParser()

        # get the result from the system call:
        return parser.parse(temp.name)
Exemple #5
0
    def graphml_gardener_call( self, options ):
        """
        Runs the include_gardener with the xml option,
        extracts the result and returns the graph.
        """
        pipe = Popen( [ self.G_PATH, self.T_PATH,
            '-f', 'xml'  ] + options, stdout=PIPE  )
        graphml_str = pipe.communicate()[0]
        temp = tempfile.NamedTemporaryFile()
        temp.write( graphml_str )
        temp.flush()
        parser = pgml.GraphMLParser()

        # get the result from the system call:
        return parser.parse( temp.name )
    def graphml_gardener_call(self, options, subpath=""):
        """
        Runs the include_gardener with the xml option,
        extracts the result and returns the graph.
        """
        result_str, err = self.call(
            [os.path.join(self.path_testfiles, subpath), '-f', 'xml'] +
            options, False)
        if len(result_str) == 0:
            return None
        logging.debug("graphml-result: {} ".format(result_str.decode('utf-8')))
        temp = tempfile.NamedTemporaryFile()
        temp.write(result_str)
        temp.flush()
        parser = pgml.GraphMLParser()

        # get the result from the system call:
        return parser.parse(temp.name)
Exemple #7
0
def loadGraphML(inf):
	parser = pygraphml.GraphMLParser()
	g = parser.parse(inf)
	return g
Exemple #8
0
g = pygraphml.Graph()

nodes = dict()
for user in db.users.find({
        'counts.followed_by': {
            '$gte': 1000000
        },
        'follows': {
            '$exists': True
        }
}):
    nodes[user['id']] = g.add_node(user['username'])
    nodes[user['id']]['follows'] = user['counts']['follows']
    nodes[user['id']]['followed_by'] = user['counts']['followed_by']

for user in db.users.find({
        'counts.followed_by': {
            '$gte': 1000000
        },
        'follows': {
            '$exists': True
        }
}):
    for followed_user_id in user['follows']:
        if followed_user_id in nodes:
            g.add_edge(nodes[user['id']],
                       nodes[followed_user_id],
                       directed=True)

parser = pygraphml.GraphMLParser()
parser.write(g, "superbloggers.graphml")
Exemple #9
0
def write_graph(graph_output_path, graph):
    pygraphml.GraphMLParser().write(graph, graph_output_path)