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();
}
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();
}
}
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();
}
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();
}
Aggregations