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