Mercurial > hg > audio-features-catalogue
comparison rdfpy/writeMarsyas.py @ 0:62d2c72e4223
initial commit
author | nothing@tehis.net |
---|---|
date | Mon, 25 Feb 2013 14:40:54 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:62d2c72e4223 |
---|---|
1 import rdflib, os, fnmatch, urllib2 | |
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL | |
3 | |
4 ############# Marsyas ############### | |
5 def removeNonAscii(s): return "".join(i for i in s if ord(i)<128) | |
6 | |
7 mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' | |
8 | |
9 graph = Graph() | |
10 local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' | |
11 graph.bind('local', URIRef(local)) | |
12 graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) | |
13 | |
14 for name in os.listdir(mdir): | |
15 if fnmatch.fnmatch(name, '*.h'): | |
16 file = open(mdir + name) | |
17 code = file.read() | |
18 file.close() | |
19 if ('\ingroup' in code) and ('Analysis' in code): | |
20 if code.find('\class') == -1: | |
21 cl = name[:-2] | |
22 else: | |
23 cl = code[code.find('\class')+7:code.find('\n', code.find('\class')+7)] | |
24 | |
25 br = code[code.find('brief')+5:code.find('*/', code.find('brief')+5)] | |
26 br = br.replace('\n', ' ') | |
27 br = " ".join(br.split()) | |
28 | |
29 br = removeNonAscii(br) | |
30 | |
31 graph.add(( | |
32 URIRef(cl), | |
33 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), | |
34 URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') | |
35 )) | |
36 graph.add(( | |
37 URIRef(cl), | |
38 URIRef('http://purl.org/dc/elements/1.1/description'), | |
39 Literal(br) | |
40 )) | |
41 | |
42 graph.serialize('/Users/alo/MusicOntology/features/rdfn3/af-Marsyas.n3', format='n3') |