nothing@0: import rdflib nothing@0: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, Namespace nothing@0: nothing@0: basedir = '/Users/alo/MusicOntology/features/' nothing@0: nothing@0: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@0: nothing@0: DC = Namespace(u"http://purl.org/dc/elements/1.1/") nothing@0: nothing@0: graph = Graph() nothing@0: graph.bind('af', URIRef(local)) nothing@0: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@0: graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(''), nothing@0: RDF.type, nothing@0: OWL.Ontology nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(''), nothing@0: DC['title'], nothing@0: Literal("Marsyas Ontology") nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(''), nothing@0: OWL.versionInfo, nothing@0: Literal("Version 0.1") nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(''), nothing@0: DC['description'], nothing@0: Literal("This is an ontology derived from Marsyas feature extraction tools for the Audio Features engineering process") nothing@0: )) nothing@0: nothing@0: nothing@0: source = Graph() nothing@0: source.parse(basedir+'rdfonto/af-Marsyas.n3', format='n3') nothing@0: nothing@0: categories = [] nothing@0: nothing@0: for su, ob in source.subject_objects(URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): nothing@0: if not ob in categories: nothing@0: categories.append(ob) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local+'Analysis'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: nothing@0: for category in categories: nothing@0: graph.add(( nothing@0: URIRef(local+category), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local+category), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local+'Analysis'), nothing@0: )) nothing@0: nothing@0: for su in source.subjects(RDF.type, RDFS.Resource): nothing@0: idref = URIRef(local+su.split('/')[-1]) nothing@15: # graph.add(( nothing@15: # idref, nothing@15: # RDF.type, nothing@15: # OWL.Class nothing@15: # )) nothing@15: nothing@0: graph.add(( nothing@0: idref, nothing@0: RDF.type, nothing@15: URIRef(local+"AudioFeature") nothing@0: )) nothing@0: nothing@0: count = sum(1 for _ in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type'))) nothing@0: nothing@0: if count > 0: nothing@0: for ob in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): nothing@0: graph.add(( nothing@0: idref, nothing@0: RDFS.subClassOf, nothing@0: URIRef(local+ob) nothing@0: )) nothing@0: else: nothing@0: graph.add(( nothing@0: idref, nothing@0: RDFS.subClassOf, nothing@0: URIRef(local+'Analysis'), nothing@0: )) nothing@0: nothing@0: for ob in source.objects(su,URIRef('http://purl.org/dc/elements/1.1/description')): nothing@0: graph.add(( nothing@0: idref, nothing@0: URIRef('http://purl.org/dc/elements/1.1/description'), nothing@0: ob nothing@0: )) nothing@0: nothing@0: graph.serialize(basedir + 'rdfonto/Marsyas-onto.rdf') nothing@0: graph.serialize(basedir + 'rdfonto/Marsyas-onto.n3', format='n3')