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