nothing@0: import rdflib, os, fnmatch, urllib2 nothing@0: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL nothing@0: nothing@0: ############# Marsyas ############### nothing@0: def removeNonAscii(s): return "".join(i for i in s if ord(i)<128) nothing@0: nothing@0: mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' nothing@0: nothing@0: graph = Graph() nothing@0: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@0: graph.bind('local', URIRef(local)) nothing@0: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@0: nothing@0: for name in os.listdir(mdir): nothing@0: if fnmatch.fnmatch(name, '*.h'): nothing@0: file = open(mdir + name) nothing@0: code = file.read() nothing@0: file.close() nothing@0: if ('\ingroup' in code) and ('Analysis' in code): nothing@0: if code.find('\class') == -1: nothing@0: cl = name[:-2] nothing@0: else: nothing@0: cl = code[code.find('\class')+7:code.find('\n', code.find('\class')+7)] nothing@0: nothing@0: br = code[code.find('brief')+5:code.find('*/', code.find('brief')+5)] nothing@0: br = br.replace('\n', ' ') nothing@0: br = " ".join(br.split()) nothing@0: nothing@0: br = removeNonAscii(br) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(cl), nothing@0: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@0: URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(cl), nothing@0: URIRef('http://purl.org/dc/elements/1.1/description'), nothing@0: Literal(br) nothing@0: )) nothing@0: nothing@0: graph.serialize('/Users/alo/MusicOntology/features/rdfn3/af-Marsyas.n3', format='n3')