view 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
line wrap: on
line source
import rdflib
from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, Namespace

url = 'http://sovarr.c4dm.eecs.qmul.ac.uk/af/'
basedir = '/Users/alo/MusicOntology/features/'

afc = Namespace(url + 'features/')

af = Namespace(url+'ontology/1.0#')

vs = Namespace('http://www.w3.org/2003/06/sw-vocab-status/ns#')

afskos = Namespace(url + '/vocabulary/skos/1.0#')

skos = Namespace('http://www.w3.org/2004/02/skos/core#')

graph = Graph()
graph.bind('afsv', afskos)
graph.bind('skos', skos)
graph.bind('owl', OWL)
graph.bind('af', af)
graph.bind('vs', vs)

graph.add(( vs['term_status'], RDF.type, OWL.AnnotationProperty ))

source = Graph()
source.parse(basedir + 'af-catalogue.rdf')

for sub in source.subjects(RDF.type, OWL.Class):
    name = sub.split('/')[-1]
    id = name.replace("(", "").replace(")", "").replace("4Hz", "")
    id = URIRef(afskos+id)
    graph.add((id, RDF.type, skos['Concept']))
    graph.add((id, RDFS.subClassOf, af['AudioFeature']))
    graph.add((id, vs['term_status'], Literal("testing", lang="en") ))
    count = sum(1 for _ in source.objects(sub, afc['feature']))
    if count > 0:
        labelAdded = False
        for label in source.objects(sub, afc['feature']):
            if not labelAdded:
                graph.add(( id, skos['prefLabel'], Literal(label, lang="en") ))
                #graph.add(( id, RDFS.label, Literal(label, lang="en") ))
                graph.add(( id, skos['note'], Literal(label) ))
                labelAdded = True
    else:        
        if name.find("ADRess") == 0:
            graph.add(( id, skos['prefLabel'], Literal(name + " (Azimuth Discrimination and Resynthesis)", lang="en") ))
            #graph.add(( id, RDFS.label, Literal(name + " (Azimuth Discrimination and Resynthesis)", lang="en") ))
            graph.add(( id, skos['note'], Literal(name + " (Azimuth Discrimination and Resynthesis)") ))
        else:
            if name.find("Aim") == 0:
                graph.add(( id, skos['prefLabel'], Literal(name + " (Auditory Image Model) ", lang="en") ))
                #graph.add(( id, RDFS.label, Literal(name + " (Auditory Image Model) ", lang="en") ))
                graph.add(( id, skos['note'], Literal(name + " (Auditory Image Model) ") ))
            else:
                graph.add(( id, skos['prefLabel'], Literal(name, lang="en")))
                #graph.add(( id, RDFS.label, Literal(name, lang="en")))
                graph.add(( id, skos['note'], Literal(name) ))
    
graph.serialize(basedir+'rdfonto/af-skos-vocabulary.rdf')
graph.serialize(basedir+'rdfonto/af-skos-vocabulary.n3', format="n3")