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. |
From: <gea...@us...> - 2009-05-03 15:24:54
|
Revision: 341 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=341&view=rev Author: gearmonkey Date: 2009-05-03 15:24:42 +0000 (Sun, 03 May 2009) Log Message: ----------- added full song as node graph. Audio weigts of edges all set to -1 as place holder Modified Paths: -------------- graphRDF/branches/songsAsNodes/graphRDF.py Added Paths: ----------- graphRDF/branches/songsAsNodes/complexSongGraph.mlz Added: graphRDF/branches/songsAsNodes/complexSongGraph.mlz =================================================================== (Binary files differ) Property changes on: graphRDF/branches/songsAsNodes/complexSongGraph.mlz ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: graphRDF/branches/songsAsNodes/graphRDF.py =================================================================== --- graphRDF/branches/songsAsNodes/graphRDF.py 2009-04-30 17:26:17 UTC (rev 340) +++ graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-03 15:24:42 UTC (rev 341) @@ -373,21 +373,19 @@ # self.Pkin = Pk def main(argv=None): - plot = 0 - includeEnds = 0 + plot = False + includeEnds = False + folder = "person_seed_134901208" + media = '' if argv is None: argv = sys.argv try: try: - opts, args = getopt.getopt(argv[1:], "ho:vl:p", ["help", "output=", "logtofile=", "plot"]) + opts, args = getopt.getopt(argv[1:], "hf:m:o:vb:e:p", ["help", "folder=", "media=", "output=", "baseGraph=","expandedGraph=". "plot"]) except getopt.error, msg: raise Usage(msg) - loggingConfig = {"format":'%(asctime)s %(levelname)-8s %(message)s', - "datefmt":'%d.%m.%y %H:%M:%S', - "level": logging.DEBUG, - #"filename":logPath + "musicGrabber.log", - "filemode":"w"} + # option processing for option, value in opts: @@ -397,19 +395,18 @@ raise Usage(help_message) if option in ("-o", "--output"): output = value + if option in ("-f", "--folder"): + folder = value if option in ("-p", "--plot"): - plot = 1 - if option in ("-l", "--logtofile"): - logPath = value - loggingConfig = {"format":'%(asctime)s %(levelname)-8s %(message)s', - "datefmt":'%d.%m.%y %H:%M:%S', - "level": logging.DEBUG, - "filename":logPath + "musicGrabber.log", - "filemode":"w"} + plot = True + if option in ("-b", "--baseGraph"): + base = value + if option in ("-e", "--expandedGraph"): + expanded = value logging.basicConfig(**loggingConfig) - G = graph(includeEnds) + G = graph('') G.populate() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gea...@us...> - 2009-05-05 17:14:30
|
Revision: 342 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=342&view=rev Author: gearmonkey Date: 2009-05-05 17:14:14 +0000 (Tue, 05 May 2009) Log Message: ----------- got an edge dump but in the process discovered a flaw in my string splitting algorithm that needs fixing and such. error has been labeled but not fixed (maybe we need trak for mypyspace...) Modified Paths: -------------- graphRDF/branches/songsAsNodes/graphRDF.py Added Paths: ----------- graphRDF/branches/songsAsNodes/complexSongGraphEdgeDump.txt.zip Added: graphRDF/branches/songsAsNodes/complexSongGraphEdgeDump.txt.zip =================================================================== (Binary files differ) Property changes on: graphRDF/branches/songsAsNodes/complexSongGraphEdgeDump.txt.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: graphRDF/branches/songsAsNodes/graphRDF.py =================================================================== --- graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-03 15:24:42 UTC (rev 341) +++ graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-05 17:14:14 UTC (rev 342) @@ -320,11 +320,71 @@ idx += 1 debug("added " + str(idx-oldidx) + " edges\n--------") print "should have added all the edges now. Have a look:\n" + str(self.S) + + def dumpEdgeList(self, filename, graphToPrint=None, prefix=''): + """Writes out (text) the edgelist of the selected + graph (G by default) as tab delimited pairs + + source0\ttarget0 + source1\ttarget1 + ... + sourceN\ttargetN + + If the graph selected is G, each node is represented + as it's myspace artist ID. If the selected graph + is S the nodes will be printed as filenames (or more + strictly, the path beyond the common <prefix>, which is + nominally just the filename but not always if there + is a directory structure of some kind.) + + WARNING: If the filename given for output already + exists it will be overwritten without any further + notice, be aware...""" + if graphToPrint==None or graphToPrint == 'G': + graphToPrint = self.G + dumpReducedGraph = True + print "Dumping the artist as node edge list." + elif graphToPrint == 'S': + graphToPrint = self.S + dumpReducedGraph = False + print "Dumping the song as node edge list.\nFile path prefix has been set to: " + prefix + else: + print "the graph specified does not exist. please specifit either 'G' for artist-centric graph or 'S' for song-centric graph." + return + try: + fH = open(filename, 'w') + except Exception, err: + print("dumpEdgeList had trouble opening the file named " + filename + " for writing. Sort it out and try again...") + print str(err) + return + + try: + print "The edge list from this graph has these properties:" + print graphToPrint + print "will be dumped to " + filename + except Exception, err: + print("dumpEdgeList was unable to access the graph you requested. Sort it out and try again...") + print str(err) + return + for edge in graphToPrint.es: + if dumpReducedGraph: + sourceText = str(graphToPrint.vs[edge.source]['uid']) + targetText = str(graphToPrint.vs[edge.target]['uid']) + else: + sourceText = str(graphToPrint.vs[edge.source]['track'].lstrip(prefix)) + targetText = str(graphToPrint.vs[edge.target]['track'].lstrip(prefix)) + fH.write(sourceText + '\t' + targetText + '\n') + fH.flush() + + return + + + def getGenreAssortativity(self): '''get the assortivaty coeff for the igraph G - based on Newman 2002 "Mixing Patterns in Networks" @@ -375,13 +435,16 @@ def main(argv=None): plot = False includeEnds = False + base = None + expanded = None folder = "person_seed_134901208" media = '' + if argv is None: argv = sys.argv try: try: - opts, args = getopt.getopt(argv[1:], "hf:m:o:vb:e:p", ["help", "folder=", "media=", "output=", "baseGraph=","expandedGraph=". "plot"]) + opts, args = getopt.getopt(argv[1:], "hf:m:o:vb:e:p", ["help", "folder=", "media=", "output=", "baseGraph=","expandedGraph=", "plot"]) except getopt.error, msg: raise Usage(msg) @@ -397,6 +460,8 @@ output = value if option in ("-f", "--folder"): folder = value + if option in ("-m", "--media"): + media = value if option in ("-p", "--plot"): plot = True if option in ("-b", "--baseGraph"): @@ -406,7 +471,9 @@ logging.basicConfig(**loggingConfig) - G = graph('') + baseGraph = igraph.Graph(folder, media) + if base != None: + G G.populate() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gea...@us...> - 2009-05-09 07:10:43
|
Revision: 343 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=343&view=rev Author: gearmonkey Date: 2009-05-09 07:10:32 +0000 (Sat, 09 May 2009) Log Message: ----------- added a script to help repair any graphs made (principally mine) before I sorted out the bug in graphRDF that was fixed in the previous revision. Modified Paths: -------------- graphRDF/branches/songsAsNodes/graphRDF.py graphRDF/branches/songsAsNodes/hplot.py Added Paths: ----------- graphRDF/branches/songsAsNodes/repairSongGraph.py Modified: graphRDF/branches/songsAsNodes/graphRDF.py =================================================================== --- graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-05 17:14:14 UTC (rev 342) +++ graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-09 07:10:32 UTC (rev 343) @@ -14,6 +14,7 @@ import getopt import ftplib import mopy +import re from logging import log, error, warning, info, debug import logging from numpy import * @@ -24,6 +25,7 @@ this package interfaces w/ myrdfspace.com to analyze and plot graphs of myspace artists by kurt Jacobson 29/10/2007 (c) +highly modified by Ben Fields on and around 15/04/2009 dependencies: - igraph (http://cneurocvs.rmki.kfki.hu/igraph/) @@ -69,10 +71,14 @@ def string2List(listAsString): """A little helper function that takes in a string that was made by printing a list and breaks it up into a list of it composite parts. returns the list. - could do with some error checking, but seems to work with the track attribute and ought to work with the genres as well.""" - items = listAsString.split("', '") - items[0] = items[0].lstrip("['") + could do with some error checking, but seems to work with the track attribute and ought to work with the genres as well. + Now handles both kinds of quote via the glory of regular expressions.""" + sep = re.compile('[\'\"], [\'\"]') + items = sep.split(listAsString) + items[0] = items[0].lstrip("['")#could do this with a regEx also, but, eh... + items[0] = items[0].lstrip("[\"") items[-1] = items[-1].rstrip("']") + items[-1] = items[-1].rstrip("\"]") return items Modified: graphRDF/branches/songsAsNodes/hplot.py =================================================================== --- graphRDF/branches/songsAsNodes/hplot.py 2009-05-05 17:14:14 UTC (rev 342) +++ graphRDF/branches/songsAsNodes/hplot.py 2009-05-09 07:10:32 UTC (rev 343) @@ -1,7 +1,7 @@ #!/usr/bin/env python # encoding: utf-8 """ -untitled.py +hplot.py Created by Kurt Jacobson on 2008-11-11. Copyright (c) 2008 C4DM - Queen Mary U of London. All rights reserved. Added: graphRDF/branches/songsAsNodes/repairSongGraph.py =================================================================== --- graphRDF/branches/songsAsNodes/repairSongGraph.py (rev 0) +++ graphRDF/branches/songsAsNodes/repairSongGraph.py 2009-05-09 07:10:32 UTC (rev 343) @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# encoding: utf-8 +""" +repairSongGraph.py + +A script to clean up the song graph without rebuilding the whole thing to deal with the poor string parsing in the original implementation + +""" + +import sys +import os +from graphRDF import * + +Usage = """usage: repairSongGraph [original Artist graphmlz] [orignal Song graphmlz] [destination Song graphmlz]\n""" + +def main(argv=None): + vertIdxsToDelete = [] + uidsAffected = [] + vertIdxsAdded = [] + idx = 0 + + if argv is None: + argv = sys.argv + if not len(argv) == 4: + print Usage + return 104 + + + fixMe = graph('person_seed_134901208') + print "Loading original Artist graph from " + argv[1] + try: + fixMe.G = igraph.Graph.Load(argv[1], format='graphmlz') + except Exception, err: + print Usage + "encountered problems loading the original Artist graphmlz file." + return 105 + fixMe.isPopulated = True + print "Loading orginal Song graph from " + argv[2] + try: + fixMe.S = igraph.Graph.Load(argv[2], format='graphmlz') + except Exception, err: + print Usage + "encountered problems loading the original Song graphmlz file." + return 106 + print "will write out correceted graph to " + argv[3] + print "scrubbing Song Graph..." + + + idx = len(fixMe.S.vs) - 1 + for vert in fixMe.S.vs: + tracks = string2List(vert['track']) + if len(tracks) > 1: + print "Removing corrupt vertex from artist with uid " + vert['uid'] + " and breaking it into " + str(len(tracks)) + " correct vertices." + vertIdxsToDelete.append(vert.index) + uidsAffected.append(vert['uid']) + fixMe.S.add_vertices(len(tracks)) + for track in tracks: + idx +=1 + fixMe.S.vs[idx]['track'] = track + fixMe.S.vs[idx]['uid'] = vert['uid'] + vertIdxsAdded.append(idx) + print "found " + str(len(vertIdxsToDelete)) + " vertices to delete.\nAdding " + str(len(vertIdxsAdded)) + " repaired vertices." + + addedVertSeq = igraph.VertexSeq(fixMe.S, vertIdxsAdded) + toDeleteVertSeq = igraph.VertexSeq(fixMe.S, vertIdxsToDelete) + artistVertsOfInterest = fixMe.G.vs.select(uid_in=uidsAffected) + sourcesDealtWith = [] + targetsDealtWith = [] + idx = len(fixMe.S.es) - 1 + print "dealing with " + str(len(artistVertsOfInterest)) + "nodes in total" + for i,vert in enumerate(artistVertsOfInterest): + for index, edgeIdx in enumerate(fixMe.G.adjacent(vert.index, 'all')): + edge = fixMe.G.es[edgeIdx] + sources = fixMe.S.vs.select(uid=fixMe.G.vs[edge.source]['uid']) + targets = fixMe.S.vs.select(uid=fixMe.G.vs[edge.target]['uid']) + #print "Expanding edge " + str(edgeIdx) + " to " + str(len(sources) * len(targets)) + " edges." + oldidx = idx + for source in sources: + if not source.index in sourcesDealtWith: + sourcesDealtWith.append(source.index) + for target in targets: + if not target.index in targetsDealtWith: + targetsDealtWith.append(target.index) + fixMe.S.add_edges((source.index,target.index)) + idx += 1 + fixMe.S.es[idx]['audioWeight'] = -1 + + #print "added " + str(idx-oldidx) + " edges\n--------" + print str(len(artistVertsOfInterest) - i - 1) + " nodes left to deal with" + print "should have added all the edges now. Have a look:\n" + str(fixMe.S) + "\nRemoving old corrupt nodes and saving. Saving expanding graph in outputfile dumpedgraph.mlz in case something goes wrong." + fixMe.S.write("dumpedgraph.mlz", format="graphmlz") + + cleanGraph = fixMe.S.delete_vertices(vertIdxsToDelete) + + print "overwriting " + argv[3] + " with corrected graph." + + cleanGraph.write(argv[3],format="graphmlz") + + return 0 + + + + +if __name__ == '__main__': + main() + Property changes on: graphRDF/branches/songsAsNodes/repairSongGraph.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gea...@us...> - 2009-05-18 14:57:28
|
Revision: 348 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=348&view=rev Author: gearmonkey Date: 2009-05-18 14:57:26 +0000 (Mon, 18 May 2009) Log Message: ----------- adjusted the formating of the edge dump slightly. Added a graph with some initial weights (~27k of 1.5M edges) the rest of the edges are weighted at the median of the edges with actual weight, so as to continue neutrality. I'm currently adjusting the way the track is specified in the 'track' attribute to have full paths to location on the GDS cluster and will update when that's finished. Modified Paths: -------------- graphRDF/branches/songsAsNodes/graphRDF.py Added Paths: ----------- graphRDF/branches/songsAsNodes/partiallyWeightedAdjustedSongGraph.graphmlz Modified: graphRDF/branches/songsAsNodes/graphRDF.py =================================================================== --- graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-17 15:34:06 UTC (rev 347) +++ graphRDF/branches/songsAsNodes/graphRDF.py 2009-05-18 14:57:26 UTC (rev 348) @@ -331,10 +331,10 @@ """Writes out (text) the edgelist of the selected graph (G by default) as tab delimited pairs - source0\ttarget0 - source1\ttarget1 + edgeNum\tsource0\ttarget0 + edgeNum\tsource1\ttarget1 ... - sourceN\ttargetN + edgeNum\tsourceN\ttargetN If the graph selected is G, each node is represented as it's myspace artist ID. If the selected graph @@ -381,7 +381,7 @@ else: sourceText = str(graphToPrint.vs[edge.source]['track'].lstrip(prefix)) targetText = str(graphToPrint.vs[edge.target]['track'].lstrip(prefix)) - fH.write(sourceText + '\t' + targetText + '\n') + fH.write(str(edge.index) + '\t' + sourceText + '\t' + targetText + '\n') fH.flush() return @@ -398,12 +398,6 @@ self.S_shortestpaths_unweighted = [[]]*len(self.S.vs) try: return self.S_shortestpaths_unweighted[src][dst] - # try: - # if not self.S_shortestpaths_unweighted[src][dst] == []: - # return self.S_shortestpaths_unweighted[src][dst] - # else: - # self.S_shortestpaths_unweighted[src] = self.S.get_shortest_paths(src) - # return self.S_shortestpaths_unweighted[src][dst] except IndexError: self.S_shortestpaths_unweighted[src] = self.S.get_shortest_paths(src) return self.S_shortestpaths_unweighted[src][dst] Added: graphRDF/branches/songsAsNodes/partiallyWeightedAdjustedSongGraph.graphmlz =================================================================== (Binary files differ) Property changes on: graphRDF/branches/songsAsNodes/partiallyWeightedAdjustedSongGraph.graphmlz ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gea...@us...> - 2009-05-27 21:20:03
|
Revision: 353 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=353&view=rev Author: gearmonkey Date: 2009-05-27 21:19:59 +0000 (Wed, 27 May 2009) Log Message: ----------- more auto-format detection added a new file with some common helper functions also a new executable that is designed to be the entry point for the backend of the radio player. At some point fairly soon the svn may need some restructuring. Modified Paths: -------------- graphRDF/branches/songsAsNodes/loadWeights.py Added Paths: ----------- graphRDF/branches/songsAsNodes/common.py graphRDF/branches/songsAsNodes/radioCore.py Added: graphRDF/branches/songsAsNodes/common.py =================================================================== --- graphRDF/branches/songsAsNodes/common.py (rev 0) +++ graphRDF/branches/songsAsNodes/common.py 2009-05-27 21:19:59 UTC (rev 353) @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# encoding: utf-8 +""" +common.py + +Some common functions to speed access for song graphs + +Created by Benjamin Fields on 2009-05-18. +Copyright (c) 2009 Goldsmiths University of London. All rights reserved. +""" + +import sys +import os +import os.path +import igraph +import graphRDF + +def getTrackList(graph, nodeList): + trackList = [] + for vert in nodeList: + trackList.append(graph.vs[vert]['track']) + return trackList + +def avgDelta(graph, nodeList): + delta = 0 + for idx, node in enumerate(nodeList[1:]): + delta += igraph.EdgeSeq(graph, [nodeList[idx], node])[0]['audioWeight'] + return delta/(len(nodeList)-1) + +def deltaList(graph, nodeList): + deltaList = [] + for idx, node in enumerate(nodeList[1:]): + deltaList.append(igraph.EdgeSeq(graph, [nodeList[idx], node])[0]['audioWeight']) + return deltaList + + + +def main(): + pass + + +if __name__ == '__main__': + main() + Modified: graphRDF/branches/songsAsNodes/loadWeights.py =================================================================== --- graphRDF/branches/songsAsNodes/loadWeights.py 2009-05-27 21:16:28 UTC (rev 352) +++ graphRDF/branches/songsAsNodes/loadWeights.py 2009-05-27 21:19:59 UTC (rev 353) @@ -104,7 +104,7 @@ typoOutHandle.write(str(idx) + " : typo : " + line) typoOutHandle.flush() typos += 1 - print >> sys.stderr, str(err) + "\n" + str(typos) + " typos found." + print >> sys.stderr, str(Exception) + " : " + str(err) + "\n" + str(typos) + " typos found." continue foundWeight += 1 Added: graphRDF/branches/songsAsNodes/radioCore.py =================================================================== --- graphRDF/branches/songsAsNodes/radioCore.py (rev 0) +++ graphRDF/branches/songsAsNodes/radioCore.py 2009-05-27 21:19:59 UTC (rev 353) @@ -0,0 +1,130 @@ +#!/usr/bin/env python +# encoding: utf-8 +""" +radioCore.py + +This is the entry point for the backend of + +Created by Benjamin Fields on 2009-05-21. +Copyright (c) 2009 Goldsmiths University of London. All rights reserved. +""" + +import sys +import getopt +import igraph +import graphRDF +from common import * + + +help_message = ''' +Core utility end point to the automatic ong selection and aggregation toolkit, built around mypyspace's graphRDF project. + +modes available: + help print this message and exit + + makePlaylist create a playlist for MP3Broadcaster. Args as follows: + + >radioCore.py makePlaylist [options] graph.graphmlz srcNode destNode outfile.playlist + + graph.graphmlz -- the graph that will be used + --note this may change to a pickled igraph to speed load time.-- + srcNode -- where the playlist will start, specified as a filename that exists in graph.graphmlz + destNode -- where the playlist will end, specified as a filename that exists in graph.graphmlz + outfile.playlist -- the full path where the playlist will be written. + + destFinder given various circumstances determine all possible destination nodes for a +''' + +playlistheader = """*PLAY-LIST* +# +# Created by radioCore.py +# +""" + +class Usage(Exception): + def __init__(self, msg): + self.msg = msg + + +def main(argv=None): + verbose = False + weighted = True + if argv is None: + argv = sys.argv + try: + if len(argv) < 2: + raise Usage(help_message) + if argv[1] == 'help': + raise Usage(help_message) + elif argv[1] == 'makePlaylist': + if len(argv) < 6: + raise Usage(help_message) + mode = 'makePlaylist' + graphFile = argv[-4] + srcNode = argv[-3] + destNode = argv[-2] + outfile = argv[-1] + if len(argv) > 6: + generalOpts = argv[2:-4] + else: + generalOpts = [] + elif argv[1] == 'destFinder': + mode = 'destFinder' + + else: + raise Usage("Poor mode specification. Run 'radioCore.py help' for more detailed usage.") + try: + opts, args = getopt.getopt(generalOpts, "hvw", ["help", "vebose", "unweighted"]) + except getopt.error, msg: + raise Usage(msg) + + # option processing + for option, value in opts: + if option == ("-v", "--verbose"): + verbose = True + if option in ("-h", "--help"): + raise Usage(help_message) + if option in ("-w", "--unweighted"): + weighted = False + + except Usage, err: + print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg) + print >> sys.stderr, "\t for help use --help" + return 2 + songGraph = graphRDF.graph('media_seed_134901208') + if mode == 'makePlaylist': + try: + outHandle = open(outfile, 'w') + if os.path.splitext(graphFile)[1] in ['.pkl', '.pickle']: + songGraph.S = igraph.Graph.Load(graphFile, format='pickle') + elif os.path.splitext(graphFile)[1] in ['.mlz', '.graphmlz']: + songGraph.S = igraph.Graph.Load(graphFile, format='graphmlz') + else: + songGraph.S = igraph.Graph.Load(graphFile) + except Exception, err: + print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err) + print >> sys.stderr, "\t for help use --help" + return 12 + if weighted and (len(songGraph.S.es.select(audioWeight_lt=0)) > 0): + print "radioCore.py: makePlaylist: WARNING: attempting to use weights, but some of the weights are negative. This may cause in some odd results." + try: + srcIDX = songGraph.S.vs.select(track=srcNode)[0].index + destIDX = songGraph.S.vs.select(track=destNode)[0].index + except Exception, err: + print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err) + print >> sys.stderr, "\t source or destination track path poorly specified, unable to dereference." + return 13 + outHandle.write(playlistheader) + if weighted: + trackList = getTrackList(songGraph.S, songGraph.shortestPath(srcIDX, destIDX, graph='S', weight='audioWeight')) + else: + trackList = getTrackList(songGraph.S, songGraph.shortestPath(srcIDX, destIDX, graph='S', weight=None)) + + for track in trackList: + outHandle.write('"'+track +'" 5\n') + outHandle.close() + + + +if __name__ == "__main__": + sys.exit(main()) Property changes on: graphRDF/branches/songsAsNodes/radioCore.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |