首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用graph.OpenManagement()获取顶点标签gremlin的模式

如何使用graph.OpenManagement()获取顶点标签gremlin的模式
EN

Stack Overflow用户
提问于 2021-07-07 16:44:50
回答 1查看 125关注 0票数 1

我已经按照https://docs.janusgraph.org/basics/schema/#schema-constraints中的描述使用graph.OpenManagement()创建了标签模式

代码语言:javascript
复制
mgmt = graph.openManagement()
person = mgmt.makeVertexLabel('person').make()
name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SET).make()
birthDate = mgmt.makePropertyKey('birthDate').dataType(Long.class).cardinality(Cardinality.SINGLE).make()
mgmt.addProperties(person, name, birthDate)
mgmt.commit()

如何获取person标签模式。要获取标签的属性列表以及数据类型和基数信息的gremlin查询是什么?

我使用以下查询来获取具有数据类型的属性列表,但没有将属性映射到标签

代码语言:javascript
复制
gremlin> mgmt.printPropertyKeys()
==>------------------------------------------------------------------------------------------------
Property Key Name              | Cardinality | Data Type                                          |
---------------------------------------------------------------------------------------------------
name2                          | SINGLE      | class java.lang.String                             |
age2                           | SINGLE      | class java.lang.Integer                            |
name3                          | SET         | class java.lang.String                             |
birthDate3                     | SINGLE      | class java.lang.Long                               |
name4                          | SET         | class java.lang.String                             |
birthDate4                     | SINGLE      | class java.lang.Long                               |
name6                          | SINGLE      | class java.lang.String                             |
age6                           | SINGLE      | class java.lang.Integer                            |
name5                          | SINGLE      | class java.lang.String                             |
age5                           | SINGLE      | class java.lang.Integer                            |
mean_radius                    | SINGLE      | class java.lang.Integer                            |
distance_in_kms                | SINGLE      | class java.lang.Integer                            |
new_field                      | SINGLE      | class java.lang.String                             |
radius_in_kms                  | SINGLE      | class java.lang.Integer                            |
name                           | SINGLE      | class java.lang.String                             |
---------------------------------------------------------------------------------------------------
EN

回答 1

Stack Overflow用户

发布于 2021-07-28 20:05:05

获取顶点标签及其基本信息:

代码语言:javascript
复制
mgmt.getVertexLabels().forEach(vertexLabel -> {
    System.out.println("Vertex label: "+vertexLabel.name()+" isPartitioned: "+vertexLabel.isPartitioned()+" isStatic: "+vertexLabel.isStatic());
});

获取边缘标签及其基本信息:

代码语言:javascript
复制
mgmt.getRelationTypes(EdgeLabel.class).forEach(edgeLabel ->{
    System.out.println("Edge label: "+edgeLabel.name()+" Multiplicity: "+edgeLabel.multiplicity().name()+" isUnidirected:"+edgeLabel.isUnidirected());
});

获取属性及其基本信息:

代码语言:javascript
复制
mgmt.getRelationTypes(PropertyKey.class).forEach(propertyKey -> {
    System.out.println("Property key: "+propertyKey.name()+" Cardinality: "+propertyKey.cardinality().name()+" Datatype: "+propertyKey.dataType().getName());
});

现在,当您获得一个特定的Vertex标签或一个特定的Edge标签时(如上所示),您可以请求模式约束信息,如下所示。同样的方法也可用于VertexLabelEdgeLabel

获取顶点标签属性:

代码语言:javascript
复制
VertexLabel vertexLabel = mgmt.getVertexLabel("myVertexLabel");
vertexLabel.mappedProperties().forEach(propertyKey -> {
  // get information about `propertyKey` as shown above in `Getting properties and their basic information` section
});

获取顶点标签连接:

代码语言:javascript
复制
VertexLabel vertexLabel = mgmt.getVertexLabel("myVertexLabel");
vertexLabel.mappedConnections().forEach(connection -> {
  // connection.getEdgeLabel() - return the label of the edge. You can use it to access the edge itself if needed like: 
 EdgeLabel edgeLabel = mgmt.getEdgeLabel(connection.getEdgeLabel());
 // You can access JanusGraphEdge via:
 JanusGraphEdge janusGraphEdge = connection.getConnectionEdge();
 // Having JanusGraphEdge you can access EdgeLabel directly via:
 edgeLabel = janusGraphEdge.edgeLabel();
 // You can also access incoming or outgoing vertices of this connection via: connection.getIncomingVertexLabel() or connection.getOutgoingVertexLabel()
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68282825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档