annotate rdfpy/writeBaseOnto.py @ 18:d5012016bf64 tip

added rdfpy and rdfonto directories
author nothing@tehis.net
date Tue, 23 Apr 2013 11:49:20 +0100
parents 53069717108c
children
rev   line source
nothing@0 1 import rdflib, os, fnmatch, urllib2
nothing@15 2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, XSD, Namespace, BNode
nothing@15 3 from InfixOwl.InfixOwl import *
nothing@0 4 from xml.dom.minidom import parseString
nothing@0 5
nothing@15 6 def addProperty(graph, propID, type, range, domain, label, comment):
nothing@15 7 propURI = URIRef(local + propID)
nothing@15 8 graph.add((
nothing@15 9 propURI,
nothing@15 10 RDF.type,
nothing@15 11 OWL.ObjectProperty
nothing@15 12 ))
nothing@15 13 graph.add((
nothing@15 14 propURI,
nothing@15 15 RDFS.range,
nothing@15 16 range
nothing@15 17 ))
nothing@15 18 graph.add((
nothing@15 19 propURI,
nothing@15 20 RDFS.domain,
nothing@15 21 domain
nothing@15 22 ))
nothing@15 23 graph.add((
nothing@15 24 propURI,
nothing@15 25 VS['term_status'],
nothing@15 26 Literal("testing")
nothing@15 27 ))
nothing@15 28 graph.add((
nothing@15 29 propURI,
nothing@15 30 RDFS.label,
nothing@15 31 Literal(label)
nothing@15 32 ))
nothing@15 33 graph.add((
nothing@15 34 propURI,
nothing@15 35 RDFS.comment,
nothing@15 36 Literal(comment)
nothing@15 37 ))
nothing@15 38
nothing@15 39
nothing@0 40 names = [line.strip() for line in open('pdfextract/names.txt')]
nothing@0 41 cat = [line.strip() for line in open('pdfextract/categories.txt')]
nothing@15 42 sig = [line.strip() for line in open('pdfextract/sigv2.txt')]
nothing@0 43
nothing@0 44
nothing@0 45 i = 0
nothing@0 46
nothing@0 47 order = [
nothing@0 48 "Zero Crossing Rate",
nothing@0 49 "Linear Predictive Coding",
nothing@0 50 "Mel-scale Frequency Cepstral Coefficients",
nothing@0 51 "Auditory Filter Bank Temporal Envelopes",
nothing@0 52 "Rate-scale-frequency Features",
nothing@0 53 "Phase Space Features"
nothing@0 54 ]
nothing@0 55
nothing@0 56 domains = {
nothing@0 57 "Zero Crossing Rate": 'temporal',
nothing@0 58 "Linear Predictive Coding": 'frequency',
nothing@0 59 "Mel-scale Frequency Cepstral Coefficients": 'cepstral',
nothing@0 60 "Auditory Filter Bank Temporal Envelopes": 'modulation frequency',
nothing@0 61 "Rate-scale-frequency Features": 'eigendomain',
nothing@0 62 "Phase Space Features": 'phase space'
nothing@0 63 }
nothing@0 64
nothing@0 65 abbr = {
nothing@0 66 "Zero Crossing Rate": "ZCR",
nothing@0 67 "Mel-scale Frequency Cepstral Coefficients": "MFCC",
nothing@0 68 "Linear Predictive Coding": "LPC",
nothing@0 69 "Linear Prediction Cepstral Coefficients": "LPCC",
nothing@0 70 "Zero crossing peak amplitudes": "ZCPA",
nothing@0 71 "Line spectral frequencies": "LSF",
nothing@0 72 "Short-time energy": "STE",
nothing@0 73 "Amplitude descriptor": "AD",
nothing@0 74 "Adaptive time frequency transform": "ATFT",
nothing@0 75 "Daubechies Wavelet coefficient histogram": "DWCH",
nothing@0 76 "Spectral Flux": "SF",
nothing@0 77 "Group delay function": "GDF",
nothing@0 78 "Modified group delay function": "MGDF",
nothing@0 79 "Spectral centroid": "SC",
nothing@0 80 "Subband spectral flux": "SSF",
nothing@0 81 "Perceptual linear prediction": "PLP"
nothing@0 82 }
nothing@0 83
nothing@0 84 appdom = {
nothing@0 85 'ASR': "Speech Recognition",
nothing@0 86 'ESR': "Environmental Sound Recognition",
nothing@0 87 'MIR': "Music Information Retrieval",
nothing@0 88 'AS': "Audio Segmentation",
nothing@0 89 'FP': "Fingerprinting",
nothing@0 90 'VAR': "Several",
nothing@0 91 'EXC': ""
nothing@0 92 }
nothing@0 93
nothing@0 94 domain = ""
nothing@0 95 domainIndex = 0
nothing@0 96 compdict = {}
nothing@0 97
nothing@15 98 basedir = '/Users/alo/MusicOntology/features/'
nothing@15 99
nothing@15 100 local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/'
nothing@15 101
nothing@15 102 DC = Namespace(u"http://purl.org/dc/elements/1.1/")
nothing@15 103 VS = Namespace(u"http://www.w3.org/2003/06/sw-vocab-status/ns#")
nothing@15 104
nothing@15 105 graph = Graph()
nothing@15 106 graph.bind('af', URIRef(local))
nothing@15 107 graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/'))
nothing@15 108 graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#'))
nothing@15 109 graph.bind('xsd', URIRef('http://www.w3.org/2001/XMLSchema#'))
nothing@15 110 graph.bind('vs', URIRef('http://www.w3.org/2003/06/sw-vocab-status/ns#'))
nothing@15 111
nothing@15 112
nothing@15 113 ########################
nothing@15 114 ####### header #########
nothing@15 115 ########################
nothing@15 116
nothing@15 117 graph.add((
nothing@15 118 URIRef(''),
nothing@15 119 RDF.type,
nothing@15 120 OWL.Ontology
nothing@15 121 ))
nothing@15 122
nothing@15 123 graph.add((
nothing@15 124 URIRef(''),
nothing@15 125 DC['title'],
nothing@15 126 Literal("Audio Features Base Ontology")
nothing@15 127 ))
nothing@15 128
nothing@15 129 graph.add((
nothing@15 130 URIRef(''),
nothing@15 131 OWL.versionInfo,
nothing@15 132 Literal("Version 0.1")
nothing@15 133 ))
nothing@15 134
nothing@15 135 graph.add((
nothing@15 136 URIRef(''),
nothing@15 137 DC['description'],
nothing@15 138 Literal("This is a base ontology for the Audio Features engineering process collected from literature")
nothing@15 139 ))
nothing@15 140
nothing@15 141 graph.add((
nothing@15 142 VS['term_status'],
nothing@15 143 RDF.type,
nothing@15 144 OWL.AnnotationProperty
nothing@15 145 ))
nothing@15 146
nothing@15 147
nothing@15 148
nothing@15 149 #############################
nothing@15 150 ####### computation #########
nothing@15 151 #############################
nothing@15 152
nothing@15 153
nothing@0 154 graph.add((
nothing@0 155 URIRef(local + 'MathematicalOperation'),
nothing@0 156 RDF.type,
nothing@0 157 OWL.Class
nothing@0 158 ))
nothing@15 159 graph.add((
nothing@15 160 URIRef(local + 'MathematicalOperation'),
nothing@15 161 OWL.subClassOf,
nothing@15 162 OWL.Thing
nothing@15 163 ))
nothing@15 164
nothing@15 165 bnode = BNode()
nothing@15 166 Restriction(URIRef(local + "operation"),graph,cardinality=Literal(1, datatype=XSD.int),identifier=bnode)
nothing@15 167 graph.add((
nothing@15 168 URIRef(local + 'MathematicalOperation'),
nothing@15 169 RDFS.subClassOf,
nothing@15 170 bnode
nothing@15 171 ))
nothing@15 172
nothing@15 173 bnode = BNode()
nothing@15 174 Restriction(URIRef(local + "operation"),graph,allValuesFrom=URIRef(local + 'MathematicalOperation'),identifier=bnode)
nothing@15 175 graph.add((
nothing@15 176 URIRef(local + 'MathematicalOperation'),
nothing@15 177 RDFS.subClassOf,
nothing@15 178 bnode
nothing@15 179 ))
nothing@15 180
nothing@15 181 graph.add((
nothing@15 182 URIRef(local + "operation"),
nothing@15 183 RDF.type,
nothing@15 184 OWL.ObjectProperty
nothing@15 185 ))
nothing@15 186 graph.add((
nothing@15 187 URIRef(local + "operation"),
nothing@15 188 RDF.type,
nothing@15 189 OWL.FunctionalProperty
nothing@15 190 ))
nothing@15 191 graph.add((
nothing@15 192 URIRef(local + "operation"),
nothing@15 193 RDFS.domain,
nothing@15 194 URIRef(local + 'MathematicalOperation')
nothing@15 195 ))
nothing@15 196
nothing@0 197
nothing@0 198 graph.add((
nothing@0 199 URIRef(local + 'Filter'),
nothing@0 200 RDF.type,
nothing@0 201 OWL.Class
nothing@0 202 ))
nothing@0 203 graph.add((
nothing@0 204 URIRef(local + 'Filter'),
nothing@0 205 RDFS.subClassOf,
nothing@0 206 URIRef(local + 'MathematicalOperation')
nothing@0 207 ))
nothing@0 208
nothing@0 209 graph.add((
nothing@0 210 URIRef(local + 'Transformation'),
nothing@0 211 RDF.type,
nothing@0 212 OWL.Class
nothing@0 213 ))
nothing@0 214 graph.add((
nothing@0 215 URIRef(local + 'Transformation'),
nothing@0 216 RDFS.subClassOf,
nothing@0 217 URIRef(local + 'MathematicalOperation')
nothing@0 218 ))
nothing@0 219 graph.add((
nothing@0 220 URIRef(local + 'Aggregation'),
nothing@0 221 RDF.type,
nothing@0 222 OWL.Class
nothing@0 223 ))
nothing@0 224 graph.add((
nothing@0 225 URIRef(local + 'Aggregation'),
nothing@0 226 RDFS.subClassOf,
nothing@0 227 URIRef(local + 'MathematicalOperation')
nothing@0 228 ))
nothing@0 229
nothing@15 230
nothing@15 231 graph.add((
nothing@15 232 URIRef(local + "Computation"),
nothing@15 233 RDF.type,
nothing@15 234 OWL.Class
nothing@15 235 ))
nothing@15 236
nothing@15 237 graph.add((
nothing@15 238 URIRef(local + "operation_sequence"),
nothing@15 239 RDF.type,
nothing@15 240 OWL.ObjectProperty
nothing@15 241 ))
nothing@15 242 graph.add((
nothing@15 243 URIRef(local + "operation_sequence"),
nothing@15 244 RDF.type,
nothing@15 245 OWL.FunctionalProperty
nothing@15 246 ))
nothing@15 247 graph.add((
nothing@15 248 URIRef(local + "operation_sequence"),
nothing@15 249 RDFS.domain,
nothing@15 250 URIRef(local + "Computation")
nothing@15 251 ))
nothing@15 252 graph.add((
nothing@15 253 URIRef(local + "operation_sequence"),
nothing@15 254 RDFS.range,
nothing@15 255 URIRef(local + 'MathematicalOperation')
nothing@15 256 ))
nothing@15 257
nothing@15 258 graph.add((
nothing@15 259 URIRef(local + "next_operation"),
nothing@15 260 RDF.type,
nothing@15 261 OWL.ObjectProperty
nothing@15 262 ))
nothing@15 263 graph.add((
nothing@15 264 URIRef(local + "next_operation"),
nothing@15 265 RDF.type,
nothing@15 266 OWL.FunctionalProperty
nothing@15 267 ))
nothing@15 268 graph.add((
nothing@15 269 URIRef(local + "next_operation"),
nothing@15 270 RDFS.domain,
nothing@15 271 URIRef(local + "MathematicalOperation")
nothing@15 272 ))
nothing@15 273 graph.add((
nothing@15 274 URIRef(local + "next_operation"),
nothing@15 275 RDFS.range,
nothing@15 276 URIRef(local + "MathematicalOperation")
nothing@15 277 ))
nothing@15 278
nothing@15 279 graph.add((
nothing@15 280 URIRef(local + 'LastOperation'),
nothing@15 281 RDF.type,
nothing@15 282 OWL.Class
nothing@15 283 ))
nothing@15 284 graph.add((
nothing@15 285 URIRef(local + 'LastOperation'),
nothing@15 286 RDFS.subClassOf,
nothing@15 287 URIRef(local + 'MathematicalOperation')
nothing@15 288 ))
nothing@15 289
nothing@15 290 bnode = BNode()
nothing@15 291 Restriction(URIRef(local + "next_operation"),graph,maxCardinality=Literal(0, datatype=XSD.int),identifier=bnode)
nothing@15 292 graph.add((
nothing@15 293 URIRef(local + 'LastOperation'),
nothing@15 294 RDFS.subClassOf,
nothing@15 295 bnode
nothing@15 296 ))
nothing@15 297
nothing@15 298 graph.add((
nothing@15 299 URIRef(local + 'OptionalOperation'),
nothing@15 300 RDF.type,
nothing@15 301 OWL.Class
nothing@15 302 ))
nothing@15 303 graph.add((
nothing@15 304 URIRef(local + 'OptionalOperation'),
nothing@15 305 RDFS.subClassOf,
nothing@15 306 URIRef(local + 'MathematicalOperation')
nothing@15 307 ))
nothing@15 308
nothing@15 309 bnode = BNode()
nothing@15 310 Restriction(URIRef(local + "operation"),graph,minCardinality=Literal(0, datatype=XSD.int),identifier=bnode)
nothing@15 311 graph.add((
nothing@15 312 URIRef(local + 'OptionalOperation'),
nothing@15 313 RDFS.subClassOf,
nothing@15 314 bnode
nothing@15 315 ))
nothing@15 316
nothing@15 317
nothing@15 318 for filename in ['filters', 'trans']:
nothing@15 319 compsuper = filename.replace('filters', 'Filter').replace('trans', 'Transformation')
nothing@0 320 for line in [line.strip() for line in open(basedir + 'pdfextract/' + filename + '.txt')]:
nothing@0 321 compname = line[2:]
nothing@0 322 compidref = URIRef(local + compname.replace(' ', '').replace('(', '').replace(')', '').replace('-', '').replace(',', ''))
nothing@0 323 graph.add((
nothing@0 324 compidref,
nothing@0 325 RDF.type,
nothing@0 326 OWL.Class
nothing@0 327 ))
nothing@0 328 graph.add((
nothing@0 329 compidref,
nothing@0 330 RDFS.subClassOf,
nothing@0 331 URIRef(local + compsuper)
nothing@0 332 ))
nothing@0 333 graph.add((
nothing@0 334 compidref,
nothing@0 335 RDFS.label,
nothing@0 336 Literal(compname)
nothing@0 337 ))
nothing@0 338 compdict[line[0]] = compidref
nothing@0 339
nothing@15 340
nothing@15 341 for line in [line.strip() for line in open(basedir + 'pdfextract/aggrdet.txt')]:
nothing@15 342 #pair = line.split('\t')
nothing@15 343 compname = line.split('\t')[1]
nothing@15 344 compidref = URIRef(local + compname.replace(' ', ''))
nothing@15 345 graph.add((
nothing@15 346 compidref,
nothing@15 347 RDF.type,
nothing@15 348 OWL.Class
nothing@15 349 ))
nothing@15 350 graph.add((
nothing@15 351 compidref,
nothing@15 352 RDFS.subClassOf,
nothing@15 353 URIRef(local + "Aggregation")
nothing@15 354 ))
nothing@15 355 graph.add((
nothing@15 356 compidref,
nothing@15 357 RDFS.label,
nothing@15 358 Literal(compname)
nothing@15 359 ))
nothing@15 360 compdict[line.split('\t')[0]] = compidref
nothing@15 361
nothing@15 362
nothing@15 363 ####################################
nothing@15 364 ####### add feature, signal ########
nothing@15 365 ####################################
nothing@15 366
nothing@15 367 graph.add((
nothing@15 368 URIRef(local + "AudioFeature"),
nothing@15 369 RDF.type,
nothing@15 370 OWL.Class
nothing@15 371 ))
nothing@15 372
nothing@0 373 graph.add((
nothing@0 374 URIRef(local + 'Signal'),
nothing@0 375 RDF.type,
nothing@0 376 OWL.Class
nothing@0 377 ))
nothing@0 378
nothing@0 379 graph.add((
nothing@0 380 URIRef(local + 'Feature'),
nothing@0 381 RDF.type,
nothing@0 382 OWL.Class
nothing@0 383 ))
nothing@0 384
nothing@0 385 graph.add((
nothing@0 386 URIRef(local + 'Feature'),
nothing@0 387 OWL.subClassOf,
nothing@0 388 URIRef(local + 'Signal'),
nothing@0 389 ))
nothing@0 390
nothing@15 391
nothing@15 392
nothing@15 393 ##################################
nothing@15 394 ####### feature hierarchy ########
nothing@15 395 ##################################
nothing@15 396
nothing@15 397
nothing@0 398 for dom in domains.values():
nothing@0 399 idref = URIRef(local + dom.capitalize().replace(' ', '') + 'Feature')
nothing@0 400 graph.add((
nothing@0 401 idref,
nothing@0 402 RDF.type,
nothing@0 403 OWL.Class
nothing@0 404 ))
nothing@0 405 graph.add((
nothing@0 406 idref,
nothing@0 407 RDFS.subClassOf,
nothing@0 408 URIRef(local + 'Feature')
nothing@0 409 ))
nothing@0 410
nothing@0 411 graph.add((
nothing@0 412 URIRef(local + 'PerceptualFeature'),
nothing@0 413 RDF.type,
nothing@0 414 OWL.Class
nothing@0 415 ))
nothing@0 416 graph.add((
nothing@0 417 URIRef(local + 'PerceptualFeature'),
nothing@0 418 RDFS.subClassOf,
nothing@0 419 URIRef(local + 'Feature')
nothing@0 420 ))
nothing@0 421
nothing@0 422 graph.add((
nothing@0 423 URIRef(local + 'FrequencyDomainPerceptualFeature'),
nothing@0 424 RDF.type,
nothing@0 425 OWL.Class
nothing@0 426 ))
nothing@0 427 graph.add((
nothing@0 428 URIRef(local + 'FrequencyDomainPerceptualFeature'),
nothing@0 429 RDFS.subClassOf,
nothing@0 430 URIRef(local + 'FrequencyFeature')
nothing@0 431 ))
nothing@0 432 graph.add((
nothing@0 433 URIRef(local + 'FrequencyDomainPerceptualFeature'),
nothing@0 434 OWL.equivalentClass,
nothing@0 435 URIRef(local + 'PerceptualFeature')
nothing@0 436 ))
nothing@0 437
nothing@0 438 graph.add((
nothing@0 439 URIRef(local + 'FrequencyDomainPhysicalFeature'),
nothing@0 440 RDF.type,
nothing@0 441 OWL.Class
nothing@0 442 ))
nothing@0 443 graph.add((
nothing@0 444 URIRef(local + 'FrequencyDomainPhysicalFeature'),
nothing@0 445 RDFS.subClassOf,
nothing@0 446 URIRef(local + 'FrequencyFeature')
nothing@0 447 ))
nothing@0 448 graph.add((
nothing@0 449 URIRef(local + 'FrequencyDomainPhysicalFeature'),
nothing@0 450 OWL.equivalentClass,
nothing@0 451 URIRef(local + 'PhysicalFeature')
nothing@0 452 ))
nothing@0 453
nothing@0 454
nothing@0 455
nothing@0 456 graph.add((
nothing@0 457 URIRef(local + 'PhysicalFeature'),
nothing@0 458 RDF.type,
nothing@0 459 OWL.Class
nothing@0 460 ))
nothing@0 461 graph.add((
nothing@0 462 URIRef(local + 'PhysicalFeature'),
nothing@0 463 RDFS.subClassOf,
nothing@0 464 URIRef(local + 'Feature')
nothing@0 465 ))
nothing@0 466
nothing@0 467 graph.add((
nothing@0 468 URIRef(local + 'ParametrizedDimensions'),
nothing@0 469 RDF.type,
nothing@0 470 OWL.Class
nothing@0 471 ))
nothing@0 472
nothing@0 473 graph.add((
nothing@15 474 URIRef(local + 'SemanticInterpretation'),
nothing@15 475 RDF.type,
nothing@15 476 OWL.Class
nothing@15 477 ))
nothing@15 478
nothing@15 479 ### Computational Complexity
nothing@15 480 graph.add((
nothing@0 481 URIRef(local + 'ComputationalComplexity'),
nothing@0 482 RDF.type,
nothing@0 483 OWL.Class
nothing@0 484 ))
nothing@0 485 graph.add((
nothing@0 486 URIRef(local + 'LowComplexity'),
nothing@0 487 RDF.type,
nothing@0 488 OWL.Class
nothing@0 489 ))
nothing@0 490 graph.add((
nothing@0 491 URIRef(local + 'LowComplexity'),
nothing@0 492 RDFS.subClassOf,
nothing@0 493 URIRef(local + 'ComputationalComplexity')
nothing@0 494 ))
nothing@0 495 graph.add((
nothing@0 496 URIRef(local + 'MediumComplexity'),
nothing@0 497 RDF.type,
nothing@0 498 OWL.Class
nothing@0 499 ))
nothing@0 500 graph.add((
nothing@0 501 URIRef(local + 'MediumComplexity'),
nothing@0 502 RDFS.subClassOf,
nothing@0 503 URIRef(local + 'ComputationalComplexity')
nothing@0 504 ))
nothing@0 505 graph.add((
nothing@0 506 URIRef(local + 'HighComplexity'),
nothing@0 507 RDF.type,
nothing@0 508 OWL.Class
nothing@0 509 ))
nothing@0 510 graph.add((
nothing@0 511 URIRef(local + 'HighComplexity'),
nothing@0 512 RDFS.subClassOf,
nothing@0 513 URIRef(local + 'ComputationalComplexity')
nothing@0 514 ))
nothing@0 515
nothing@15 516
nothing@15 517 #### Temporal scale
nothing@0 518 graph.add((
nothing@0 519 URIRef(local + 'TemporalScale'),
nothing@0 520 RDF.type,
nothing@0 521 OWL.Class
nothing@0 522 ))
nothing@0 523 graph.add((
nothing@0 524 URIRef(local + 'IntraFrame'),
nothing@0 525 RDF.type,
nothing@0 526 OWL.Class
nothing@0 527 ))
nothing@0 528 graph.add((
nothing@0 529 URIRef(local + 'IntraFrame'),
nothing@0 530 RDFS.subClassOf,
nothing@0 531 URIRef(local + 'TemporalScale')
nothing@0 532 ))
nothing@0 533 graph.add((
nothing@0 534 URIRef(local + 'InterFrame'),
nothing@0 535 RDF.type,
nothing@0 536 OWL.Class
nothing@0 537 ))
nothing@0 538 graph.add((
nothing@0 539 URIRef(local + 'InterFrame'),
nothing@0 540 RDFS.subClassOf,
nothing@0 541 URIRef(local + 'TemporalScale')
nothing@0 542 ))
nothing@0 543 graph.add((
nothing@0 544 URIRef(local + 'Global'),
nothing@0 545 RDF.type,
nothing@0 546 OWL.Class
nothing@0 547 ))
nothing@0 548 graph.add((
nothing@0 549 URIRef(local + 'Global'),
nothing@0 550 RDFS.subClassOf,
nothing@0 551 URIRef(local + 'TemporalScale')
nothing@0 552 ))
nothing@0 553
nothing@0 554
nothing@15 555 ### Application domain
nothing@0 556 graph.add((
nothing@0 557 URIRef(local + 'ApplicationDomain'),
nothing@0 558 RDF.type,
nothing@0 559 OWL.Class
nothing@0 560 ))
nothing@0 561
nothing@0 562 for key in appdom.keys():
nothing@0 563 if appdom[key] != "":
nothing@0 564 idref = URIRef(local + appdom[key].replace(" ", ""))
nothing@0 565 graph.add((
nothing@0 566 idref,
nothing@0 567 URIRef(RDF.type),
nothing@0 568 OWL.Class
nothing@0 569 ))
nothing@0 570 graph.add((
nothing@0 571 idref,
nothing@0 572 RDFS.subClassOf,
nothing@0 573 URIRef(local + 'ApplicationDomain')
nothing@0 574 ))
nothing@0 575
nothing@0 576
nothing@0 577
nothing@15 578 ###############################
nothing@15 579 ####### add properties ########
nothing@15 580 ###############################
nothing@0 581
nothing@15 582 # property: application_domain
nothing@15 583 addProperty(
nothing@15 584 graph=graph,
nothing@15 585 propID="application_domain",
nothing@15 586 type=OWL.ObjectProperty,
nothing@15 587 range=URIRef(local + 'ApplicationDomain'),
nothing@15 588 domain=URIRef(local + "AudioFeature"),
nothing@15 589 label="application_domain property",
nothing@15 590 comment="application domain: mir, speech, environmental, etc."
nothing@15 591 )
nothing@0 592
nothing@18 593 bnode = BNode()
nothing@18 594 Restriction(URIRef(local + "application_domain"),graph,someValuesFrom=URIRef(local + 'ApplicationDomain'),identifier=bnode)
nothing@18 595 graph.add((
nothing@18 596 URIRef(local + "AudioFeature"),
nothing@18 597 RDFS.subClassOf,
nothing@18 598 bnode
nothing@18 599 ))
nothing@18 600
nothing@15 601 # property: semantic_interpretation
nothing@15 602 addProperty(
nothing@15 603 graph=graph,
nothing@15 604 propID="semantic_interpretation",
nothing@15 605 type=OWL.ObjectProperty,
nothing@15 606 range=URIRef(local + 'SemanticInterpretation'),
nothing@15 607 domain=URIRef(local + "AudioFeature"),
nothing@15 608 label="semantic_interpretation property",
nothing@15 609 comment="semantic interpretation: physical/perceptual"
nothing@15 610 )
nothing@0 611
nothing@18 612 bnode = BNode()
nothing@18 613 Restriction(URIRef(local + "semantic_interpretation"),graph,allValuesFrom=URIRef(local + 'SemanticInterpretation'),identifier=bnode)
nothing@18 614 graph.add((
nothing@18 615 URIRef(local + "AudioFeature"),
nothing@18 616 RDFS.subClassOf,
nothing@18 617 bnode
nothing@18 618 ))
nothing@18 619
nothing@18 620 bnode = BNode()
nothing@18 621 Restriction(URIRef(local + "semantic_interpretation"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode)
nothing@18 622 graph.add((
nothing@18 623 URIRef(local + "AudioFeature"),
nothing@18 624 RDFS.subClassOf,
nothing@18 625 bnode
nothing@18 626 ))
nothing@18 627
nothing@15 628 # property: computational_complexity
nothing@15 629 addProperty(
nothing@15 630 graph=graph,
nothing@15 631 propID="computational_complexity",
nothing@15 632 type=OWL.ObjectProperty,
nothing@15 633 range=URIRef(local + 'ComputationalComplexity'),
nothing@15 634 domain=URIRef(local + "AudioFeature"),
nothing@15 635 label="computational_complexity property",
nothing@15 636 comment="computational complexity: high/medium/low"
nothing@15 637 )
nothing@0 638
nothing@18 639 bnode = BNode()
nothing@18 640 Restriction(URIRef(local + "computational_complexity"),graph,allValuesFrom=URIRef(local + 'ComputationalComplexity'),identifier=bnode)
nothing@18 641 graph.add((
nothing@18 642 URIRef(local + "AudioFeature"),
nothing@18 643 RDFS.subClassOf,
nothing@18 644 bnode
nothing@18 645 ))
nothing@18 646
nothing@18 647 bnode = BNode()
nothing@18 648 Restriction(URIRef(local + "computational_complexity"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode)
nothing@18 649 graph.add((
nothing@18 650 URIRef(local + "AudioFeature"),
nothing@18 651 RDFS.subClassOf,
nothing@18 652 bnode
nothing@18 653 ))
nothing@18 654
nothing@15 655 # property: psychoacoustic_model
nothing@15 656 addProperty(
nothing@15 657 graph=graph,
nothing@15 658 propID="psychoacoustic_model",
nothing@15 659 type=OWL.ObjectProperty,
nothing@15 660 range=XSD.Boolean,
nothing@15 661 domain=URIRef(local + "AudioFeature"),
nothing@15 662 label="psychoacoustic_model property",
nothing@15 663 comment="psychoacoustic model: true/false"
nothing@15 664 )
nothing@0 665
nothing@18 666 bnode = BNode()
nothing@18 667 Restriction(URIRef(local + "psychoacoustic_model"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode)
nothing@18 668 graph.add((
nothing@18 669 URIRef(local + "AudioFeature"),
nothing@18 670 RDFS.subClassOf,
nothing@18 671 bnode
nothing@18 672 ))
nothing@18 673
nothing@15 674 # property: temporal_scale
nothing@15 675 addProperty(
nothing@15 676 graph=graph,
nothing@15 677 propID="temporal_scale",
nothing@15 678 type=OWL.ObjectProperty,
nothing@15 679 range=URIRef(local + 'TemporalScale'),
nothing@15 680 domain=URIRef(local + "AudioFeature"),
nothing@15 681 label="temporal_scale",
nothing@15 682 comment="temporal scale: global, interframe, intraframe"
nothing@15 683 )
nothing@0 684
nothing@18 685 bnode = BNode()
nothing@18 686 Restriction(URIRef(local + "temporal_scale"),graph,allValuesFrom=URIRef(local + 'TemporalScale'),identifier=bnode)
nothing@18 687 graph.add((
nothing@18 688 URIRef(local + "AudioFeature"),
nothing@18 689 RDFS.subClassOf,
nothing@18 690 bnode
nothing@18 691 ))
nothing@18 692
nothing@18 693 bnode = BNode()
nothing@18 694 Restriction(URIRef(local + "temporal_scale"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode)
nothing@18 695 graph.add((
nothing@18 696 URIRef(local + "AudioFeature"),
nothing@18 697 RDFS.subClassOf,
nothing@18 698 bnode
nothing@18 699 ))
nothing@18 700
nothing@18 701
nothing@15 702 # property: dimensions
nothing@15 703 addProperty(
nothing@15 704 graph=graph,
nothing@15 705 propID="dimensions",
nothing@15 706 type=OWL.ObjectProperty,
nothing@15 707 range=XSD.Integer,
nothing@15 708 domain=URIRef(local + "AudioFeature"),
nothing@15 709 label="dimensions property",
nothing@15 710 comment="dimensions: an integer value"
nothing@15 711 )
nothing@15 712
nothing@18 713 bnode = BNode()
nothing@18 714 Restriction(URIRef(local + "dimensions"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode)
nothing@18 715 graph.add((
nothing@18 716 URIRef(local + "AudioFeature"),
nothing@18 717 RDFS.subClassOf,
nothing@18 718 bnode
nothing@18 719 ))
nothing@18 720
nothing@15 721 # property: computation
nothing@15 722 addProperty(
nothing@15 723 graph=graph,
nothing@15 724 propID="computation",
nothing@15 725 type=OWL.ObjectProperty,
nothing@15 726 range=URIRef(local + 'Computation'),
nothing@15 727 domain=URIRef(local + "AudioFeature"),
nothing@15 728 label="computation",
nothing@15 729 comment="computation: a sequence of mathematical operations"
nothing@15 730 )
nothing@15 731
nothing@18 732 bnode = BNode()
nothing@18 733 Restriction(URIRef(local + "computation"),graph,allValuesFrom=URIRef(local + 'Computation'),identifier=bnode)
nothing@18 734 graph.add((
nothing@18 735 URIRef(local + "AudioFeature"),
nothing@18 736 RDFS.subClassOf,
nothing@18 737 bnode
nothing@18 738 ))
nothing@18 739
nothing@18 740 bnode = BNode()
nothing@18 741 Restriction(URIRef(local + "computation"),graph,maxCardinality=Literal(1, datatype=XSD.int),identifier=bnode)
nothing@18 742 graph.add((
nothing@18 743 URIRef(local + "AudioFeature"),
nothing@18 744 RDFS.subClassOf,
nothing@18 745 bnode
nothing@18 746 ))
nothing@15 747
nothing@15 748 #############################
nothing@15 749 ####### add features ########
nothing@15 750 #############################
nothing@15 751
nothing@0 752 for name in names:
nothing@15 753 basename = name.replace(' ','').replace('-','').replace('4Hz', '')
nothing@15 754 id = local + basename
nothing@0 755
nothing@0 756 if name == order[domainIndex]:
nothing@0 757 domain = domains[order[domainIndex]]
nothing@0 758 domainIndex += 1
nothing@15 759
nothing@18 760 # graph.add((
nothing@18 761 # URIRef(id),
nothing@18 762 # RDF.type,
nothing@18 763 # URIRef(local + "AudioFeature")
nothing@18 764 # ))
nothing@18 765
nothing@18 766 graph.add((
nothing@18 767 URIRef(id),
nothing@18 768 RDF.type,
nothing@18 769 OWL.Class
nothing@15 770 ))
nothing@0 771
nothing@0 772 graph.add((
nothing@0 773 URIRef(id),
nothing@0 774 VS['term_status'],
nothing@0 775 Literal("testing")
nothing@0 776 ))
nothing@15 777
nothing@0 778 if domain == "frequency":
nothing@0 779 if word[1] == 'Y':
nothing@0 780 temp = URIRef(local + 'FrequencyDomainPerceptualFeature')
nothing@0 781 else:
nothing@0 782 temp = URIRef(local + 'FrequencyDomainPhysicalFeature')
nothing@0 783
nothing@0 784 graph.add((
nothing@0 785 URIRef(id),
nothing@0 786 RDFS.subClassOf,
nothing@0 787 URIRef(temp)
nothing@0 788 ))
nothing@0 789
nothing@0 790 else:
nothing@0 791 graph.add((
nothing@0 792 URIRef(id),
nothing@0 793 RDFS.subClassOf,
nothing@0 794 URIRef(local + domain.capitalize().replace(' ', '') + 'Feature')
nothing@0 795 ))
nothing@0 796
nothing@0 797 graph.add((
nothing@0 798 URIRef(id),
nothing@0 799 #URIRef(local + 'feature'),
nothing@0 800 RDFS.label,
nothing@0 801 Literal(name.replace(' ','').replace('-',''))
nothing@0 802 ))
nothing@0 803
nothing@0 804 graph.add((
nothing@0 805 URIRef(id),
nothing@0 806 RDFS.comment,
nothing@0 807 Literal(name + " feature")
nothing@0 808 ))
nothing@0 809
nothing@0 810 graph.add((
nothing@0 811 URIRef(id),
nothing@0 812 RDFS.label,
nothing@0 813 Literal(name)
nothing@0 814 ))
nothing@0 815
nothing@0 816 word = cat[i].split(' ')
nothing@0 817
nothing@0 818 temp = {
nothing@0 819 'I': URIRef(local+'IntraFrame'),
nothing@0 820 'X': URIRef(local+'InterFrame'),
nothing@0 821 'G': URIRef(local+'Global')
nothing@0 822 }[word[0]]
nothing@0 823
nothing@0 824 graph.add((
nothing@0 825 URIRef(id),
nothing@0 826 URIRef(local + 'temporal_scale'),
nothing@0 827 temp
nothing@0 828 ))
nothing@0 829
nothing@0 830
nothing@0 831 if word[1] == 'Y':
nothing@0 832 temp = URIRef(local + 'PerceptualFeature')
nothing@0 833 else:
nothing@0 834 temp = URIRef(local + 'PhysicalFeature')
nothing@0 835
nothing@0 836 graph.add((
nothing@0 837 URIRef(id),
nothing@0 838 URIRef(local + "semantic_interpretation"),
nothing@0 839 temp
nothing@0 840 ))
nothing@0 841
nothing@0 842 if word[2] == 'Y':
nothing@0 843 graph.add((
nothing@0 844 URIRef(id),
nothing@0 845 URIRef(local + "psychoacoustic_model"),
nothing@0 846 Literal(True)
nothing@0 847 ))
nothing@0 848 else:
nothing@0 849 graph.add((
nothing@0 850 URIRef(id),
nothing@0 851 URIRef(local + "psychoacoustic_model"),
nothing@0 852 Literal(False)
nothing@0 853 ))
nothing@0 854
nothing@0 855 temp = {
nothing@0 856 'L': URIRef(local + 'LowComplexity'),
nothing@0 857 'M': URIRef(local + 'MediumComplexity'),
nothing@0 858 'H': URIRef(local + 'HighComplexity')
nothing@0 859 }[word[3]]
nothing@0 860
nothing@0 861 graph.add((
nothing@0 862 URIRef(id),
nothing@0 863 URIRef(local + "computational_complexity"),
nothing@0 864 temp
nothing@0 865 ))
nothing@0 866
nothing@0 867 if word[4] == 'V':
nothing@0 868 temp = URIRef(local + 'ParametrizedDimensions')
nothing@0 869 else:
nothing@0 870 temp = Literal(int(word[4]))
nothing@0 871
nothing@0 872 graph.add((
nothing@0 873 URIRef(id),
nothing@0 874 URIRef(local + 'dimensions'),
nothing@0 875 temp
nothing@0 876 ))
nothing@0 877
nothing@0 878 temp = appdom[word[5]]
nothing@0 879
nothing@0 880 if temp != '':
nothing@0 881 graph.add((
nothing@0 882 URIRef(id),
nothing@0 883 URIRef(local + "application_domain"),
nothing@0 884 URIRef(local + temp.replace(" ", ""))
nothing@0 885 ))
nothing@0 886
nothing@0 887 steps = sig[i].split(' ')
nothing@15 888
nothing@15 889 compid = URIRef(local + basename + "_computation")
nothing@15 890
nothing@15 891 graph.add((compid, RDF.type, URIRef(local+"Computation")))
nothing@0 892
nothing@15 893 nSteps = 0
nothing@15 894
nothing@15 895 for item in steps:
nothing@15 896 if item != "(" and item != ")" and item != "[" and item != "]":
nothing@15 897 nSteps = nSteps + 1
nothing@15 898
nothing@15 899 iIndex = -1
nothing@15 900 isOptional = False
nothing@15 901 for cIndex in range(len(steps)):
nothing@15 902 if steps[cIndex] == "(" or steps[cIndex] == ")" or steps[cIndex] == "[" or steps[cIndex] == "]":
nothing@15 903 if steps[cIndex] == "(":
nothing@15 904 isOptional = True
nothing@15 905 else:
nothing@15 906 iIndex = iIndex + 1
nothing@15 907 opid = URIRef(local + basename + '_operation_sequence_' + str(iIndex + 1))
nothing@15 908 isa = compdict[steps[cIndex]]
nothing@15 909 graph.add((
nothing@15 910 opid,
nothing@15 911 RDF.type,
nothing@15 912 isa
nothing@15 913 ))
nothing@15 914 if iIndex == 0:
nothing@15 915 graph.add((
nothing@15 916 compid,
nothing@15 917 URIRef(local + 'operation_sequence'),
nothing@15 918 opid
nothing@15 919 ))
nothing@15 920 if iIndex < nSteps-1:
nothing@15 921 graph.add((
nothing@15 922 opid,
nothing@15 923 URIRef(local + "next_operation"),
nothing@15 924 URIRef(local + basename + '_operation_sequence_' + str(iIndex + 2))
nothing@15 925 ))
nothing@15 926 else:
nothing@15 927 graph.add((
nothing@15 928 opid,
nothing@15 929 RDF.type,
nothing@15 930 URIRef(local + 'LastOperation')
nothing@15 931 ))
nothing@15 932 if isOptional:
nothing@15 933 graph.add((
nothing@15 934 opid,
nothing@15 935 RDF.type,
nothing@15 936 URIRef(local + 'OptionalOperation')
nothing@15 937 ))
nothing@15 938 isOptional = False
nothing@15 939
nothing@15 940 graph.add(( URIRef(id), URIRef(local+'computation'), compid ))
nothing@15 941
nothing@0 942 if name.find('MPEG-7') >= 0:
nothing@0 943 graph.add((
nothing@0 944 URIRef(id),
nothing@0 945 URIRef(local + 'computedIn'),
nothing@0 946 Literal('MPEG-7')
nothing@0 947 ))
nothing@0 948 #graph.add((
nothing@0 949 # URIRef(local+name.replace('MPEG-7', '').lower().lstrip().replace(' ', '_')+'_feature'),
nothing@0 950 # RDF.type,
nothing@0 951 # URIRef(id)
nothing@0 952 #))
nothing@0 953
nothing@0 954 if name in abbr.keys():
nothing@0 955 graph.add((
nothing@0 956 URIRef(id),
nothing@0 957 URIRef(local + 'abbreviation'),
nothing@0 958 Literal(abbr[name])
nothing@0 959 ))
nothing@0 960
nothing@0 961
nothing@0 962 i += 1
nothing@0 963
nothing@0 964
nothing@0 965
nothing@15 966 graph.serialize('/Users/alo/MusicOntology/features/rdfonto/baseOntoV2.n3', format='n3')
nothing@15 967 graph.serialize('/Users/alo/MusicOntology/features/rdfonto/baseOntoV2.rdf')