GithubHelp home page GithubHelp logo

pygraphml's Introduction

pygraphml

Build Status PyPI version

pygraphml is a Python library designed to parse GraphML file. To see specification about GraphML, see http://graphml.graphdrawing.org/

A documentation is provided as a Jupyter notebook.

Requirements

  • Python > 2.7 and > 3.6.
  • matplotlib and networkx for visualization (optional).

Install

pip install pygraphml

Or you can use Anaconda and conda-forge :

conda config --add channels conda-forge
conda install pygraphml

License

Under BSD license. See LICENSE.

Authors

pygraphml's People

Contributors

feddischson avatar hadim avatar kurtasov avatar lowks avatar pradyunsg avatar spacemanjosh avatar tensory avatar virtuald avatar wanderijames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pygraphml's Issues

Incorrect usage of e.directed

if e.directed() != graph.directed:

Hello,
The directed attribute of e is not a function it is a boolean attribute.
Here is the error I am getting:
File "/users/trunkle/anaconda2/lib/python2.7/site-packages/pygraphml/graphml_parser.py", line 67, in write
if e.directed() != graph.directed:
TypeError: 'bool' object is not callable

Suggest removing the parens () from directed on two lines, line 67 and line 68.
Works for me.
Thanks,
Tim.

Resource Warning

I am having a test-script with PyUnittest, which creates the following warning with Python 3.4.5:

/usr/lib64/python3.4/site-packages/pygraphml/graphml_parser.py:84: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/tmpa6yjwlip' mode='r' encoding='UTF-8'>
  dom = minidom.parse(open(fname, 'r'))

Format incompatible with Boost GraphML loader

Thanks for your contribution! I'm currently using this lib to dump the graph data into xml and load with boost, but seems like these two formats are inconsistant:

part of xml wrote with pygraphml

<?xml version="1.0" ?>
<graphml>
    <key attr.name="label" attr.type="string" id="label"/>
    <graph edgedefault="directed" id="">
        <node id="v_000000001"/>
        <node id="v_000000040"/>

But when I try with boost, their file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
  <key id="key0" for="edge" attr.name="edge_name" attr.type="string" />
  <key id="key1" for="node" attr.name="vertex_name" attr.type="string" />
  <graph id="G" edgedefault="undirected" parse.nodeids="free" parse.edgeids="canonical" parse.order="nodesfirst">
    <node id="n0">
      <data key="key1">v_000000000</data>
    </node>
    <node id="n1">
      <data key="key1">v_000000001</data>
    </node>

Is there any plan for support boost favorable format?

Add tests

Anyone want to do that ?

nose is a nice package to use.

[feature] Create graph by just defining edges

For my application (import .shp files) I find it easiest to just add edges. When added, the nodes are created if they don't exist already. The nodes are are labeled "latitude|longitude|elevation" so each time I pull a node out of the shapefile it does have the same label as its other occurrences.

Is there any interest in me cleaning it up and making a pull request? My full shapefile to GraphML converter has a dependency that probably aren't appropriate here: https://github.com/django/django/tree/master/django/contrib/gis/gdal

UnsatisfiableError

UnsatisfiableError: The following specifications were found to be in conflict:

  • pygraphml -> python 3.4*
  • python 3.6*
    Use "conda info " to see the dependencies for each package.

how i resolve this?

ImportError: No module named GraphMLParser

from pygraphml.GraphMLParser import *

ImportError: No module named GraphMLParser
root@kali:# import pygraphml
import.im6: unable to open image `pygraphml': Is a directory @ error/blob.c/OpenBlob/2638.
root@kali:
#

Additional support for attributes

Hello,

here are some changes I made to version 2.2 in order to import a graph into Gephi: Some support for attribute value types other than string and addition of the for attribute (as requested in #17).

mforkel

output graphml file not accepted by graph-tool

from pygraphml import GraphMLParser, Graph
import random
parser = GraphMLParser.GraphMLParser()
graph = Graph.Graph()
n0 = graph.add_node(label='first')
for x in range (20000):
   x = str(random.random())
   n1 = graph.add_node(label=x)
   graph.add_edge(n0,n1)
   n0=n1
parser.write(graph,'test.graphml')

from graph_tool import load_graph
g = load_graph('test.graphml')

Expected behavior: g is a graph_tool Graph

Actual behavior: load_graph raises

ValueError: cannot determine file format of: test.graphml

I also tried the graph from main.py

g = Graph()
n1 = g.add_node("salut")
n2 = g.add_node("coucou")
n1['positionX'] = 555
g.add_edge(n1, n2)
parser = GraphMLParser()
parser.write(g, "ttest.graphml")

Control over minor detail

Hi,

I've just started using this library, and it's very useful - thanks for developing it !

I've hit a couple of small problems though. The tool I'm trying to load the GraphML into is very picky. It insists on having all the namespaces set - e.g. :

And also insists that the for attribute is set in each key - e.g.

<key id="myKeyID" for="node" attr.name="My Key" attr.type="string"/>

Is there an easy way to set this ? I couldn't see it in the tutorial, and nothing was jumping out in the API spec.

Thanks

Ian

DOM parser is too resource hungry

I'm trying to parse a 3.7GB graph in the graphml format. However, the DOM parser occupies too much memory (nearly 10GB before I killed the process) and my 16GB mem laptop is not really enough (the swap grows already). Have you considered using a SAX parser instead?

Setting attributes

I must be totally missing something. I've created nodes and edges but I don't know how to give them attributes! I see they inherit an attr dictionary from Item, but adding keys to that doesn't work. There is an Attribute object, which must be the value in the dictionary, but then what is the key? I don't see anywhere where attributes get set in any of the code.

GraphMLParser uses getAttribute and setAttribute, but those aren't implemented.

how do I add an attribute to an edge?

Bug in v2 pypi archive

Received by mail.

Hello Hadrien and Nick,

in the 2.0 tar gz from
 * https://pypi.python.org/pypi/pygraphml/2.0

the README.md is missing.

On my machine, this results in a crash when trying to install via pip ...

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.