-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
怎么访问边和顶点的属性? #2539
Comments
To access the properties of edges and vertices after obtaining an edge iterator with
This approach assumes you're working with the HugeGraph toolchain. For specific implementations or methods to access properties directly, refer to the documentation or source code of the HugeGraph client library you're using.
|
根据点Id是否能够同时查到点的邻边和另一端顶点的属性 |
要根据点ID同时查到点的邻边和另一端顶点的属性,可以使用HugeGraph工具链中的 import org.apache.hugegraph.structure.HugeEdge;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Property;
import java.util.Iterator;
public class HugeGraphExample {
public static void main(String[] args) {
// 假设你已经有一个HugeGraph实例和一个点ID
HugeGraph graph = ExampleUtil.loadGraph();
String vertexId = "your-vertex-id";
// 根据点ID获取点
HugeVertex vertex = (HugeVertex) graph.traversal().V(vertexId).next();
// 获取与该点相连的边
Iterator<Edge> edges = vertex.edges(Direction.BOTH);
while (edges.hasNext()) {
HugeEdge edge = (HugeEdge) edges.next();
// 获取边的属性
Iterator<Property<Object>> edgeProperties = edge.properties();
while (edgeProperties.hasNext()) {
Property<Object> property = edgeProperties.next();
System.out.println("Edge Property: " + property.key() + " = " + property.value());
}
// 获取相连的顶点
Iterator<Vertex> connectedVertices = edge.vertices(Direction.BOTH);
while (connectedVertices.hasNext()) {
HugeVertex connectedVertex = (HugeVertex) connectedVertices.next();
// 获取相连顶点的属性
Iterator<Property<Object>> vertexProperties = connectedVertex.properties();
while (vertexProperties.hasNext()) {
Property<Object> property = vertexProperties.next();
System.out.println("Vertex Property: " + property.key() + " = " + property.value());
}
}
}
graph.close();
HugeFactory.shutdown(30L);
}
} 在这个示例中,
|
Iterator connectedVertices = edge.vertices(Direction.BOTH);这里获取与边相连的顶点,为什么返回的是一个迭代器对象,而不是一个vertex对象。 |
@Watched(prefix = "vertex")
@Override
public Iterator<Vertex> vertices(Direction direction, String... edgeLabels) {
Iterator<Edge> edges = this.edges(direction, edgeLabels);
return this.graph().adjacentVertices(edges);
} 这个代码片段来自 |
Feature Description (功能描述)
通过Iterator edges = edgesOfVertex(source, dir,label, degree);得到边迭代器后,怎么访问每一条边和顶点的属性值,是字符类型吗
The text was updated successfully, but these errors were encountered: