Sunday, 30 January 2022

JanusGraph: Add a label to vertex

While adding a vertex to the graph, you can attach a label to it. A vertex label is a label attached to vertices in a JanusGraph graph. This can be used to define the nature of a vertex.

 

Example

JanusGraphVertex janusGraphVertex = janusGraph.addVertex("person");

 

VertexLabel.java

package com.sample.app.vertex;

import java.util.Iterator;

import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.JanusGraphVertex;

public class VertexLabel {

	public static void main(String args[]) {

		JanusGraph janusGraph = JanusGraphFactory.open("/Users/Shared/janus.properties");

		// Create a person vertex
		JanusGraphVertex janusGraphVertex = janusGraph.addVertex("person");
		janusGraph.tx().commit();

		Iterator<Vertex> janusGraphVertexes = janusGraph.vertices(janusGraphVertex.id());
		Vertex vertex = janusGraphVertexes.next();

		System.out.println("label : " + vertex.label());

		janusGraph.close();
		System.out.println("Done!!!");
	}

}

 

Output

label : person
Done!!!

 

 

 

  

Previous                                                 Next                                                 Home

No comments:

Post a Comment