Comments (5)
Thank you for your question. Please keep the issue title in English at least and maintain the basic
[Question] xxx
format. Thank you for your understanding
To access the properties of edges and vertices after obtaining an edge iterator with Iterator<Edge> edges = edgesOfVertex(source, dir, label, degree);
, follow these steps:
-
Edge Attributes:
- To set a property, use
edge.property("key", "value");
where"key"
is the property name and"value"
is the property value. - To get a property, if there's a method to access properties, use it to retrieve the value by the property name, e.g.,
String value = (String) edge.properties().get("propertyName");
.
- To set a property, use
-
Vertex Attributes:
- Accessing vertex attributes directly from an edge requires you to first get the vertex object. The edge object provides methods like
sourceId()
andtargetId()
to get vertex identifiers, but to access vertex properties, you'll need to use the vertex object itself, which is not detailed in your snippet.
- Accessing vertex attributes directly from an edge requires you to first get the vertex object. The edge object provides methods like
-
Attribute Types:
- Attributes can be of any type, not just
String
. When you set or get a property, it's treated as anObject
. Ensure to cast it to the correct type when retrieving.
- Attributes can be of any type, not just
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.
Details
Sources
- hugegraph-client/src/main/java/org/apache/hugegraph/structure/graph/Edge.java
- hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeEdge.java
- hugegraph-client/src/main/java/org/apache/hugegraph/structure/graph/Graph.java
- hugegraph-client/src/main/java/org/apache/hugegraph/example/BatchExample.java
- content/en/docs/language/hugegraph-example.md
- hugegraph-client/src/main/java/org/apache/hugegraph/example/SingleExample.java
- content/en/docs/quickstart/hugegraph-client.md
- hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/Example1.java
- hugegraph-client/src/main/java/org/apache/hugegraph/structure/graph/Vertex.java
- hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeVertex.java
- hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/schema/PropertyKeyService.java
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.
To continue the conversation, mention @dosu.
from incubator-hugegraph.
要根据点ID同时查到点的邻边和另一端顶点的属性,可以使用HugeGraph工具链中的HugeVertex
类提供的edges
和vertices
方法。以下是一个示例代码:
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
方法用于获取边和相连顶点[1][2][3][4]。
Details
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.
To continue the conversation, mention @dosu.
from incubator-hugegraph.
edge.vertices(Direction.BOTH);
返回一个迭代器对象而不是单个顶点对象,因为它可能会返回多个顶点。具体来说,当方向是 BOTH
时,它包括边的源顶点和目标顶点。该方法设计用于处理不同的方向(OUT
、IN
、BOTH
),在 BOTH
的情况下,需要返回两个顶点,因此使用迭代器来容纳多个结果。
@Watched(prefix = "vertex")
@Override
public Iterator<Vertex> vertices(Direction direction, String... edgeLabels) {
Iterator<Edge> edges = this.edges(direction, edgeLabels);
return this.graph().adjacentVertices(edges);
}
这个代码片段来自 HugeVertex
类,显示了对于 BOTH
方向,该方法检索两个方向的边,然后返回相邻顶点的迭代器。这种设计确保了方法能够高效地处理多个顶点[1][2]。
To continue talking to Dosu, mention @dosu.
from incubator-hugegraph.
Thank you for your question. Please keep the issue title in English at least and maintain the basic
[Question] xxx
format. Thank you for your understandingTo access the properties of edges and vertices after obtaining an edge iterator with
Iterator<Edge> edges = edgesOfVertex(source, dir, label, degree);
, follow these steps:
Edge Attributes:
- To set a property, use
edge.property("key", "value");
where"key"
is the property name and"value"
is the property value.- To get a property, if there's a method to access properties, use it to retrieve the value by the property name, e.g.,
String value = (String) edge.properties().get("propertyName");
.Vertex Attributes:
- Accessing vertex attributes directly from an edge requires you to first get the vertex object. The edge object provides methods like
sourceId()
andtargetId()
to get vertex identifiers, but to access vertex properties, you'll need to use the vertex object itself, which is not detailed in your snippet.Attribute Types:
- Attributes can be of any type, not just
String
. When you set or get a property, it's treated as anObject
. Ensure to cast it to the correct type when retrieving.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.
Details
Sources
- hugegraph-client/src/main/java/org/apache/hugegraph/structure/graph/Edge.java
- hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeEdge.java
- hugegraph-client/src/main/java/org/apache/hugegraph/structure/graph/Graph.java
- hugegraph-client/src/main/java/org/apache/hugegraph/example/BatchExample.java
- content/en/docs/language/hugegraph-example.md
- hugegraph-client/src/main/java/org/apache/hugegraph/example/SingleExample.java
- content/en/docs/quickstart/hugegraph-client.md
- hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/Example1.java
- hugegraph-client/src/main/java/org/apache/hugegraph/structure/graph/Vertex.java
- hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeVertex.java
- hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/schema/PropertyKeyService.java
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.
To continue the conversation, mention @dosu.
根据点Id是否能够同时查到点的邻边和另一端顶点的属性
from incubator-hugegraph.
要根据点ID同时查到点的邻边和另一端顶点的属性,可以使用HugeGraph工具链中的
HugeVertex
类提供的edges
和vertices
方法。以下是一个示例代码: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
方法用于获取边和相连顶点[1][2][3][4]。Details
To continue the conversation, mention @dosu.
Iterator connectedVertices = edge.vertices(Direction.BOTH);这里获取与边相连的顶点,为什么返回的是一个迭代器对象,而不是一个vertex对象。
from incubator-hugegraph.
Related Issues (20)
- [Question] 创建顶点的时候,使用.ifNotExist()判断,但是还是出现下面错误 HOT 1
- [Bug] connect graph error in the hubble HOT 1
- 创建一个新的图,可以和原来的图共同存储在同一个mysql后端中吗? HOT 3
- [Question] Vulnerability found in dependency: CVE-2022-42889 9.8 Transitive Improper Control of Generation of Code ("Code Injection") vulnerability with High severity found HOT 2
- [Summary] update licenses/notice for 1.5 HOT 1
- [Question] gremlin-groovy is not an available GremlinScriptEngine HOT 1
- [Question] gremlin-groovy is not an available GremlinScriptEngine HOT 3
- hugegraph最大内存配置 HOT 3
- [Bug] AccessLogFilter for path matrics make Server OOM HOT 7
- 往hugegraph集群添加新机器一直不成功 HOT 3
- [Bug] 使用cypher api查询,提示Unsupported predicate: 'containing(XXXX)' HOT 5
- [Summary] Preparations for Releasing HugeGraph Distributed (pd-store, 1.5) Version
- [Bug] Resolved the cache invalidation of the partition->leader shard in ClientCache HOT 1
- [Bug] Memory leaks occur in HugeGraph Server during data writing. HOT 2
- Add comments to the initial-store-count attribute in pd application.yml
- [Bug] PD, Store process log files do not scroll HOT 1
- [Feature] support disable rocksdb auto compaction through configuration
- [Feature] add MiniCluster as integration test environment
- [Bug] pd /v1/partitions method returns data partition ID are all 0 HOT 1
- [refact] The pdconfig property in LogMeta and PartitionMeta is redundant HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from incubator-hugegraph.