Problem:
I have a large undirected graph in the .ncol
format, and want to get it in to Mathematica.
I understand that Mathematica doesn't natively support the import of .ncol
format, but .ncol
format is very simple...
node1 node2 0.1
node2 node3 0.2
node1 node5 0.3
node3 node5 0.9
node2 node5 0.5
For example, this .ncol
file produces the following undirected graph...
Question:
What's the best way to import a large, complete, undirected graph of 4268 nodes, and 9105778 edges in .ncol
format? Is it possible to import this type of file even though it is not natively supported? Reading in line by line?
What I've Tried So Far
Thank you vikram reddy and user6014 for your suggestions.
I have implemented ReadList
as such:
list = ReadList["/path/to/file.ncol", Word, RecordLists -> True,
WordSeparators -> {" "}]
Now, list
is a nested list of the lines like:
{{"0000004", "0000002", "0.8516145163710000"}, {"0000007", "0000006",
"0.9169866102280000"}, {"0000011", "0000000", "0.8639846171470000"}...}
How do I add these elements to a graph object?
The .ncol
File (snippet):
Here's a snippet of the .ncol
graph I am actually trying to import:
0000001 0000000 0.4408587960080000
0000002 0000000 0.7405196230980000
0000002 0000001 0.5211728712080000
0000003 0000000 0.7376683700760000
0000003 0000001 0.4166055229790000
0000003 0000002 0.6032695565790000
0000004 0000000 0.7225082142750000
0000004 0000001 0.5197121010690000
0000004 0000002 0.8516145163710000
0000004 0000003 0.6050347164500000
0000005 0000000 0.3433514873340000
0000005 0000001 0.4807050687280000
0000005 0000002 0.3554792851080000
0000005 0000003 0.3306190830880000
0000005 0000004 0.3536941923200000
0000006 0000000 0.4033221771690000
0000006 0000001 0.6300091271690000
0000006 0000002 0.4136969934920000
0000006 0000003 0.4107973190560000
0000006 0000004 0.4259157902110000
Thank you!
ReadList[yourFileName, Word, RecordLists -> True, WordSeparators -> {" "}]
, where your file name is the .ncol file. It should bring the data in as a list of strings, to which you can easily then likely modify it to meet your needs. $\endgroup$