当前位置: 首页>>代码示例>>Java>>正文


Java TitanGraph.addVertex方法代码示例

本文整理汇总了Java中com.thinkaurelius.titan.core.TitanGraph.addVertex方法的典型用法代码示例。如果您正苦于以下问题:Java TitanGraph.addVertex方法的具体用法?Java TitanGraph.addVertex怎么用?Java TitanGraph.addVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.thinkaurelius.titan.core.TitanGraph的用法示例。


在下文中一共展示了TitanGraph.addVertex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doWork

import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
private void doWork()
    {
        TitanGraph graph = TitanFactory.build().set("storage.backend", "inmemory").open();

        // do "auto" transaction work
        graph.addVertex("type", "human");
        graph.tx().commit();

        // do "named" transaction work
//        TitanTransaction tx = graph.buildTransaction().logIdentifier("david1").start();
//        Vertex v = tx.addVertex("type", "dog");
//        Long id = (Long)v.id();
//        tx.commit();

//        GraphTraversalSource g = graph.traversal();
//        Vertex v1 = g.V(id.longValue()).next();
//        v1.remove();

        graph.close();
    }
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:21,代码来源:Driver.java

示例2: main

import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
public static void main(String[] args) {
    String dataDir = "./data";
    TitanGraph graph = TitanFactory.open("berkeleyje:" + dataDir);

    // see org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateClassic()
    final Vertex marko = graph.addVertex("name", "marko", "age", 29);
    final Vertex vadas = graph.addVertex("name", "vadas", "age", 27);
    final Vertex lop = graph.addVertex("name", "lop", "lang", "java");
    final Vertex josh = graph.addVertex("name", "josh", "age", 32);
    final Vertex ripple = graph.addVertex("name", "ripple", "lang", "java");
    final Vertex peter = graph.addVertex("name", "peter", "age", 35);
    marko.addEdge("knows", vadas, "weight", 0.5f);
    marko.addEdge("knows", josh, "weight", 1.0f);
    marko.addEdge("created", lop, "weight", 0.4f);
    josh.addEdge("created", ripple, "weight", 1.0f);
    josh.addEdge("created", lop, "weight", 0.4f);
    peter.addEdge("created", lop, "weight", 0.2f);

    GraphTraversalSource g = graph.traversal();
    Vertex fromNode = g.V().has("name", "marko").next();
    Vertex toNode = g.V().has("name", "peter").next();
    ArrayList list = new ArrayList();
    g.V(fromNode).repeat(both().simplePath()).until(is(toNode)).limit(1).path().fill(list);
    LOGGER.info(list.toString());
    System.exit(0);
}
 
开发者ID:pluradj,项目名称:titan-tp3-java-example,代码行数:27,代码来源:JavaExample.java

示例3: codeSnippets

