Search in sources :

Example 71 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project gremlin by tinkerpop.

the class GremlinGroovyScriptEngineTest method testUTF8Query.

public void testUTF8Query() throws Exception {
    TinkerGraph graph = new TinkerGraph();
    Index<Vertex> index = graph.createIndex("nodes", Vertex.class);
    Vertex nonUtf8 = graph.addVertex("1");
    nonUtf8.setProperty("name", "marko");
    nonUtf8.setProperty("age", 29);
    index.put("name", "marko", nonUtf8);
    Vertex utf8Name = graph.addVertex("2");
    utf8Name.setProperty("name", "轉注");
    utf8Name.setProperty("age", 32);
    index.put("name", "轉注", utf8Name);
    graph.addVertex(utf8Name);
    graph.addEdge("12", nonUtf8, utf8Name, "created").setProperty("weight", 0.2f);
    ScriptEngine engine = new GremlinGroovyScriptEngine();
    engine.put("g", graph);
    Pipeline eval = (Pipeline) engine.eval("g.idx(\"nodes\")[['name' : 'marko']]");
    assertEquals(nonUtf8, eval.next());
    eval = (Pipeline) engine.eval("g.idx(\"nodes\")[['name' : '轉注']]");
    assertEquals(utf8Name, eval.next());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ScriptEngine(javax.script.ScriptEngine) Pipeline(com.tinkerpop.pipes.util.Pipeline)

Example 72 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class KeyIndexableGraphHelperTest method testReIndexElements.

public void testReIndexElements() {
    TinkerGraph graph = TinkerGraphFactory.createTinkerGraph();
    assertTrue(graph.getVertices("name", "marko") instanceof PropertyFilteredIterable);
    assertEquals(count(graph.getVertices("name", "marko")), 1);
    assertEquals(graph.getVertices("name", "marko").iterator().next(), graph.getVertex(1));
    graph.createKeyIndex("name", Vertex.class);
    // KeyIndexableGraphHelper.reIndexElements(graph, graph.getVertices(), new HashSet<String>(Arrays.asList("name")));
    assertFalse(graph.getVertices("name", "marko") instanceof PropertyFilteredIterable);
    assertEquals(count(graph.getVertices("name", "marko")), 1);
    assertEquals(graph.getVertices("name", "marko").iterator().next(), graph.getVertex(1));
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph)

Example 73 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class PropertyFilteredIterableTest method testBasicFunctionality.

public void testBasicFunctionality() {
    TinkerGraph graph = new TinkerGraph();
    Vertex a = graph.addVertex("a");
    a.setProperty("age", 29);
    Vertex b = graph.addVertex("b");
    b.setProperty("age", 29);
    Vertex c = graph.addVertex("c");
    c.setProperty("age", 30);
    Vertex d = graph.addVertex("d");
    d.setProperty("age", 31);
    // throw a vertex without the expected key in the mix
    Vertex e = graph.addVertex("e");
    List<Vertex> list = Arrays.asList(a, b, c, d, e);
    PropertyFilteredIterable<Vertex> iterable = new PropertyFilteredIterable<Vertex>("age", 29, list);
    assertEquals(count(iterable), 2);
    assertEquals(count(iterable), 2);
    for (Vertex vertex : iterable) {
        assertTrue(vertex.equals(a) || vertex.equals(b));
    }
    iterable = new PropertyFilteredIterable<Vertex>("age", 30, list);
    assertEquals(count(iterable), 1);
    assertEquals(iterable.iterator().next(), c);
    iterable = new PropertyFilteredIterable<Vertex>("age", 30, graph.getVertices());
    assertEquals(count(iterable), 1);
    assertEquals(iterable.iterator().next(), c);
    iterable = new PropertyFilteredIterable<Vertex>("age", 37, list);
    assertEquals(count(iterable), 0);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph)

Example 74 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class GMLReaderTest method example2GMLTestingMapParsing.

@Test
public void example2GMLTestingMapParsing() throws IOException {
    TinkerGraph graph = new TinkerGraph();
    GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example2.gml"));
    Assert.assertEquals(2, getIterableCount(graph.getVertices()));
    Assert.assertEquals(1, getIterableCount(graph.getEdges()));
    Object property = graph.getVertex(1).getProperty(GMLTokens.GRAPHICS);
    Assert.assertTrue(property instanceof Map<?, ?>);
    @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) property;
    Assert.assertEquals(5, map.size());
    Assert.assertEquals(0.1f, map.get("x"));
    // NB comes back as int
    Assert.assertEquals(0, map.get("y"));
    Assert.assertEquals(0.1f, map.get("w"));
    Assert.assertEquals(0.1f, map.get("h"));
    Assert.assertEquals("earth.gif", map.get("bitmap"));
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Map(java.util.Map) Test(org.junit.Test)

Example 75 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class GMLReaderTest method exampleGMLGetsCorrectProperties.

@Test
public void exampleGMLGetsCorrectProperties() throws IOException {
    TinkerGraph graph = new TinkerGraph();
    GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example.gml"));
    Vertex v1 = graph.getVertex(1);
    Assert.assertEquals("Node 1", v1.getProperty(LABEL));
    Vertex v2 = graph.getVertex(2);
    Assert.assertEquals("Node 2", v2.getProperty(LABEL));
    Vertex v3 = graph.getVertex(3);
    Assert.assertEquals("Node 3", v3.getProperty(LABEL));
    Iterable<Edge> out1 = v1.getEdges(Direction.OUT);
    Edge e1 = out1.iterator().next();
    Assert.assertEquals("Edge from node 1 to node 2", e1.getLabel());
    Iterable<Edge> out2 = v2.getEdges(Direction.OUT);
    Edge e2 = out2.iterator().next();
    Assert.assertEquals("Edge from node 2 to node 3", e2.getLabel());
    Iterable<Edge> out3 = v3.getEdges(Direction.OUT);
    Edge e3 = out3.iterator().next();
    Assert.assertEquals("Edge from node 3 to node 1", e3.getLabel());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Aggregations

TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)105 Vertex (com.tinkerpop.blueprints.Vertex)66 Graph (com.tinkerpop.blueprints.Graph)58 Test (org.junit.Test)42 Edge (com.tinkerpop.blueprints.Edge)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JSONObject (org.codehaus.jettison.json.JSONObject)10 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)10 InputStream (java.io.InputStream)9 HashSet (java.util.HashSet)9 JSONTokener (org.codehaus.jettison.json.JSONTokener)8 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)7 Map (java.util.Map)6 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)6 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)4 IgnoreIdTinkerGraph (com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph)4