comparison rdfpy/af-skos-vocabulary.py @ 18:d5012016bf64 tip

added rdfpy and rdfonto directories
author nothing@tehis.net
date Tue, 23 Apr 2013 11:49:20 +0100
parents
children
comparison
equal deleted inserted replaced
17:2b5c292ad12f 18:d5012016bf64
1 import rdflib
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, Namespace
3
4 url = 'http://sovarr.c4dm.eecs.qmul.ac.uk/af/'
5 basedir = '/Users/alo/MusicOntology/features/'
6
7 afc = Namespace(url + 'features/')
8
9 af = Namespace(url+'ontology/1.0#')
10
11 vs = Namespace('http://www.w3.org/2003/06/sw-vocab-status/ns#')
12
13 afskos = Namespace(url + '/vocabulary/skos/1.0#')
14
15 skos = Namespace('http://www.w3.org/2004/02/skos/core#')
16
17 graph = Graph()
18 graph.bind('afsv', afskos)
19 graph.bind('skos', skos)
20 graph.bind('owl', OWL)
21 graph.bind('af', af)
22 graph.bind('vs', vs)
23
24 graph.add(( vs['term_status'], RDF.type, OWL.AnnotationProperty ))
25
26 source = Graph()
27 source.parse(basedir + 'af-catalogue.rdf')
28
29 for sub in source.subjects(RDF.type, OWL.Class):
30 name = sub.split('/')[-1]
31 id = name.replace("(", "").replace(")", "").replace("4Hz", "")
32 id = URIRef(afskos+id)
33 graph.add((id, RDF.type, skos['Concept']))
34 graph.add((id, RDFS.subClassOf, af['AudioFeature']))
35 graph.add((id, vs['term_status'], Literal("testing", lang="en") ))
36 count = sum(1 for _ in source.objects(sub, afc['feature']))
37 if count > 0:
38 labelAdded = False
39 for label in source.objects(sub, afc['feature']):
40 if not labelAdded:
41 graph.add(( id, skos['prefLabel'], Literal(label, lang="en") ))
42 #graph.add(( id, RDFS.label, Literal(label, lang="en") ))
43 graph.add(( id, skos['note'], Literal(label) ))
44 labelAdded = True
45 else:
46 if name.find("ADRess") == 0:
47 graph.add(( id, skos['prefLabel'], Literal(name + " (Azimuth Discrimination and Resynthesis)", lang="en") ))
48 #graph.add(( id, RDFS.label, Literal(name + " (Azimuth Discrimination and Resynthesis)", lang="en") ))
49 graph.add(( id, skos['note'], Literal(name + " (Azimuth Discrimination and Resynthesis)") ))
50 else:
51 if name.find("Aim") == 0:
52 graph.add(( id, skos['prefLabel'], Literal(name + " (Auditory Image Model) ", lang="en") ))
53 #graph.add(( id, RDFS.label, Literal(name + " (Auditory Image Model) ", lang="en") ))
54 graph.add(( id, skos['note'], Literal(name + " (Auditory Image Model) ") ))
55 else:
56 graph.add(( id, skos['prefLabel'], Literal(name, lang="en")))
57 #graph.add(( id, RDFS.label, Literal(name, lang="en")))
58 graph.add(( id, skos['note'], Literal(name) ))
59
60 graph.serialize(basedir+'rdfonto/af-skos-vocabulary.rdf')
61 graph.serialize(basedir+'rdfonto/af-skos-vocabulary.n3', format="n3")
62