0

I have a class Node that I set as a property for a graph using graph-tool.

from graph_tool.all import *

class Node(object):
    def __init__(self, name, age):
        self.symbol = name
        self.named_entity = age


#create your graph object
g = Graph()

#add the property to vertex object
vprop = g.new_vertex_property("string") 

#add vertex 
v1 = g.add_vertex() #here you create a vertex
v2 = g.add_vertex() #here you create a vertex

#set the value to the vertex property
vx1 = Node("John", 15)
vx2 = Node("Sarah", 22)

v_prop[v1] = vx1
v_prop[v2] = vx2

#assign properties as a dic value
g.vertex_properties["node"]=vprop 

#add edge
g.add_edge(vertex_1,vertex_2) #add an edge 

# This does not work
find_match(g, "red")

How do I find vertices that match for equality on either the name or age fields for each node? The find_match() function seems to only work for the native types for PropertyMap.

Emut
  • 319
  • 4
  • 10
Francis
  • 137
  • 1
  • 10
  • You write a statement, or even a separate method, that expresses the compound relationship. Does that not work for you? – Prune Jun 15 '18 at 16:38
  • Is there an example I can find for this? The docs don't seem to show one. – Francis Jun 15 '18 at 16:44
  • This is essentially a one-line Boolean expression, embedded in whatever implementation vehicle you choose. Perhaps you need to search for a tutorial on implementing a custom `Node` method? You haven't given any context for us to give a solution. – Prune Jun 15 '18 at 16:50
  • @Prune edited for better context, thanks – Francis Jun 15 '18 at 17:05
  • Much better. Now, if I could find the docs that include find_match ... and maybe manage to install graph-tool to validate a solution ... then I could be of specific help. – Prune Jun 15 '18 at 17:26

0 Answers0