Search in sources :

Example 1 with GraphMLReader

use of com.tinkerpop.blueprints.util.io.graphml.GraphMLReader in project blueprints by tinkerpop.

the class Neo4jBatchGraphTest method testGraphMLLoad.

public void testGraphMLLoad() throws Exception {
    final String directory = this.getWorkingDirectory();
    final Neo4jBatchGraph batch = new Neo4jBatchGraph(directory);
    new GraphMLReader(batch).inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
    assertNotNull(batch.getVertex(1));
    assertNotNull(batch.getVertex(2));
    assertNotNull(batch.getVertex(3));
    assertNotNull(batch.getVertex(4));
    assertNotNull(batch.getVertex(5));
    assertNotNull(batch.getVertex(6));
    assertNull(batch.getVertex(7));
    assertEquals(batch.getVertex(1).getProperty("name"), "marko");
    assertEquals(batch.getVertex(2).getProperty("name"), "vadas");
    assertEquals(batch.getVertex(3).getProperty("name"), "lop");
    assertEquals(batch.getVertex(4).getProperty("name"), "josh");
    assertEquals(batch.getVertex(5).getProperty("name"), "ripple");
    assertEquals(batch.getVertex(6).getProperty("name"), "peter");
    batch.shutdown();
    // native neo4j graph load
    Neo4jGraph graph = new Neo4jGraph(directory);
    assertEquals(count(graph.getVertices()), 6);
    assertEquals(count(graph.getEdges()), 6);
    assertEquals(count(graph.getVertex("1").getEdges(Direction.OUT)), 3);
    assertEquals(count(graph.getVertex("1").getEdges(Direction.IN)), 0);
    Vertex marko = graph.getVertex("1");
    assertEquals(marko.getProperty("name"), "marko");
    assertEquals(marko.getProperty("age"), 29);
    int counter = 0;
    assertEquals(count(graph.getVertex("4").getEdges(Direction.OUT)), 2);
    assertEquals(count(graph.getVertex("4").getEdges(Direction.IN)), 1);
    Vertex josh = graph.getVertex("4");
    assertEquals(josh.getProperty("name"), "josh");
    assertEquals(josh.getProperty("age"), 32);
    for (Edge e : graph.getVertex("4").getEdges(Direction.OUT)) {
        if (e.getVertex(Direction.IN).getId().equals(3l)) {
            assertEquals(Math.round((Float) e.getProperty("weight")), 0);
            assertEquals(e.getLabel(), "created");
            counter++;
        } else if (e.getVertex(Direction.IN).getId().equals(5l)) {
            assertEquals(Math.round((Float) e.getProperty("weight")), 1);
            assertEquals(e.getLabel(), "created");
            counter++;
        }
    }
    assertEquals(counter, 2);
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Neo4jGraph(com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph) GraphMLReader(com.tinkerpop.blueprints.util.io.graphml.GraphMLReader) Edge(com.tinkerpop.blueprints.Edge)

Example 2 with GraphMLReader

use of com.tinkerpop.blueprints.util.io.graphml.GraphMLReader in project hale by halestudio.

the class GraphMLDialog method open.

/**
 * Opens the dialog for displaying the graph
 *
 * @throws IOException may be thrown if the graph string from the database
 *             can fails to convert
 */
public void open() throws IOException {
    Shell parent = super.getParent();
    final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.MODELESS);
    shell.setFocus();
    shell.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            shell.setMinimized(true);
        }

        @Override
        public void focusGained(FocusEvent e) {
        // ignore
        }
    });
    shell.setLayout(GridLayoutFactory.fillDefaults().create());
    shell.setText(getText());
    final Composite viewerContainer = new Composite(shell, SWT.EMBEDDED);
    viewerContainer.setLayout(new FillLayout());
    viewerContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    TinkerGraph tgraph = new TinkerGraph();
    GraphMLReader greader = new GraphMLReader(tgraph);
    ByteArrayInputStream in;
    in = new ByteArrayInputStream(graphString.getBytes(("UTF-8")));
    greader.inputGraph(in);
    GraphViewer viewer = new GraphViewer(viewerContainer, SWT.NONE);
    TreeLayoutAlgorithm la = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
    viewer.setLabelProvider(new GraphMLLabelProvider());
    viewer.setContentProvider(new GraphMLContentProvider());
    viewer.setInput(tgraph.getEdges());
    viewer.setLayoutAlgorithm(la, true);
    viewer.applyLayout();
    viewerContainer.pack();
    viewerContainer.setVisible(true);
    shell.open();
    Display display = parent.getDisplay();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) FillLayout(org.eclipse.swt.layout.FillLayout) FocusEvent(org.eclipse.swt.events.FocusEvent) Shell(org.eclipse.swt.widgets.Shell) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) ByteArrayInputStream(java.io.ByteArrayInputStream) GraphMLReader(com.tinkerpop.blueprints.util.io.graphml.GraphMLReader) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display)

Example 3 with GraphMLReader

use of com.tinkerpop.blueprints.util.io.graphml.GraphMLReader in project blueprints by tinkerpop.

