|
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.
|