def test_graphwrite(self):
     metaknowledge.writeGraph(self.G, fileShortName, suffix = filesuffix)
     tmpG = metaknowledge.readGraph(fileEName, fileNName)
     self.assertEqual(len(tmpG.edges()), len(self.G.edges()))
     self.assertEqual(len(tmpG.nodes()), len(self.G.nodes()))
     os.remove(fileEName)
     os.remove(fileNName)
 def test_graphwrite(self):
     metaknowledge.writeGraph(self.G, fileShortName, suffix=filesuffix)
     tmpG = metaknowledge.readGraph(fileEName, fileNName)
     self.assertEqual(len(tmpG.edges()), len(self.G.edges()))
     self.assertEqual(len(tmpG.nodes()), len(self.G.nodes()))
     os.remove(fileEName)
     os.remove(fileNName)
Exemplo n.º 3
0
def outputNetwork(clargs, grph):
    outDict = collections.OrderedDict([
        ('1', "edge list and node attribute list"),
        ('2', "edge list"),
        ('3', "node attribute list"),
        ('4', "graphml (SLOW)"),
    ])
    try:
        import metaknowledge.contour
    except ImportError:
        import metaknowledge
    else:
        outDict['0'] = "view graph"
        outDict.move_to_end('0', last=False)
    print("The network contains {} nodes and {} edges.".format(
        len(grph.nodes()), len(grph.edges())))
    outID = int(inputMenu(outDict, header="What type of output to you want? "))
    if outID == 0:
        metaknowledge.contour.quickVisual(grph)
        outputNetwork(clargs, grph)
    elif outID == 1:
        while True:
            try:
                outName = getOutputName(clargs, '', checking=False)
                metaknowledge.writeGraph(grph, outName, overwrite=False)
            except OSError:
                if clargs.name:
                    metaknowledge.writeGraph(grph, outName, overwrite=True)
                    break
                else:
                    overWrite = yesorNo("{}, overwrite (y/n)? ")
                    if overWrite:
                        metaknowledge.writeGraph(grph, outName, overwrite=True)
                        break
                    else:
                        pass
            else:
                break

    elif outID == 2:
        outName = getOutputName(clargs, '.csv')
        metaknowledge.writeEdgeList(grph, outName)
    elif outID == 3:
        outName = getOutputName(clargs, '.csv')
        metaknowledge.writeNodeAttributeFile(grph, outName)
    else:
        outName = getOutputName(clargs, '.graphml')
        nx.write_graphml(grph, outName)
def  outputNetwork(clargs, grph):
    outDict = collections.OrderedDict([
    ('1', "edge list and node attribute list"),
    ('2', "edge list"),
    ('3', "node attribute list"),
    ('4', "graphml (SLOW)"),
    ])
    try:
        import metaknowledge.contour
    except ImportError:
        import metaknowledge
    else:
        outDict['0'] = "view graph"
        outDict.move_to_end('0', last = False)
    print("The network contains {} nodes and {} edges.".format(len(grph.nodes()), len(grph.edges())))
    outID = int(inputMenu(outDict, header = "What type of output to you want? "))
    if outID == 0:
        metaknowledge.contour.quickVisual(grph)
        outputNetwork(clargs, grph)
    elif outID == 1:
        while True:
            try:
                outName = getOutputName(clargs, '', checking = False)
                metaknowledge.writeGraph(grph, outName, overwrite = False)
            except OSError:
                if clargs.name:
                    metaknowledge.writeGraph(grph, outName, overwrite = True)
                    break
                else:
                    overWrite = yesorNo("{}, overwrite (y/n)? ")
                    if overWrite:
                        metaknowledge.writeGraph(grph, outName, overwrite = True)
                        break
                    else:
                        pass
            else:
                break

    elif outID == 2:
        outName = getOutputName(clargs, '.csv')
        metaknowledge.writeEdgeList(grph, outName)
    elif outID == 3:
        outName = getOutputName(clargs, '.csv')
        metaknowledge.writeNodeAttributeFile(grph, outName)
    else:
        outName = getOutputName(clargs, '.graphml')
        nx.write_graphml(grph, outName)