dosubot[bot] commented on issue #2539:
URL: 
https://github.com/apache/incubator-hugegraph/issues/2539#issuecomment-2134472622

   <!-- Answer -->
   
要根据点ID同时查到点的邻边和另一端顶点的属性,可以使用HugeGraph工具链中的`HugeVertex`类提供的`edges`和`vertices`方法。以下是一个示例代码:
   
   ```java
   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);
       }
   }
   ```
   
   
在这个示例中,`ExampleUtil.loadGraph()`方法用于加载`HugeGraph`实例。代码通过点ID获取点,遍历与该点相连的边,并获取边和相连顶点的属性。请确保将`"your-vertex-id"`替换为你要查询的实际点ID。`HugeVertex`类中的`edges`和`vertices`方法用于获取边和相连顶点<sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeEdge.java)</sup><sup>[[2]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/Example1.java)</sup><sup>[[3]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeVertex.java)</sup><sup>[[4]](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/language/hugegraph-example.md)</sup>。
   
   
   <!-- Dosu Comment Footer -->
   <details>
   <summary>
   
   #### Details
   </summary>
   
   **About Dosu**
   This response is meant to be useful and save you time. It is **not meant to 
be a precise solution**, but rather a starting point for your own research.
   
   Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is 
irrelevant.
   </details>
   
   *To continue the conversation, mention @dosu.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to