def formSemanticNet(self, problem): graph = Graph() inCard = {} pp = pprint.PrettyPrinter(indent=4) #populate all inCard[obects] = figure, before parsing other things # example inCards[b] = A for figName, figure in problem.figures.iteritems(): # print "Figure: "+figName # pp.pprint(figure.objects) for objName, obj in figure.objects.iteritems(): inCard[obj.name] = figure.name #pp.pprint(obj.attributes) # print "inCards are: " # pp.pprint(inCard) graph.inCard = inCard print "done building inCards. Initiating SemNet construction..." # now we can identify which attribute is an attribute and which attribute is a relation for figName, figure in problem.figures.iteritems(): # print "Parsing Figure: "+figName # print figure.visualFilename # pp.pprint(figure.objects) card = Card(figure.name) for objName, obj in figure.objects.iteritems(): properties = {} properties['inCard'] = figure.name # add the additional property to identify the parent figure relations = {} #clientForMigration.php #print "Object attributes:" #pprint.pprint(obj.attributes) for attrib, val in obj.attributes.iteritems(): vals = val.split(",") isNode = True #print "Adding "+attrib+"==>"+val for v in vals: if v in inCard: # relations are saved in the format: relation['inside'] = 'b', # where inside is the relation and 'b; is the target node if attrib in relations: relations[attrib].append(v) else: relations[attrib] = [v] else: isNode = False break if not isNode: # properties are saved in the format: properties['filled'] = 'yes' properties[attrib] = val # got all relations and properties of the object. form the node now. graph.addNode(obj.name, relations, properties) card.addNode(graph.getNode(obj.name)) # end of for graph.addCard(card) return graph