From: <gea...@us...> - 2009-03-23 11:15:41
|
Revision: 336 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=336&view=rev Author: gearmonkey Date: 2009-03-23 11:15:35 +0000 (Mon, 23 Mar 2009) Log Message: ----------- the standard populate now has a property (is that the right word?) called tracks that contains a list of uris to songs associated with the current node. There is also a stub function that will eventually use this property to create a new graph with one node per track, but that's for later... Modified Paths: -------------- graphRDF/branches/songsAsNodes/audioWeights.py graphRDF/branches/songsAsNodes/graphRDF.py Modified: graphRDF/branches/songsAsNodes/audioWeights.py =================================================================== --- graphRDF/branches/songsAsNodes/audioWeights.py 2009-03-09 19:14:15 UTC (rev 335) +++ graphRDF/branches/songsAsNodes/audioWeights.py 2009-03-23 11:15:35 UTC (rev 336) @@ -38,7 +38,7 @@ lambda_max = 2500 def addAudioWeights(): - '''read in lambdsa and assign as audio label to each edge''' + '''read in lambdas and assign as audio label to each edge''' audioDic = {} audioZeros = 0 for line in lines: Modified: graphRDF/branches/songsAsNodes/graphRDF.py =================================================================== --- graphRDF/branches/songsAsNodes/graphRDF.py 2009-03-09 19:14:15 UTC (rev 335) +++ graphRDF/branches/songsAsNodes/graphRDF.py 2009-03-23 11:15:35 UTC (rev 336) @@ -69,15 +69,24 @@ class graph(object): '''G = graph(rdfFolder) -> returns a graph object encapsulating an igraph G includeEnds is a bool value to include nodes w/ no actual rdf file (ends) - rdfFolder is the "person" folder name on myrdfspace.com + rdfFolder is the "person" folder name on myrdfspace.com. If the graph + to be built is going to use songs as nodes based on the old split rdf files, + the mediaRDFFolder must point to the repository of rdf files containing + information about the songs. If it is not set and the songwise graph is + attempted, it will try to find the song references in the same rdf files as + the artist metadata (new style). *** NOTE includeEnds is disabled permanently ***''' - def __init__(self, rdfFolder): + def __init__(self, rdfFolder, mediaRdfFolder=''): self.includeEnds = 0 + self.isPopulated = False rdfFolder = rdfFolder.rstrip('/') rdfFolder = rdfFolder+'/' self.rdfFolder = rdfFolder + self.mediaRdfFolder = mediaRdfFolder setLogger() debug("creating graph object...") + if (mediaRdfFolder == ''): + debug("using old style seperate media rdf files.") self.G = igraph.Graph(directed=True) # self.AG = pg.AGraph() # set some default attribs @@ -87,7 +96,7 @@ # self.AG.node_attr['fontcolor'] = '#FFFFFF' # self.AG.node_attr['fontsize'] = '6.0' # self.AG.graph_attr['overlap'] = 'scale' - info("call populate() to build graph...") + print "call populate() or populateLocal() to build graph..." def populateLocal(self): '''use to populate from a local directory instead of myrdfspace.com''' @@ -127,7 +136,6 @@ pass print "genres for "+ str(node) + " are " +str(gkeys) self.G.vs[vDict[node]]['genres'] = gkeys - ## for the .dot file for graphviz ################ color by genre somehow??? # if gkeys: @@ -147,8 +155,8 @@ key = key[len(strip):] if not key == str(node.rstrip(".rdf")): friendList.append(key) + self.isPopulated = True - print friendList if self.includeEnds: for friend in friendList: @@ -183,7 +191,7 @@ idxE = 0 for v in vList: v = v.rstrip(".rdf") - print "*********** " + v + " *********** idx: " + str(idx) + #print "*********** " + v + " *********** idx: " + str(idx) # self.AG.add_node(v) self.G.add_vertices(1) self.G.vs[idx]['uid'] = v @@ -204,8 +212,28 @@ except: pass print "genres for "+ str(node) + " are " +str(gkeys) + self.G.vs[vDict[node]]['genres'] = gkeys + try: + trackList = [] + if (self.mediaRdfFolder != ''): + #attempt to fetch the corrisponding media RDF file, if the old split style has been declared. + mediaRDF = mopy.importRDFFile(os.path.join("http://myrdfspace.com/", self.mediaRdfFolder,str(node)+"media.rdf" )) + for track in mediaRDF.TrackIdx: + trackList.append(track) + debug("added " + track + " to list of tracks for artist # " + str(node)) + else: + #if the caller didn't specify a media RDF location assume new style combined rdf, so look for + #the track listings in the previously loaded rdf file. + for track in rdf.TrackIdx: + trackList.append(track) + debug("added " + track + " to list of tracks for artist # " + str(node)) + self.G.vs[vDict[node]]['tracks'] = trackList + except Exception, err: + error("something went wrong while trying to load the track listing for artist " + str(node) + "\nErrMsg: " + str(err)) + + ## for the .dot file for graphviz ################ color by genre somehow??? # if gkeys: @@ -226,7 +254,7 @@ if not key == str(node.rstrip(".rdf")): friendList.append(key) - + self.isPopulated = True print friendList if self.includeEnds: for friend in friendList: @@ -247,6 +275,17 @@ self.G.add_edges((vDict[node], vDict[friend])) # 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().''' + if not self.isPopulated: + error("Base graph has not been built. Run populate() or populateLocal() first.") + return + self.S = igraph.Graph(directed=True) + + + + + def getGenreAssortativity(self): '''get the assortivaty coeff for the igraph G - based on Newman 2002 "Mixing Patterns in Networks" THIS DOESNT WORK QUITE RIGHT - graphmeasures.py ''' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |