def lab2timelineRDF(infilename, outfilename, format="xml"): infile = open(infilename, 'r') lines = infile.readlines() mi = mopy.MusicInfo() homepage = mopy.foaf.Document("http://sourceforge.net/projects/motools") mi.add(homepage) program = mopy.foaf.Agent() program.name = "lab2timelineRDF.py" program.homepage = homepage mi.add(program) tl = RelativeTimeLine("tl") tl.label = "Timeline derived from "+infilename tl.maker = program mi.add(tl) intervalNum = 0 for line in lines: i = Interval("i"+str(intervalNum)) try: [start_s, end_s, label] = parseLabLine(line) i.beginsAtDuration = secondsToXSDDuration(start_s) i.endsAtDuration = secondsToXSDDuration(end_s) i.label = label i.onTimeLine = tl except Exception, e: raise Exception("Problem parsing input file at line "+str(intervalNum+1)+" !\n"+str(e)) mi.add(i) intervalNum+=1
def labchords2RDF(infilename, outfilename, format="xml", audiofilename=None, withdescriptions=False): if withdescriptions: commonchords = ConjunctiveGraph() commonchords.load("CommonChords.rdf") extrachords = ConjunctiveGraph() infile = open(infilename, 'r') lines = infile.readlines() mi = mopy.MusicInfo() homepage = mopy.foaf.Document("http://sourceforge.net/projects/motools") mi.add(homepage) program = mopy.foaf.Agent() program.name = "labchords2RDF.py" program.homepage = homepage mi.add(program) tl = RelativeTimeLine("#tl") tl.label = "Timeline derived from "+infilename tl.maker = program mi.add(tl) intervalNum = 0 for line in lines: i = Interval("#i"+str(intervalNum)) try: [start_s, end_s, label] = parseLabLine(line) i.beginsAtDuration = secondsToXSDDuration(start_s) i.endsAtDuration = secondsToXSDDuration(end_s) #i.label = "Interval containing "+label+" chord." i.onTimeLine = tl # Produce chord object for the label : chordURI = "http://purl.org/ontology/chord/symbol/"+label.replace("#","s").replace(",","%2C") if withdescriptions and \ len(list(commonchords.predicate_objects(URIRef(chordURI)))) == 0 and \ len(list(extrachords.predicate_objects(URIRef(chordURI)))) == 0: # Deref to grab chord info print "loading "+chordURI+"..." extrachords.load(chordURI) c = mopy.chord.Chord(chordURI) c_event = mopy.chord.ChordEvent("#ce"+str(intervalNum)) c_event.chord = c c_event.label = label c_event.time = i except Exception, e: raise Exception("Problem parsing input file at line "+str(intervalNum+1)+" !\n"+str(e)) mi.add(i) mi.add(c) mi.add(c_event) intervalNum+=1