Monday 7 February 2022

JanusGraph: Define vertex labels

You can define vertex labels using ‘janusGraphManagement.makeVertexLabel()’ method. Vertex labels must be unique in the graph.

 

Example

VertexLabelMaker vertexLabelMaker = janusGraphManagement.makeVertexLabel("software");
VertexLabel vertexLabel = vertexLabelMaker.make();

 

Find the below working application.

 

ModelVertexLabel.java

 

package com.sample.app.schema;

import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.VertexLabel;
import org.janusgraph.core.schema.JanusGraphManagement;
import org.janusgraph.core.schema.VertexLabelMaker;

public class ModelVertexLabel {
	public static void main(String args[]) {

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

			JanusGraphManagement janusGraphManagement = janusGraph.openManagement();

			VertexLabelMaker vertexLabelMaker = janusGraphManagement.makeVertexLabel("software");
			VertexLabel vertexLabel = vertexLabelMaker.make();

			janusGraph.tx().commit();

			String vertexLabels = janusGraphManagement.printVertexLabels();

			System.out.println(vertexLabels);
		} finally {
			System.out.println("\nDone!!!");
		}

	}
}

 

Output

------------------------------------------------------------------------------------------------
Vertex Label Name              | Partitioned | Static                                             |
---------------------------------------------------------------------------------------------------
software                       | false       | false                                              |
---------------------------------------------------------------------------------------------------


Done!!!

 

Is vertex labels mandatory?

Vertex labels are optional.

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment