Package com.tinkerpop.blueprints.impls.tg

Examples of com.tinkerpop.blueprints.impls.tg.TinkerGraph


    }

    public void testQuadLoading() {
        int numEdges = 10000;
        String[][] quads = generateQuads(100, numEdges, new String[]{"knows", "friend"});
        TinkerGraph graph = new TinkerGraph();
        BatchGraph bgraph = new BatchGraph(new WritethroughGraph(graph), VertexIDType.STRING, 1000);
        for (String[] quad : quads) {
            Vertex[] vertices = new Vertex[2];
            for (int i = 0; i < 2; i++) {
                vertices[i] = bgraph.getVertex(quad[i]);
                if (vertices[i] == null) vertices[i] = bgraph.addVertex(quad[i]);
            }
            Edge edge = bgraph.addEdge(null, vertices[0], vertices[1], quad[2]);
            edge.setProperty("annotation", quad[3]);
        }
        assertEquals(numEdges, BaseTest.count(graph.getEdges()));

        bgraph.shutdown();
    }
View Full Code Here


    }

    public void testLoadingWithExisting1() {
        int numEdges = 1000;
        String[][] quads = generateQuads(100, numEdges, new String[]{"knows", "friend"});
        TinkerGraph tg = new TinkerGraph();
        BatchGraph bg = new BatchGraph(new WritethroughGraph(tg), VertexIDType.STRING, 100);
        bg.setLoadingFromScratch(false);
        Graph graph = null;
        int counter = 0;
        for (String[] quad : quads) {
            if (counter < numEdges / 2) graph = tg;
            else graph = bg;

            Vertex[] vertices = new Vertex[2];
            for (int i = 0; i < 2; i++) {
                vertices[i] = graph.getVertex(quad[i]);
                if (vertices[i] == null) vertices[i] = graph.addVertex(quad[i]);
            }
            Edge edge = graph.addEdge(null, vertices[0], vertices[1], quad[2]);
            edge.setProperty("annotation", quad[3]);
            counter++;
        }
        assertEquals(numEdges, BaseTest.count(tg.getEdges()));

        bg.shutdown();
    }
View Full Code Here

    }

    public void testLoadingWithExisting2() {
        int numEdges = 1000;
        String[][] quads = generateQuads(100, numEdges, new String[]{"knows", "friend"});
        TinkerGraph tg = new IgnoreIdTinkerGraph();
        BatchGraph bg = new BatchGraph(new WritethroughGraph(tg), VertexIDType.STRING, 100);
        try {
            bg.setLoadingFromScratch(false);
            fail();
        } catch (IllegalStateException e) {
        }
        bg.setVertexIdKey("uid");
        bg.setLoadingFromScratch(false);
        try {
            bg.setVertexIdKey(null);
            fail();
        } catch (IllegalStateException e) {
        }

        Graph graph = null;
        int counter = 0;
        for (String[] quad : quads) {
            if (counter < numEdges / 2) graph = tg;
            else graph = bg;

            Vertex[] vertices = new Vertex[2];
            for (int i = 0; i < 2; i++) {
                vertices[i] = graph.getVertex(quad[i]);
                if (vertices[i] == null) vertices[i] = graph.addVertex(quad[i]);
            }
            Edge edge = graph.addEdge(null, vertices[0], vertices[1], quad[2]);
            edge.setProperty("annotation", quad[3]);
            counter++;
        }
        assertEquals(numEdges, BaseTest.count(tg.getEdges()));

        bg.shutdown();
    }
View Full Code Here

        MockTransactionalGraph tgraph = null;
        if (ignoreIDs) {
            tgraph = new MockTransactionalGraph(new IgnoreIdTinkerGraph());
        } else {
            tgraph = new MockTransactionalGraph(new TinkerGraph());
        }

        BLGraph graph = new BLGraph(tgraph, counter, ids);
        BatchGraph<BLGraph> loader = new BatchGraph<BLGraph>(graph, type, bufferSize);
View Full Code Here

import java.util.Iterator;

public class GMLWriterTest extends TestCase {

    public void testNormal() throws Exception {
        TinkerGraph g = new TinkerGraph();
        GMLReader.inputGraph(g, GMLReaderTest.class.getResourceAsStream("example.gml"));

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GMLWriter w = new GMLWriter(g);
        w.setNormalize(true);
View Full Code Here

        assertEquals(expected.replace("\r", ""), actual.replace("\r", ""));

    }

