Search in sources :

Example 6 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress in project constellation by constellation-app.

the class InfoMapMainNGTest method testMain.

/**
 * Test of InfoMapMain.
 *
 * @throws java.lang.Exception
 */
@Test
public void testMain() throws Exception {
    final String fnam = "ninetriangles" + GraphDataObject.FILE_EXTENSION;
    // A test graph.
    Graph graph;
    try (InputStream inStream = InfoMapMainNGTest.class.getResourceAsStream(fnam)) {
        graph = new GraphJsonReader().readGraphZip(fnam, inStream, new TextIoProgress(true));
    }
    final Config conf = new Config();
    conf.setNoFileOutput(false);
    conf.setVerbosity(1);
    conf.setNetworkFile(fnam);
    conf.setOutDirectory(System.getProperty("java.io.tmpdir"));
    conf.setPrintClu(true);
    conf.setPrintNodeRanks(true);
    conf.setPrintFlowNetwork(true);
    conf.setVerbosity(1);
    conf.setNumTrials(5);
    System.out.printf("fastHierarchicalSolution %d\n", conf.getFastHierarchicalSolution());
    System.out.printf("Parsing %s network from file '%s'... ", conf.isUndirected() ? "undirected" : "directed", conf.getNetworkFile());
    conf.setConnectionType(Config.ConnectionType.TRANSACTIONS);
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        System.out.printf("vertices=%d, Transactions=%d edges=%d links=%d\n", rg.getVertexCount(), rg.getTransactionCount(), rg.getEdgeCount(), rg.getLinkCount());
        runInfoMap(conf, rg);
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) InputStream(java.io.InputStream) Config(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.io.Config) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) GraphJsonReader(au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader) Test(org.testng.annotations.Test)

Example 7 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress in project constellation by constellation-app.

the class GraphSavingNGTest method writeReadGraphTest.

@Test
public void writeReadGraphTest() throws Exception {
    final String name = "tmp1";
    File graphFile = File.createTempFile(name, ".star");
    ReadableGraph rg = graph.getReadableGraph();
    try {
        assertEquals("num nodes", 7, rg.getVertexCount());
        assertEquals("num transactions", 5, rg.getTransactionCount());
        assertTrue("nd 'name1' found", nodeFound(rg, "name1"));
        assertTrue("nd 'name2' found", nodeFound(rg, "name2"));
        assertTrue("nd 'name3' found", nodeFound(rg, "name3"));
        assertTrue("nd 'name4' found", nodeFound(rg, "name4"));
        assertTrue("nd 'name5' found", nodeFound(rg, "name5"));
        assertTrue("nd 'name6' found", nodeFound(rg, "name6"));
        assertTrue("nd 'name7' found", nodeFound(rg, "name7"));
        assertTrue("tx 'name101' found", transactionFound(rg, "name101"));
        assertTrue("tx 'name102' found", transactionFound(rg, "name102"));
        assertTrue("tx 'name103' found", transactionFound(rg, "name103"));
        assertTrue("tx 'name104' found", transactionFound(rg, "name104"));
        assertTrue("tx 'name105' found", transactionFound(rg, "name105"));
    } finally {
        rg.release();
    }
    rg = graph.getReadableGraph();
    try {
        GraphJsonWriter writer = new GraphJsonWriter();
        writer.writeGraphToZip(rg, graphFile.getPath(), new TextIoProgress(false));
    } finally {
        rg.release();
    }
    assertTrue("file created", graphFile.exists());
    String path = graphFile.getPath();
    path = path.substring(0, path.length() - 5);
    final Graph newGraph = new GraphJsonReader().readGraphZip(graphFile, new TextIoProgress(false));
    graphFile.delete();
    rg = newGraph.getReadableGraph();
    try {
        assertEquals("num nodes", 7, rg.getVertexCount());
        assertEquals("num transactions", 5, rg.getTransactionCount());
        assertTrue("nd 'name1' found", nodeFound(rg, "name1"));
        assertTrue("nd 'name2' found", nodeFound(rg, "name2"));
        assertTrue("nd 'name3' found", nodeFound(rg, "name3"));
        assertTrue("nd 'name4' found", nodeFound(rg, "name4"));
        assertTrue("nd 'name5' found", nodeFound(rg, "name5"));
        assertTrue("nd 'name6' found", nodeFound(rg, "name6"));
        assertTrue("nd 'name7' found", nodeFound(rg, "name7"));
        assertTrue("tx 'name101' found", transactionFound(rg, "name101"));
        assertTrue("tx 'name102' found", transactionFound(rg, "name102"));
        assertTrue("tx 'name103' found", transactionFound(rg, "name103"));
        assertTrue("tx 'name104' found", transactionFound(rg, "name104"));
        assertTrue("tx 'name105' found", transactionFound(rg, "name105"));
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File) Test(org.testng.annotations.Test)

Example 8 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress in project constellation by constellation-app.

the class SaveGraphUtilities method saveGraphToTemporaryDirectory.

/**
 * Save the graph to the temporary directory for debugging.
 * <p>
 * The main use case of this method is debugging unit tests and so this
 * method does extra checks to make sure one can interact with the graph
 * build from a crude unit test.
 *
 * @param graph The graph
 * @param filename The filename excluding the file extension
 * @param makeInteractable If true, will modify the graph and add attributes
 * to make sure the graph can be opened
 * @throws IOException
 * @throws InterruptedException
 */
public static void saveGraphToTemporaryDirectory(final Graph graph, final String filename, boolean makeInteractable) throws IOException, InterruptedException {
    final File saveCreatedGraph = File.createTempFile(filename, FileExtensionConstants.STAR);
    final WritableGraph wg = graph.getWritableGraph("make graph interactable", true);
    try {
        if (makeInteractable) {
            makeGraphInteractable(wg);
        }
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        final GraphJsonWriter writer = new GraphJsonWriter();
        writer.writeGraphToZip(rg, saveCreatedGraph.getPath(), new TextIoProgress(false));
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 9 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress in project constellation by constellation-app.

the class SaveGraphUtilities method saveGraphToTemporaryDirectory.

/**
 * Save the graph to the temporary directory for debugging.
 * <p>
 * The main use case of this method is debugging unit tests and so this
 * method does extra checks to make sure one can interact with the graph
 * build from a crude unit test.
 *
 * @param graph The graph
 * @param file The graph file
 * @param makeInteractable If true, will modify the graph and add attributes
 * to make sure the graph can be opened
 * @throws IOException
 * @throws InterruptedException
 */
public static void saveGraphToTemporaryDirectory(final Graph graph, final File file, boolean makeInteractable) throws IOException, InterruptedException {
    final WritableGraph wg = graph.getWritableGraph("make graph interactable", true);
    try {
        if (makeInteractable) {
            makeGraphInteractable(wg);
        }
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        final GraphJsonWriter writer = new GraphJsonWriter();
        writer.writeGraphToZip(rg, file.getPath(), new TextIoProgress(false));
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Aggregations

TextIoProgress (au.gov.asd.tac.constellation.utilities.gui.TextIoProgress)9 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)7 File (java.io.File)6 Test (org.testng.annotations.Test)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)4 GraphJsonWriter (au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter)4 GraphJsonReader (au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader)2 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)2 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 GraphDataObject (au.gov.asd.tac.constellation.graph.file.GraphDataObject)1 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)1 Config (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.io.Config)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 TopComponent (org.openide.windows.TopComponent)1