nothing@0: import rdflib, os, fnmatch, urllib2 nothing@15: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, XSD, Namespace, BNode nothing@15: from InfixOwl.InfixOwl import * nothing@0: from xml.dom.minidom import parseString nothing@0: nothing@15: def addProperty(graph, propID, type, range, domain, label, comment): nothing@15: propURI = URIRef(local + propID) nothing@15: graph.add(( nothing@15: propURI, nothing@15: RDF.type, nothing@15: OWL.ObjectProperty nothing@15: )) nothing@15: graph.add(( nothing@15: propURI, nothing@15: RDFS.range, nothing@15: range nothing@15: )) nothing@15: graph.add(( nothing@15: propURI, nothing@15: RDFS.domain, nothing@15: domain nothing@15: )) nothing@15: graph.add(( nothing@15: propURI, nothing@15: VS['term_status'], nothing@15: Literal("testing") nothing@15: )) nothing@15: graph.add(( nothing@15: propURI, nothing@15: RDFS.label, nothing@15: Literal(label) nothing@15: )) nothing@15: graph.add(( nothing@15: propURI, nothing@15: RDFS.comment, nothing@15: Literal(comment) nothing@15: )) nothing@15: nothing@15: nothing@0: names = [line.strip() for line in open('pdfextract/names.txt')] nothing@0: cat = [line.strip() for line in open('pdfextract/categories.txt')] nothing@15: sig = [line.strip() for line in open('pdfextract/sigv2.txt')] nothing@0: nothing@0: nothing@0: i = 0 nothing@0: nothing@0: order = [ nothing@0: "Zero Crossing Rate", nothing@0: "Linear Predictive Coding", nothing@0: "Mel-scale Frequency Cepstral Coefficients", nothing@0: "Auditory Filter Bank Temporal Envelopes", nothing@0: "Rate-scale-frequency Features", nothing@0: "Phase Space Features" nothing@0: ] nothing@0: nothing@0: domains = { nothing@0: "Zero Crossing Rate": 'temporal', nothing@0: "Linear Predictive Coding": 'frequency', nothing@0: "Mel-scale Frequency Cepstral Coefficients": 'cepstral', nothing@0: "Auditory Filter Bank Temporal Envelopes": 'modulation frequency', nothing@0: "Rate-scale-frequency Features": 'eigendomain', nothing@0: "Phase Space Features": 'phase space' nothing@0: } nothing@0: nothing@0: abbr = { nothing@0: "Zero Crossing Rate": "ZCR", nothing@0: "Mel-scale Frequency Cepstral Coefficients": "MFCC", nothing@0: "Linear Predictive Coding": "LPC", nothing@0: "Linear Prediction Cepstral Coefficients": "LPCC", nothing@0: "Zero crossing peak amplitudes": "ZCPA", nothing@0: "Line spectral frequencies": "LSF", nothing@0: "Short-time energy": "STE", nothing@0: "Amplitude descriptor": "AD", nothing@0: "Adaptive time frequency transform": "ATFT", nothing@0: "Daubechies Wavelet coefficient histogram": "DWCH", nothing@0: "Spectral Flux": "SF", nothing@0: "Group delay function": "GDF", nothing@0: "Modified group delay function": "MGDF", nothing@0: "Spectral centroid": "SC", nothing@0: "Subband spectral flux": "SSF", nothing@0: "Perceptual linear prediction": "PLP" nothing@0: } nothing@0: nothing@0: appdom = { nothing@0: 'ASR': "Speech Recognition", nothing@0: 'ESR': "Environmental Sound Recognition", nothing@0: 'MIR': "Music Information Retrieval", nothing@0: 'AS': "Audio Segmentation", nothing@0: 'FP': "Fingerprinting", nothing@0: 'VAR': "Several", nothing@0: 'EXC': "" nothing@0: } nothing@0: nothing@0: domain = "" nothing@0: domainIndex = 0 nothing@0: compdict = {} nothing@0: nothing@15: basedir = '/Users/alo/MusicOntology/features/' nothing@15: nothing@15: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@15: nothing@15: DC = Namespace(u"http://purl.org/dc/elements/1.1/") nothing@15: VS = Namespace(u"http://www.w3.org/2003/06/sw-vocab-status/ns#") nothing@15: nothing@15: graph = Graph() nothing@15: graph.bind('af', URIRef(local)) nothing@15: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@15: graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) nothing@15: graph.bind('xsd', URIRef('http://www.w3.org/2001/XMLSchema#')) nothing@15: graph.bind('vs', URIRef('http://www.w3.org/2003/06/sw-vocab-status/ns#')) nothing@15: nothing@15: nothing@15: ######################## nothing@15: ####### header ######### nothing@15: ######################## nothing@15: nothing@15: graph.add(( nothing@15: URIRef(''), nothing@15: RDF.type, nothing@15: OWL.Ontology nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: URIRef(''), nothing@15: DC['title'], nothing@15: Literal("Audio Features Base Ontology") nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: URIRef(''), nothing@15: OWL.versionInfo, nothing@15: Literal("Version 0.1") nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: URIRef(''), nothing@15: DC['description'], nothing@15: Literal("This is a base ontology for the Audio Features engineering process collected from literature") nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: VS['term_status'], nothing@15: RDF.type, nothing@15: OWL.AnnotationProperty nothing@15: )) nothing@15: nothing@15: nothing@15: nothing@15: ############################# nothing@15: ####### computation ######### nothing@15: ############################# nothing@15: nothing@15: nothing@0: graph.add(( nothing@0: URIRef(local + 'MathematicalOperation'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@15: graph.add(( nothing@15: URIRef(local + 'MathematicalOperation'), nothing@15: OWL.subClassOf, nothing@15: OWL.Thing nothing@15: )) nothing@15: nothing@15: bnode = BNode() nothing@15: Restriction(URIRef(local + "operation"),graph,cardinality=Literal(1, datatype=XSD.int),identifier=bnode) nothing@15: graph.add(( nothing@15: URIRef(local + 'MathematicalOperation'), nothing@15: RDFS.subClassOf, nothing@15: bnode nothing@15: )) nothing@15: nothing@15: bnode = BNode() nothing@15: Restriction(URIRef(local + "operation"),graph,allValuesFrom=URIRef(local + 'MathematicalOperation'),identifier=bnode) nothing@15: graph.add(( nothing@15: URIRef(local + 'MathematicalOperation'), nothing@15: RDFS.subClassOf, nothing@15: bnode nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: URIRef(local + "operation"), nothing@15: RDF.type, nothing@15: OWL.ObjectProperty nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + "operation"), nothing@15: RDF.type, nothing@15: OWL.FunctionalProperty nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + "operation"), nothing@15: RDFS.domain, nothing@15: URIRef(local + 'MathematicalOperation') nothing@15: )) nothing@15: nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'Filter'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'Filter'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'MathematicalOperation') nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'Transformation'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'Transformation'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'MathematicalOperation') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'Aggregation'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'Aggregation'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'MathematicalOperation') nothing@0: )) nothing@0: nothing@15: nothing@15: graph.add(( nothing@15: URIRef(local + "Computation"), nothing@15: RDF.type, nothing@15: OWL.Class nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: URIRef(local + "operation_sequence"), nothing@15: RDF.type, nothing@15: OWL.ObjectProperty nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + "operation_sequence"), nothing@15: RDF.type, nothing@15: OWL.FunctionalProperty nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + "operation_sequence"), nothing@15: RDFS.domain, nothing@15: URIRef(local + "Computation") nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + "operation_sequence"), nothing@15: RDFS.range, nothing@15: URIRef(local + 'MathematicalOperation') nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: URIRef(local + "next_operation"), nothing@15: RDF.type, nothing@15: OWL.ObjectProperty nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + "next_operation"), nothing@15: RDF.type, nothing@15: OWL.FunctionalProperty nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + "next_operation"), nothing@15: RDFS.domain, nothing@15: URIRef(local + "MathematicalOperation") nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + "next_operation"), nothing@15: RDFS.range, nothing@15: URIRef(local + "MathematicalOperation") nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: URIRef(local + 'LastOperation'), nothing@15: RDF.type, nothing@15: OWL.Class nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + 'LastOperation'), nothing@15: RDFS.subClassOf, nothing@15: URIRef(local + 'MathematicalOperation') nothing@15: )) nothing@15: nothing@15: bnode = BNode() nothing@15: Restriction(URIRef(local + "next_operation"),graph,maxCardinality=Literal(0, datatype=XSD.int),identifier=bnode) nothing@15: graph.add(( nothing@15: URIRef(local + 'LastOperation'), nothing@15: RDFS.subClassOf, nothing@15: bnode nothing@15: )) nothing@15: nothing@15: graph.add(( nothing@15: URIRef(local + 'OptionalOperation'), nothing@15: RDF.type, nothing@15: OWL.Class nothing@15: )) nothing@15: graph.add(( nothing@15: URIRef(local + 'OptionalOperation'), nothing@15: RDFS.subClassOf, nothing@15: URIRef(local + 'MathematicalOperation') nothing@15: )) nothing@15: nothing@15: bnode = BNode() nothing@15: Restriction(URIRef(local + "operation"),graph,minCardinality=Literal(0, datatype=XSD.int),identifier=bnode) nothing@15: graph.add(( nothing@15: URIRef(local + 'OptionalOperation'), nothing@15: RDFS.subClassOf, nothing@15: bnode nothing@15: )) nothing@15: nothing@15: nothing@15: for filename in ['filters', 'trans']: nothing@15: compsuper = filename.replace('filters', 'Filter').replace('trans', 'Transformation') nothing@0: for line in [line.strip() for line in open(basedir + 'pdfextract/' + filename + '.txt')]: nothing@0: compname = line[2:] nothing@0: compidref = URIRef(local + compname.replace(' ', '').replace('(', '').replace(')', '').replace('-', '').replace(',', '')) nothing@0: graph.add(( nothing@0: compidref, nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: compidref, nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + compsuper) nothing@0: )) nothing@0: graph.add(( nothing@0: compidref, nothing@0: RDFS.label, nothing@0: Literal(compname) nothing@0: )) nothing@0: compdict[line[0]] = compidref nothing@0: nothing@15: nothing@15: for line in [line.strip() for line in open(basedir + 'pdfextract/aggrdet.txt')]: nothing@15: #pair = line.split('\t') nothing@15: compname = line.split('\t')[1] nothing@15: compidref = URIRef(local + compname.replace(' ', '')) nothing@15: graph.add(( nothing@15: compidref, nothing@15: RDF.type, nothing@15: OWL.Class nothing@15: )) nothing@15: graph.add(( nothing@15: compidref, nothing@15: RDFS.subClassOf, nothing@15: URIRef(local + "Aggregation") nothing@15: )) nothing@15: graph.add(( nothing@15: compidref, nothing@15: RDFS.label, nothing@15: Literal(compname) nothing@15: )) nothing@15: compdict[line.split('\t')[0]] = compidref nothing@15: nothing@15: nothing@15: #################################### nothing@15: ####### add feature, signal ######## nothing@15: #################################### nothing@15: nothing@15: graph.add(( nothing@15: URIRef(local + "AudioFeature"), nothing@15: RDF.type, nothing@15: OWL.Class nothing@15: )) nothing@15: nothing@0: graph.add(( nothing@0: URIRef(local + 'Signal'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'Feature'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'Feature'), nothing@0: OWL.subClassOf, nothing@0: URIRef(local + 'Signal'), nothing@0: )) nothing@0: nothing@15: nothing@15: nothing@15: ################################## nothing@15: ####### feature hierarchy ######## nothing@15: ################################## nothing@15: nothing@15: nothing@0: for dom in domains.values(): nothing@0: idref = URIRef(local + dom.capitalize().replace(' ', '') + 'Feature') nothing@0: graph.add(( nothing@0: idref, nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: idref, nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'Feature') nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'PerceptualFeature'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'PerceptualFeature'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'Feature') nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'FrequencyDomainPerceptualFeature'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'FrequencyDomainPerceptualFeature'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'FrequencyFeature') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'FrequencyDomainPerceptualFeature'), nothing@0: OWL.equivalentClass, nothing@0: URIRef(local + 'PerceptualFeature') nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'FrequencyDomainPhysicalFeature'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'FrequencyDomainPhysicalFeature'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'FrequencyFeature') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'FrequencyDomainPhysicalFeature'), nothing@0: OWL.equivalentClass, nothing@0: URIRef(local + 'PhysicalFeature') nothing@0: )) nothing@0: nothing@0: nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'PhysicalFeature'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'PhysicalFeature'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'Feature') nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(local + 'ParametrizedDimensions'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@15: URIRef(local + 'SemanticInterpretation'), nothing@15: RDF.type, nothing@15: OWL.Class nothing@15: )) nothing@15: nothing@15: ### Computational Complexity nothing@15: graph.add(( nothing@0: URIRef(local + 'ComputationalComplexity'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'LowComplexity'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'LowComplexity'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'ComputationalComplexity') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'MediumComplexity'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'MediumComplexity'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'ComputationalComplexity') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'HighComplexity'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'HighComplexity'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'ComputationalComplexity') nothing@0: )) nothing@0: nothing@15: nothing@15: #### Temporal scale nothing@0: graph.add(( nothing@0: URIRef(local + 'TemporalScale'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'IntraFrame'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'IntraFrame'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'TemporalScale') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'InterFrame'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'InterFrame'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'TemporalScale') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'Global'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(local + 'Global'), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'TemporalScale') nothing@0: )) nothing@0: nothing@0: nothing@15: ### Application domain nothing@0: graph.add(( nothing@0: URIRef(local + 'ApplicationDomain'), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: nothing@0: for key in appdom.keys(): nothing@0: if appdom[key] != "": nothing@0: idref = URIRef(local + appdom[key].replace(" ", "")) nothing@0: graph.add(( nothing@0: idref, nothing@0: URIRef(RDF.type), nothing@0: OWL.Class nothing@0: )) nothing@0: graph.add(( nothing@0: idref, nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + 'ApplicationDomain') nothing@0: )) nothing@0: nothing@0: nothing@0: nothing@15: ############################### nothing@15: ####### add properties ######## nothing@15: ############################### nothing@0: nothing@15: # property: application_domain nothing@15: addProperty( nothing@15: graph=graph, nothing@15: propID="application_domain", nothing@15: type=OWL.ObjectProperty, nothing@15: range=URIRef(local + 'ApplicationDomain'), nothing@15: domain=URIRef(local + "AudioFeature"), nothing@15: label="application_domain property", nothing@15: comment="application domain: mir, speech, environmental, etc." nothing@15: ) nothing@0: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "application_domain"),graph,someValuesFrom=URIRef(local + 'ApplicationDomain'),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@15: # property: semantic_interpretation nothing@15: addProperty( nothing@15: graph=graph, nothing@15: propID="semantic_interpretation", nothing@15: type=OWL.ObjectProperty, nothing@15: range=URIRef(local + 'SemanticInterpretation'), nothing@15: domain=URIRef(local + "AudioFeature"), nothing@15: label="semantic_interpretation property", nothing@15: comment="semantic interpretation: physical/perceptual" nothing@15: ) nothing@0: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "semantic_interpretation"),graph,allValuesFrom=URIRef(local + 'SemanticInterpretation'),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "semantic_interpretation"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@15: # property: computational_complexity nothing@15: addProperty( nothing@15: graph=graph, nothing@15: propID="computational_complexity", nothing@15: type=OWL.ObjectProperty, nothing@15: range=URIRef(local + 'ComputationalComplexity'), nothing@15: domain=URIRef(local + "AudioFeature"), nothing@15: label="computational_complexity property", nothing@15: comment="computational complexity: high/medium/low" nothing@15: ) nothing@0: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "computational_complexity"),graph,allValuesFrom=URIRef(local + 'ComputationalComplexity'),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "computational_complexity"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@15: # property: psychoacoustic_model nothing@15: addProperty( nothing@15: graph=graph, nothing@15: propID="psychoacoustic_model", nothing@15: type=OWL.ObjectProperty, nothing@15: range=XSD.Boolean, nothing@15: domain=URIRef(local + "AudioFeature"), nothing@15: label="psychoacoustic_model property", nothing@15: comment="psychoacoustic model: true/false" nothing@15: ) nothing@0: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "psychoacoustic_model"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@15: # property: temporal_scale nothing@15: addProperty( nothing@15: graph=graph, nothing@15: propID="temporal_scale", nothing@15: type=OWL.ObjectProperty, nothing@15: range=URIRef(local + 'TemporalScale'), nothing@15: domain=URIRef(local + "AudioFeature"), nothing@15: label="temporal_scale", nothing@15: comment="temporal scale: global, interframe, intraframe" nothing@15: ) nothing@0: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "temporal_scale"),graph,allValuesFrom=URIRef(local + 'TemporalScale'),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "temporal_scale"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@18: nothing@15: # property: dimensions nothing@15: addProperty( nothing@15: graph=graph, nothing@15: propID="dimensions", nothing@15: type=OWL.ObjectProperty, nothing@15: range=XSD.Integer, nothing@15: domain=URIRef(local + "AudioFeature"), nothing@15: label="dimensions property", nothing@15: comment="dimensions: an integer value" nothing@15: ) nothing@15: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "dimensions"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@15: # property: computation nothing@15: addProperty( nothing@15: graph=graph, nothing@15: propID="computation", nothing@15: type=OWL.ObjectProperty, nothing@15: range=URIRef(local + 'Computation'), nothing@15: domain=URIRef(local + "AudioFeature"), nothing@15: label="computation", nothing@15: comment="computation: a sequence of mathematical operations" nothing@15: ) nothing@15: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "computation"),graph,allValuesFrom=URIRef(local + 'Computation'),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@18: nothing@18: bnode = BNode() nothing@18: Restriction(URIRef(local + "computation"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode) nothing@18: graph.add(( nothing@18: URIRef(local + "AudioFeature"), nothing@18: RDFS.subClassOf, nothing@18: bnode nothing@18: )) nothing@15: nothing@15: ############################# nothing@15: ####### add features ######## nothing@15: ############################# nothing@15: nothing@0: for name in names: nothing@15: basename = name.replace(' ','').replace('-','').replace('4Hz', '') nothing@15: id = local + basename nothing@0: nothing@0: if name == order[domainIndex]: nothing@0: domain = domains[order[domainIndex]] nothing@0: domainIndex += 1 nothing@15: nothing@18: # graph.add(( nothing@18: # URIRef(id), nothing@18: # RDF.type, nothing@18: # URIRef(local + "AudioFeature") nothing@18: # )) nothing@18: nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: RDF.type, nothing@18: OWL.Class nothing@15: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: VS['term_status'], nothing@0: Literal("testing") nothing@0: )) nothing@15: nothing@0: if domain == "frequency": nothing@0: if word[1] == 'Y': nothing@0: temp = URIRef(local + 'FrequencyDomainPerceptualFeature') nothing@0: else: nothing@0: temp = URIRef(local + 'FrequencyDomainPhysicalFeature') nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: RDFS.subClassOf, nothing@0: URIRef(temp) nothing@0: )) nothing@0: nothing@0: else: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: RDFS.subClassOf, nothing@0: URIRef(local + domain.capitalize().replace(' ', '') + 'Feature') nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: #URIRef(local + 'feature'), nothing@0: RDFS.label, nothing@0: Literal(name.replace(' ','').replace('-','')) nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: RDFS.comment, nothing@0: Literal(name + " feature") nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: RDFS.label, nothing@0: Literal(name) nothing@0: )) nothing@0: nothing@0: word = cat[i].split(' ') nothing@0: nothing@0: temp = { nothing@0: 'I': URIRef(local+'IntraFrame'), nothing@0: 'X': URIRef(local+'InterFrame'), nothing@0: 'G': URIRef(local+'Global') nothing@0: }[word[0]] nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + 'temporal_scale'), nothing@0: temp nothing@0: )) nothing@0: nothing@0: nothing@0: if word[1] == 'Y': nothing@0: temp = URIRef(local + 'PerceptualFeature') nothing@0: else: nothing@0: temp = URIRef(local + 'PhysicalFeature') nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + "semantic_interpretation"), nothing@0: temp nothing@0: )) nothing@0: nothing@0: if word[2] == 'Y': nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + "psychoacoustic_model"), nothing@0: Literal(True) nothing@0: )) nothing@0: else: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + "psychoacoustic_model"), nothing@0: Literal(False) nothing@0: )) nothing@0: nothing@0: temp = { nothing@0: 'L': URIRef(local + 'LowComplexity'), nothing@0: 'M': URIRef(local + 'MediumComplexity'), nothing@0: 'H': URIRef(local + 'HighComplexity') nothing@0: }[word[3]] nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + "computational_complexity"), nothing@0: temp nothing@0: )) nothing@0: nothing@0: if word[4] == 'V': nothing@0: temp = URIRef(local + 'ParametrizedDimensions') nothing@0: else: nothing@0: temp = Literal(int(word[4])) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + 'dimensions'), nothing@0: temp nothing@0: )) nothing@0: nothing@0: temp = appdom[word[5]] nothing@0: nothing@0: if temp != '': nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + "application_domain"), nothing@0: URIRef(local + temp.replace(" ", "")) nothing@0: )) nothing@0: nothing@0: steps = sig[i].split(' ') nothing@15: nothing@15: compid = URIRef(local + basename + "_computation") nothing@15: nothing@15: graph.add((compid, RDF.type, URIRef(local+"Computation"))) nothing@0: nothing@15: nSteps = 0 nothing@15: nothing@15: for item in steps: nothing@15: if item != "(" and item != ")" and item != "[" and item != "]": nothing@15: nSteps = nSteps + 1 nothing@15: nothing@15: iIndex = -1 nothing@15: isOptional = False nothing@15: for cIndex in range(len(steps)): nothing@15: if steps[cIndex] == "(" or steps[cIndex] == ")" or steps[cIndex] == "[" or steps[cIndex] == "]": nothing@15: if steps[cIndex] == "(": nothing@15: isOptional = True nothing@15: else: nothing@15: iIndex = iIndex + 1 nothing@15: opid = URIRef(local + basename + '_operation_sequence_' + str(iIndex + 1)) nothing@15: isa = compdict[steps[cIndex]] nothing@15: graph.add(( nothing@15: opid, nothing@15: RDF.type, nothing@15: isa nothing@15: )) nothing@15: if iIndex == 0: nothing@15: graph.add(( nothing@15: compid, nothing@15: URIRef(local + 'operation_sequence'), nothing@15: opid nothing@15: )) nothing@15: if iIndex < nSteps-1: nothing@15: graph.add(( nothing@15: opid, nothing@15: URIRef(local + "next_operation"), nothing@15: URIRef(local + basename + '_operation_sequence_' + str(iIndex + 2)) nothing@15: )) nothing@15: else: nothing@15: graph.add(( nothing@15: opid, nothing@15: RDF.type, nothing@15: URIRef(local + 'LastOperation') nothing@15: )) nothing@15: if isOptional: nothing@15: graph.add(( nothing@15: opid, nothing@15: RDF.type, nothing@15: URIRef(local + 'OptionalOperation') nothing@15: )) nothing@15: isOptional = False nothing@15: nothing@15: graph.add(( URIRef(id), URIRef(local+'computation'), compid )) nothing@15: nothing@0: if name.find('MPEG-7') >= 0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + 'computedIn'), nothing@0: Literal('MPEG-7') nothing@0: )) nothing@0: #graph.add(( nothing@0: # URIRef(local+name.replace('MPEG-7', '').lower().lstrip().replace(' ', '_')+'_feature'), nothing@0: # RDF.type, nothing@0: # URIRef(id) nothing@0: #)) nothing@0: nothing@0: if name in abbr.keys(): nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local + 'abbreviation'), nothing@0: Literal(abbr[name]) nothing@0: )) nothing@0: nothing@0: nothing@0: i += 1 nothing@0: nothing@0: nothing@0: nothing@15: graph.serialize('/Users/alo/MusicOntology/features/rdfonto/baseOntoV2.n3', format='n3') nothing@15: graph.serialize('/Users/alo/MusicOntology/features/rdfonto/baseOntoV2.rdf')