the class SparkseeGraphSpecificTestSuite method testMultipleSessions.

public void testMultipleSessions() throws InterruptedException, IOException {
    TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
    ((SparkseeGraph) graph).typeScope.set(true);
    this.stopWatch();
    // This test requires a multiple sessions license,
    // so just executed if a license has been given,
    // see SparkseeGraphTest#generateGraph(...) -> blueprints-sparksee.cfg
    com.sparsity.sparksee.gdb.SparkseeConfig cfg = new com.sparsity.sparksee.gdb.SparkseeConfig();
    if (cfg.getLicense() == null || cfg.getLicense().length() == 0) {
        printPerformance(graph.toString(), null, "skip because no license", this.stopWatch());
        graph.shutdown();
        return;
    }
    new GraphMLReader(graph).inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
    printPerformance(graph.toString(), null, "load", this.stopWatch());
    List<SessionThread> threads = new ArrayList<SessionThread>();
    for (int i = 0; i < 10; i++) threads.add(new SessionThread(graph));
    this.stopWatch();
    for (SessionThread th : threads) th.start();
    Thread.sleep(5000);
    for (SessionThread th : threads) th.stop = true;
    int acum = 0;
    for (SessionThread th : threads) {
        while (!th.finished) ;
        acum += th.counter;
    }
    printPerformance(graph.toString(), acum, "tx (sessions)", this.stopWatch());
    graph.shutdown();
}
Also used : GraphMLReader(com.tinkerpop.blueprints.util.io.graphml.GraphMLReader) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) ArrayList(java.util.ArrayList)

Example 4 with GraphMLReader

use of com.tinkerpop.blueprints.util.io.graphml.GraphMLReader in project blueprints by tinkerpop.

the class Neo4j2BatchGraphTest method testGraphMLLoad.

public void testGraphMLLoad() throws Exception {
    final String directory = this.getWorkingDirectory();
    final Neo4j2BatchGraph batch = new Neo4j2BatchGraph(directory);
    new GraphMLReader(batch).inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
    assertNotNull(batch.getVertex(1));
    assertNotNull(batch.getVertex(2));
    assertNotNull(batch.getVertex(3));
    assertNotNull(batch.getVertex(4));
    assertNotNull(batch.getVertex(5));
    assertNotNull(batch.getVertex(6));
    assertNull(batch.getVertex(7));
    assertEquals(batch.getVertex(1).getProperty("name"), "marko");
    assertEquals(batch.getVertex(2).getProperty("name"), "vadas");
    assertEquals(batch.getVertex(3).getProperty("name"), "lop");
    assertEquals(batch.getVertex(4).getProperty("name"), "josh");
    assertEquals(batch.getVertex(5).getProperty("name"), "ripple");
    assertEquals(batch.getVertex(6).getProperty("name"), "peter");
    batch.shutdown();
    // native neo4j graph load
    Neo4j2Graph graph = new Neo4j2Graph(directory);
    graph.autoStartTransaction(true);
    assertEquals(count(graph.getVertices()), 6);
    assertEquals(count(graph.getEdges()), 6);
    assertEquals(count(graph.getVertex("1").getEdges(Direction.OUT)), 3);
    assertEquals(count(graph.getVertex("1").getEdges(Direction.IN)), 0);
    Vertex marko = graph.getVertex("1");
    assertEquals(marko.getProperty("name"), "marko");
    assertEquals(marko.getProperty("age"), 29);
    int counter = 0;
    assertEquals(count(graph.getVertex("4").getEdges(Direction.OUT)), 2);
    assertEquals(count(graph.getVertex("4").getEdges(Direction.IN)), 1);
    Vertex josh = graph.getVertex("4");
    assertEquals(josh.getProperty("name"), "josh");
    assertEquals(josh.getProperty("age"), 32);
    for (Edge e : graph.getVertex("4").getEdges(Direction.OUT)) {
        if (e.getVertex(Direction.IN).getId().equals(3l)) {
            assertEquals(Math.round((Float) e.getProperty("weight")), 0);
            assertEquals(e.getLabel(), "created");
            counter++;
        } else if (e.getVertex(Direction.IN).getId().equals(5l)) {
            assertEquals(Math.round((Float) e.getProperty("weight")), 1);
            assertEquals(e.getLabel(), "created");
            counter++;
        }
    }
    assertEquals(counter, 2);
    graph.shutdown();
}
Also used : GraphMLReader(com.tinkerpop.blueprints.util.io.graphml.GraphMLReader) Neo4j2Graph(com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph)

Aggregations

GraphMLReader (com.tinkerpop.blueprints.util.io.graphml.GraphMLReader)4 Edge (com.tinkerpop.blueprints.Edge)1 TransactionalGraph (com.tinkerpop.blueprints.TransactionalGraph)1 Vertex (com.tinkerpop.blueprints.Vertex)1 Neo4jGraph (com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph)1 Neo4j2Graph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph)1 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1 GraphViewer (org.eclipse.zest.core.viewers.GraphViewer)1 TreeLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm)1