***************************************************** Accessing Properties and Labels on Vertices and Edges ***************************************************** Setting and Getting Property Values ----------------------------------- PGX offers the following methods for setting and getting property values in the :class:`PgxProperty` class: .. code-block:: python :linenos: prop[key] You can either pass in a :class:`PgxVertex`/:class:`PgxEdge` object or directly assign the vertex/edge identifier values. Another way to get vertex/edge property values is to pass vertex/edge property name to :meth:`PgxVertex.get_property`/:class:`PgxEdge.get_property` methods. Examples: .. code-block:: python :linenos: vip = G.get_vertex_property("vip") cost = G.get_edge_property("cost") vertex = G.get_vetex(801) edge = G.get_edge(5692) is_vip = vip.get(vertex) cost_value = cost.get(edge) is_vip = vip.get(801) cost_value = cost.get(5692) is_vip = vertex.get_property("vip") cost_value = edge.get_property("cost") Similarly, the client can set the value of properties by applying one of the following methods in :class:`PgxProperty`: .. code-block:: python :linenos: property.property(key, value) Property values may be set in a number of ways. A single property value can be set directly (first method), or the property values for several vertices and edges can be set all at once. Using the following :meth:`fill()` method, the client can set the same value for a property in every vertex or edge of the graph: .. code-block:: python :linenos: property.fill(value) You can set a single property value through the following method of :class:`PgxVertex` and :class:`PgxEdge` .. code-block:: python :linenos: edge.get_property(property_name) vertex.get_property(property_name) Ordered Iteration over the values of a Property ----------------------------------------------- To iterate the values of a property, the client can invoke the following methods in the :class:`PgxProperty` class: .. code-block:: python :linenos: property.get_values() property.get_bottom_k_values(k) property.get_top_k_values(k) The method :meth:`get_values` returns an iterator of key-value pairs; the key is the unique :class:`PgxVertex` and the value is the value of this property for that vertex or edge. The iteration does not necessarily follow a specific order. The next two methods (:meth:`get_top_k_values` and :meth:`get_bottom_k_values`) return similar iterators. However, these iterators are ordered by the value of this property, in descending or ascending order up to K elements. Getting Label Values -------------------- PGX provides :class:`VertexLabels` and :class:`EdgeLabel` for multiple labels on a vertex and a single label on an edge. The property graph model that PGX support defines such label concepts. Similar to the property access, to access vertex labels, PGX offers the following methods of :class:`VertexLabels`: .. code-block:: python :linenos: vertices.get(key) To access an edge label, PGX offers the following methods of :class:`EdgeLabel`: .. code-block:: python :linenos: edges.get(key) You can either pass in a :class:`PgxVertex` / :class:`PgxEdge` object or directly assign the vertex/edge identifier values and a boxed Java object with the appropriate type that contains the requested value is returned. Another way to get vertex/edge labels is to directly call :meth:`PgxVertex.labels` / :meth:`PgxEdge.labels` methods. Examples: .. code-block:: python :linenos: G = ... vertex_labels = G.get_vertex_labels() edge_label = G.get_edge_label() vertex = G.get_vertex(801) edge = G.get_edge(5692L) v_labels = vertex_labels.get(vertex) e_label = edge_label.get(edge) # shortcuts v_labels = vertex_labels.get(801) e_label = edge_label.get(5692L) # from PgxVertex and PgxEdge v_labels = vertex.get_labels() e_label = edge.get_label()