igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Problem saving graphml file


From: Bernie Hogan
Subject: Re: [igraph] Problem saving graphml file
Date: Fri, 12 Feb 2010 18:59:55 +0000

Hi guys, 

Thanks for the offer but after some determined testing, I've sorted out the issue. 

It is indeed unicode. But what tripped me up was that some of the names of the attributes were also in unicode. Both the names of the attributes and the attributes themselves have to be strings (or numeric for the values). 

Here is a dirty script snippet that should work for others: 

# Part 1: Clean up names
for i in G.vs[0].attributes().keys():
if isinstance(i,unicode):
ilist = G.vs[i]
iname = i.encode("ASCII","replace")
del G.vs[i]
G.vs[iname] = ilist

# Part 2: Clean up actual attributes
for i in G.vs[0].attributes().keys():
if isinstance(G.vs[0][i],unicode):
for y in range(len(G.vs[i])):
if G.vs[y][i] == None or G.vs[y][i] == "":
G.vs[y][i] = "None"
else:
G.vs[y][i] = G.vs[y][i].encode('ASCII','replace')
else:
for y in range(len(G.vs[i])):
if G.vs[y][i] == None or G.vs[y][i] == "":
G.vs[y][i] = "None"


You will notice that one of the things that it does is to replace null or empty strings with "None". This is because several GraphML implementations do not like empty sets. In particular, I'm opening this data in NodeXL. Running a graph through this before exporting it will first make igraph work and second make NodeXL work. 

(sorry for the rich text - it seems that otherwise Gmail munges the whitespace). 

Take care,
BERNiE 


On Fri, Feb 12, 2010 at 10:34 AM, Tamas Nepusz <address@hidden> wrote:
> Bernie,
>
>> I am having some trouble saving graphml files with many attributes
>> around 30 node attributes, many with unicode text.
> If you are working with the Python interface, a workaround is to convert
> all your Python unicode objects to string objects with utf-8 encoding
> (using the .encode() method of the unicode object) before saving the
> graph. I'm working on a patch that will do this automatically.
>
> If this workaround does not work, let me know because there might be
> something else going on behind the scenes.
>
> --
> Tamas
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]