    public void testUseIds() throws Exception {
        TinkerGraph g = new TinkerGraph();
        GMLReader.inputGraph(g, GMLReaderTest.class.getResourceAsStream("example.gml"));

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GMLWriter w = new GMLWriter(g);
        w.setNormalize(true);
View Full Code Here

        assertEquals(expected.replace("\r", ""), actual.replace("\r", ""));

    }

    public void testRoundTrip() throws Exception {
        TinkerGraph g1 = TinkerGraphFactory.createTinkerGraph();

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GMLWriter w = new GMLWriter(g1);
        w.setUseId(true);
        w.outputGraph(bos);

        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());

        Graph g2 = new TinkerGraph();
        GMLReader.inputGraph(g2, bis);

        assertEquals(getIterableCount(g1.getVertices()), getIterableCount(g2.getVertices()));
        assertEquals(getIterableCount(g1.getEdges()), getIterableCount(g2.getEdges()));

    }
View Full Code Here

        assertEquals(getIterableCount(g1.getEdges()), getIterableCount(g2.getEdges()));

    }

    public void testRoundTripIgnoreBadProperties() throws Exception {
        TinkerGraph g1 = TinkerGraphFactory.createTinkerGraph();
        Vertex v = g1.getVertex(1);
        v.setProperty("bad_property", "underscore");
        v.setProperty("bad property", "space");
        v.setProperty("bad-property", "dash");
        v.setProperty("bad$property", "other stuff");
        v.setProperty("badproperty_", "but don't get too fancy");
        v.setProperty("_badproperty", "or it won't work");
        v.setProperty("55", "numbers alone are bad");
        v.setProperty("5badproperty", "must start with alpha");
        v.setProperty("badpropertyajflalfjsajfdfjdkfjsdiahfshfksajdhfkjdhfkjhaskdfhaksdhfsalkjdfhkjdhkahsdfkjasdhfkajfdhkajfhkadhfkjsdafhkajfdhasdkfhakfdhakjsdfhkadhfakjfhaksdjhfkajfhakhfaksfdhkahdfkahfkajsdhfkjahdfkahsdfkjahfkhakfsdjhakjksfhakfhaksdhfkadhfakhfdkasfdhiuerfaeafdkjhakfdhfdadfasdfsdafadf", "super long keys won't work");
        v.setProperty("good5property", "numbers are cool");
        v.setProperty("goodproperty5", "numbers are cool");
        v.setProperty("a", "one letter is ok");

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GMLWriter w = new GMLWriter(g1);
        w.setStrict(true);
        w.setUseId(true);
        w.outputGraph(bos);

        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());

        Graph g2 = new TinkerGraph();
        GMLReader.inputGraph(g2, bis);

        assertEquals(getIterableCount(g1.getVertices()), getIterableCount(g2.getVertices()));
        assertEquals(getIterableCount(g1.getEdges()), getIterableCount(g2.getEdges()));

        Vertex v1 = g2.getVertex(1);
        Assert.assertNull(v1.getProperty("bad_property"));
        Assert.assertNull(v1.getProperty("bad property"));
        Assert.assertNull(v1.getProperty("bad-property"));
        Assert.assertNull(v1.getProperty("bad$property"));
        Assert.assertNull(v1.getProperty("_badproperty"));
View Full Code Here

     * This tests checks, if quotation marks (") are escaped correctly, before
     * they are written to the GML file.
     * @throws Exception if something fails
     */
    public void testWriteStringPropertyWithQuotationMarks() throws Exception {
      TinkerGraph g1 = TinkerGraphFactory.createTinkerGraph();
      Vertex v = g1.getVertex(1);
      v.setProperty("escape_property", "quotation \"quote\" quotation end");

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      GMLWriter w = new GMLWriter(g1);
      w.setUseId(true);
View Full Code Here

    // It is known that there are characters which, when written by GMLWriter,
    // cause parse errors for GraphMLReader.
    // However, this happens uncommonly enough that is not yet known which characters those are.
    public void testEncoding() throws Exception {

        Graph g = new TinkerGraph();
        Vertex v = g.addVertex(1);
        v.setProperty("text", "\u00E9");

        GMLWriter w = new GMLWriter(g);

        File f = File.createTempFile("test", "txt");
        f.deleteOnExit();
        OutputStream out = new FileOutputStream(f);
        w.outputGraph(out);
        out.close();

        Graph g2 = new TinkerGraph();
        GMLReader r = new GMLReader(g2);

        InputStream in = new FileInputStream(f);
        r.inputGraph(in);
        in.close();

        Vertex v2 = g2.getVertex(1);
        assertEquals("\u00E9", v2.getProperty("text"));
    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.impls.tg.TinkerGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.