import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
private static void codeSnippets() throws Exception {
    TitanGraph g = TitanFactory.open("/tmp/titan");
    g.createKeyIndex("name", Vertex.class);
    Vertex juno = g.addVertex(null);
    juno.setProperty("name", "juno");
    juno = g.getVertices("name", "juno").iterator().next();

    TransactionalGraph tx = g.newTransaction();
    Thread[] threads = new Thread[10];
    for (int i = 0; i < threads.length; i++) {
        //threads[i]=new Thread(new DoSomething(tx));
        threads[i].start();
    }
    for (int i = 0; i < threads.length; i++) threads[i].join();
    tx.commit();
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:17,代码来源:TestBed.java

示例4: testCanReadListValuedProperty

import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
@Test
public void testCanReadListValuedProperty() throws Exception {
    TitanGraph tg = TitanFactory.open(getTitanConfiguration());

    TitanManagement mgmt = tg.getManagementSystem();
    mgmt.makePropertyKey("email").dataType(String.class).cardinality(com.thinkaurelius.titan.core.Cardinality.LIST).make();
    mgmt.commit();
    tg.commit();

    TitanVertex v = tg.addVertex();
    v.addProperty("email", "one");
    v.addProperty("email", "two");
    tg.commit();

    Configuration c = new Configuration();
    c.set("titan.hadoop.input.format", "com.thinkaurelius.titan.hadoop.formats.cassandra.TitanCassandraInputFormat");
    c.set("titan.hadoop.input.conf.storage.backend", "cassandrathrift");
    c.set("titan.hadoop.input.conf.storage.cassandra.keyspace", KEYSPACE_NAME);
    c.set("titan.hadoop.sideeffect.format", "org.apache.hadoop.mapreduce.lib.output.TextOutputFormat");
    c.set("titan.hadoop.output.format", "com.thinkaurelius.titan.hadoop.formats.graphson.GraphSONOutputFormat");
    c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner");

    HadoopGraph hg = new HadoopGraph(c);

    assertEquals(0, new HadoopPipeline(hg).V().map().submit());
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:27,代码来源:TitanCassandraInputFormatTest.java

示例5: generateData

import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
/**
 * Generate a scale-free graph using parameters specified in the
 * {@link Schema} object provided to this instance's constructor. The types
 * must already exist. The types can be created by either calling
 * {@link #generateTypesAndData(TitanGraph)} instead of this method or by
 * calling {@link Schema#makeTypes(TitanGraph)} before calling this method.
 *
 * @param g A graph with types predefined. If it already contains vertices
 *          or relations, they may be overwritten.
 */
public void generateData(TitanGraph g) {

    // Generate vertices
    for (long i = uidCounter; i < schema.getVertexCount() + INITIAL_VERTEX_UID - 1; i++) {
        Vertex v = g.addVertex(i);
        // DistributionGenerator doesn't currently support VertexAnnotator
        vertexAnnotator.annotate(v, null);
    }

    // Generate edges
    for (int i = 0; i < schema.getEdgeLabels(); i++) {
        DistributionGenerator gen = new DistributionGenerator(schema.getEdgeLabelName(i), edgeAnnotator);
        gen.setOutDistribution(new PowerLawDistribution(GAMMA));
        gen.setInDistribution(new PowerLawDistribution(GAMMA));
        gen.generate(g, schema.getEdgeCount());
    }

    g.commit();

    TitanTransaction tx = g.newTransaction();
    // Add a vertex that has an out edge to every other vertex
    Vertex hiOutDeg = tx.addVertex(Schema.SUPERNODE_UID);
    String label = schema.getSupernodeOutLabel();
    PropertyKey uidKey = tx.getPropertyKey(Schema.UID_PROP);
    hiOutDeg.setProperty(Schema.UID_PROP, Schema.SUPERNODE_UID);
    String pKey = schema.getSortKeyForLabel(label);
    for (long i = INITIAL_VERTEX_UID; i < schema.getVertexCount(); i++) {
        Vertex in = Iterables.getOnlyElement(tx.getVertices(uidKey, i));
        Edge e = hiOutDeg.addEdge(label, in);
        e.setProperty(pKey, (int) i);
    }

    tx.commit();
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:45,代码来源:GraphGenerator.java

示例6: main

import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

		Configuration conf = new PropertiesConfiguration( getRelativeResourcePath( "titan-cassandra-es.properties" ) );
		// start elastic search on startup
		Node node = new NodeBuilder().node();
		
		TitanGraph graph = TitanFactory.open(conf);
		/* Comment if you do not want to reload the graph every time */
		graph.close();
		TitanCleanup.clear(graph);
		graph = TitanFactory.open(conf);
		GraphOfTheGodsFactory.load(graph);
		/* graph loaded  */
		
		// create own indexes
		TitanManagement mgmt = graph.openManagement();
		PropertyKey name = mgmt.getPropertyKey("name");
		PropertyKey age = mgmt.getPropertyKey("age");
		mgmt.buildIndex( "byNameComposite", Vertex.class ).addKey(name).buildCompositeIndex();
		// index consisting of multiple properties
		mgmt.buildIndex( "byNameAndAgeComposite", Vertex.class ).addKey(name).addKey(age).buildCompositeIndex();
		mgmt.commit();
		
		// wait for the index to become available
		ManagementSystem.awaitGraphIndexStatus(graph, "byNameComposite").call();
		ManagementSystem.awaitGraphIndexStatus(graph, "byNameAndAgeComposite").call();
		
		// create new vertex
		Vertex me = graph.addVertex("theOneAndOnly");
		me.property( "name", "me" );
		me.property( "age", 1 );
		graph.tx().commit();
		System.out.println("Created the one and only!");
		
		// re index the existing data (not required, just for demo purposes)
		mgmt = graph.openManagement();
		mgmt.updateIndex( mgmt.getGraphIndex("byNameComposite"), SchemaAction.REINDEX ).get();
		mgmt.updateIndex( mgmt.getGraphIndex("byNameAndAgeComposite"), SchemaAction.REINDEX ).get();
		mgmt.commit();
		
		GraphTraversalSource g = graph.traversal();
		GremlinPipeline<GraphTraversal<?, ?>, ?> pipe = new GremlinPipeline();
		
		// read our new vertex
		pipe.start( g.V().has( "name", "me" ) );	
		Vertex v = (Vertex)pipe.next();
		System.out.println();
		System.out.println( "Label: " + v.label() );
		System.out.println( "Name: " + v.property("name").value() );
		System.out.println( "Age: " + v.property("age").value() );
		System.out.println();
		
		// read different vertex
		pipe.start( g.V().has( "name", "hercules" ) );	
		Vertex herclues = (Vertex)pipe.next();
		System.out.println( "Label: " + herclues.label() );
		System.out.println( "Name: " + herclues.property("name").value() );
		System.out.println( "Age: " + herclues.property("age").value() );
		
		// print some edges
		Iterator<Edge> it = herclues.edges( Direction.OUT );
		while( it.hasNext() ) {
			Edge e = it.next();
			System.out.println( "Out: " + e.label()  + " --> " + e.inVertex().property("name").value() );
		}
		System.out.println();
		
		// close graph
		graph.close();
		// close elastic search on shutdown
		node.close();
		
		System.exit(0);
	}
 
开发者ID:maltesander,项目名称:titan-cassandra-elasticsearch-index,代码行数:75,代码来源:TitanStart.java


注:本文中的com.thinkaurelius.titan.core.TitanGraph.addVertex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。