微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我已经使用 https://docs.janusgraph.org/basics/schema/#schema-constraints

中所述的 graph.OpenManagement() 创建了标签架构
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 查询是什么。

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

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                             |
---------------------------------------------------------------------------------------------------

解决方法

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

mgmt.getVertexLabels().forEach(vertexLabel -> {
    System.out.println("Vertex label: "+vertexLabel.name()+" isPartitioned: "+vertexLabel.isPartitioned()+" isStatic: "+vertexLabel.isStatic());
});

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

mgmt.getRelationTypes(EdgeLabel.class).forEach(edgeLabel ->{
    System.out.println("Edge label: "+edgeLabel.name()+" Multiplicity: "+edgeLabel.multiplicity().name()+" isUnidirected:"+edgeLabel.isUnidirected());
});

获取属性及其基本信息:

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

现在,当您获得特定的 Vertex 标签或特定的 Edge 标签(如上所示)时,您可以询问架构约束信息,如下所示。相同的方法可用于 VertexLabelEdgeLabel

获取顶点标签属性:

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

获取顶点标签连接:

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()
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。