From: <gea...@us...> - 2009-04-30 17:26:18
|
Revision: 340 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=340&view=rev Author: gearmonkey Date: 2009-04-30 17:26:17 +0000 (Thu, 30 Apr 2009) Log Message: ----------- I now have a highly unoptimized function that expands the graph to be songwise. My back of the napkin calculation says it will take 6 - 8 hours to expand the graph, which is annoyingly long and I expect it could be improved, but this will work for now. Modified Paths: -------------- graphRDF/branches/songsAsNodes/graphRDF.py Modified: graphRDF/branches/songsAsNodes/graphRDF.py =================================================================== --- graphRDF/branches/songsAsNodes/graphRDF.py 2009-04-30 15:01:37 UTC (rev 339) +++ graphRDF/branches/songsAsNodes/graphRDF.py 2009-04-30 17:26:17 UTC (rev 340) @@ -287,11 +287,40 @@ # self.AG.add_edge(node, friend) def populateSongwise(self): - '''Create a graph S which uses artist relationships as egdes but seperates each song into seperate nodes, such that song to song distance can be used as edge weights, rather than artist to artist distance. The artist as node graph must be built first, via either populate() or populateLocal().''' + '''Create a graph S which uses artist relationships as egdes but seperates each song into seperate nodes, such that song to song distance can be used as edge weights, rather than artist to artist distance. The artist as node graph must be built first, via either populate() or populateLocal(). On initalisation weights are set to 1.''' if not self.isPopulated: error("Base graph has not been built. Run populate() or populateLocal() first.") return self.S = igraph.Graph(directed=True) + idx = 0 + artistLookup = {} + for v in self.G.vs: + tracks = string2List(v["tracks"]) + if len(tracks) == 0: + print "no songs found for artist #" + str(v["uid"]) + " moving on." + artistLookup[v["uid"]] = [] + for track in tracks: + self.S.add_vertices(1) + self.S.vs[idx]['uid'] = v['uid'] + self.S.vs[idx]['track'] = str(track) + artistLookup[v["uid"]] += [idx] + idx += 1 + print str(self.S) + print "hope that's all the songs, now it's time to add some edges.\n----------\n----------" + idx = 0 + for index, edge in enumerate(self.G.es): + sources = artistLookup[self.G.vs[edge.source]['uid']] + targets = artistLookup[self.G.vs[edge.target]['uid']] + debug("Expand edge " + str(index) + " to " + str(len(sources) * len(targets)) + " edges.") + oldidx = idx + for source in sources: + for target in targets: + self.S.add_edges((source,target)) + self.S.es[idx]['audioWeight'] = -1 + idx += 1 + debug("added " + str(idx-oldidx) + " edges\n--------") + print "should have added all the edges now. Have a look:\n" + str(self.S) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |