Mercurial > hg > audio-features-catalogue
view rdfpy/writeMarsyasOnto.py @ 0:62d2c72e4223
initial commit
author | nothing@tehis.net |
---|---|
date | Mon, 25 Feb 2013 14:40:54 +0000 |
parents | |
children | 53069717108c |
line wrap: on
line source
import rdflib from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, Namespace basedir = '/Users/alo/MusicOntology/features/' local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' DC = Namespace(u"http://purl.org/dc/elements/1.1/") graph = Graph() graph.bind('af', URIRef(local)) graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) graph.add(( URIRef(''), RDF.type, OWL.Ontology )) graph.add(( URIRef(''), DC['title'], Literal("Marsyas Ontology") )) graph.add(( URIRef(''), OWL.versionInfo, Literal("Version 0.1") )) graph.add(( URIRef(''), DC['description'], Literal("This is an ontology derived from Marsyas feature extraction tools for the Audio Features engineering process") )) source = Graph() source.parse(basedir+'rdfonto/af-Marsyas.n3', format='n3') categories = [] for su, ob in source.subject_objects(URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): if not ob in categories: categories.append(ob) graph.add(( URIRef(local+'Analysis'), RDF.type, OWL.Class )) for category in categories: graph.add(( URIRef(local+category), RDF.type, OWL.Class )) graph.add(( URIRef(local+category), RDFS.subClassOf, URIRef(local+'Analysis'), )) for su in source.subjects(RDF.type, RDFS.Resource): idref = URIRef(local+su.split('/')[-1]) graph.add(( idref, RDF.type, OWL.Class )) count = sum(1 for _ in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type'))) if count > 0: for ob in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): graph.add(( idref, RDFS.subClassOf, URIRef(local+ob) )) else: graph.add(( idref, RDFS.subClassOf, URIRef(local+'Analysis'), )) for ob in source.objects(su,URIRef('http://purl.org/dc/elements/1.1/description')): graph.add(( idref, URIRef('http://purl.org/dc/elements/1.1/description'), ob )) graph.serialize(basedir + 'rdfonto/Marsyas-onto.rdf') graph.serialize(basedir + 'rdfonto/Marsyas-onto.n3', format='n3')