Skip to content
Zack Maril edited this page Dec 5, 2012 · 10 revisions

While there are of course marked differences between a vertex and a edge, both objects implement com.Tinkerpop.blueprints.Element and other interfaces. This means there is a subset of functions in Hermes that apply to both edges and vertices. We've implemented this in Hermes in the hermes.element namespace. All of the following functions are immigrated into both hermes.edge and hermes.vertex, so they are available via either namespace. We've found in practice that it is easier to keep track of what is going on in the code if we only use hermes.vertex to act on vertices and likewise with edges and hermes.edge.

get-keys

get-keys returns a PersistentHashSet of all the keys for properties of an element.

(v/get-keys (v/create! {:a 1 :b 2 :c 3}))
;;#{:a :b :c}

get-id

get-id returns a unique identifier of the object it is called on. A vertex is identifed uniquely by a Long integer, while a edge is defined by a RelationIdentifier.

(v/get-id (v/create!))
;;24601
(e/get-id (e/connect! (v/create!) (v/create!) "test"))
#<RelationIdentifier 99:188:350>

get-property

get-property takes an element and a property keyword and returns the property of the object with that key.

(v/get-property (v/create! {:a 1}) :a)
;;1

set-property!

set-property! takes an element, a keyword and an object and sets the property of the element to that object.

(def vertex-in-memory (v/create! {:a 1}))
;;#'hermes.example/vertex-in-memory
(v/set-property! vertex-in-memory :b 1)
;;nil
(v/get-property vertex-in-memory :b)
;;1

prop-map

prop-map takes an element and returns a PersistentHashSet representing that object. Note that in addition to any properties the element might posses, the object also includes a :id keyword. TODO: Change this to :__id__

(v/prop-map (v/create! {:a 1 :b 3}))
;;{:id 324, :a 1, :b 3}
(v/prop-map (e/connect! (v/create!) (v/create!) "test" {:a 1 :b 2}))
;;{:id #<RelationIdentifier 173:336:350>, :a 1, :b 2}

set-properties!

set-properties! takes an element and a map and merges the values of the map into the properties of the element.

(def vertex-in-memory (v/create! {:a 1 :b 2}))
;;#'hermes.example/vertex-in-memory
(v/set-properties! vertex-in-memory {:b 3 :c 4})
;;#<PersistStandardTitanVertex v[288]>
(v/prop-map vertex-in-memory)
;;{:id 288, :a 1, :c 4, :b 3}

remove-property

remove-property takes an element and a keyword and removes that property from the element.

(def vertex-in-memory (v/create! {:a 1 :b 2}))
;;#'hermes.example/vertex-in-memory
(v/remove-property! vertex-in-memory :b)
;;#<PersistStandardTitanVertex v[288]>
(v/prop-map vertex-in-memory)
;;{:id 324, :a 1}