Changeset 28351
- Timestamp:
- 2013-10-03T01:07:37+13:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/afrepo/trunk/src/src/AFRepo.GSDLEXT.class.php.in
r27983 r28351 58 58 59 59 60 p rotectedfunction remove_audio_files_prefix($full_filepath) {60 public function remove_audio_files_prefix($full_filepath) { 61 61 # echo "full filepath = " . $full_filepath . "\n"; 62 62 # echo "af prefix = " . $this->af_prefix . "\n"; … … 285 285 return null; 286 286 } 287 288 289 290 291 /** 292 * extraTriples 293 * Return an array of any extra implementation-specific triples should be 294 * added to the RDF given the ID of an audiofile 295 * 296 * This should be an array of triples in Turtle format without the trailing 297 * dot. (See generateRDF) 298 * It should return triples about all audiofiles of the same song rather 299 * than just the one with the ID given. 300 */ 301 protected function extraTriples($id) { 302 303 $extra_triples = array(); 304 305 306 // analyze the file, get some metadata 307 $structured_metadata = $this->getStructuredMetadata($id); 308 309 if ($structured_metadata !== false) { 310 311 } 312 313 // loop through the audiofiles for this tune 314 /* foreach ($ids as $key => $fileid) { */ 315 316 /* // some identifiers */ 317 /* $audiofile = "repo:$fileid"; */ 318 /* $digitalsignal = "repo:$fileid#DigitalSignal"; */ 319 320 /* // triples about the document */ 321 /* $triples[] = "{$audiofile}_ a foaf:Document; foaf:primaryTopic $audiofile"; */ 322 323 /* // this is a mo:AudioFile, which is a mo:MusicalItem */ 324 /* $triples[] = "$audiofile a mo:AudioFile"; */ 325 326 /* // this encodes a corresponding digital signal */ 327 /* $triples[] = "$audiofile mo:encodes $digitalsignal"; */ 328 329 /* // our digital signal is a mo:DigitalSignal (which is a subclass of */ 330 /* // mo:Signal, which is a subclass of mo:MusicalExpression) */ 331 /* $triples[] = "$digitalsignal a mo:DigitalSignal"; */ 332 333 /* // different logic depending whether this audiofile is the preferred */ 334 /* // one or not */ 335 /* if ($key == 0) { */ 336 /* // preferred -- if we have an MBID this Signal is derived from */ 337 /* // the original (that at Musicbrainz) */ 338 /* if (!is_null($mbid)) */ 339 /* $triples[] = "$digitalsignal mo:derived_from " . mbidToSignalURI($mbid); */ 340 /* // otherwise we don't assert that it derives from anything */ 341 /* } else { */ 342 /* // non-preferred -- we assert that it is derived from our */ 343 /* // preferred audiofile's Signal */ 344 /* $triples[] = "$digitalsignal mo:derived_from repo:" . $ids[0] . "#DigitalSignal"; */ 345 /* } */ 346 347 /* // analyze the file, get some metadata */ 348 /* $filemetadata = $this->getFileMetadata($fileid); */ 349 350 /* // mo:AudioFile metadata */ 351 /* if (isset($filemetadata["dataformat"])) */ 352 /* $triples[] = "$audiofile mo:encoding \"" . $filemetadata["dataformat"] */ 353 /* . (isset($filemetadata["bitrate"]) ? " @ " . $filemetadata["bitrate"] . "bps" : "") */ 354 /* . (isset($filemetadata["bitrate_mode"]) ? " " . $filemetadata["bitrate_mode"] : "") */ 355 /* . "\""; */ 356 357 /* // mo:DigitalSignal metadata */ 358 /* if (isset($filemetadata["playtime_seconds"])) */ 359 /* $triples[] = "$digitalsignal mo:time [ " */ 360 /* . "a time:Interval; " */ 361 /* . "time:seconds \"" . $filemetadata["playtime_seconds"] . "\"^^xsd:float " */ 362 /* . "]"; */ 363 /* if (isset($filemetadata["channels"])) */ 364 /* $triples[] = "$digitalsignal mo:channels \"" . $filemetadata["channels"] . "\"^^xsd:int"; */ 365 /* if (isset($filemetadata["sample_rate"])) */ 366 /* $triples[] = "$digitalsignal mo:sample_rate \"" . $filemetadata["sample_rate"] . "\"^^xsd:float"; */ 367 /* } */ 368 369 return $extra_triples; 370 371 372 } 373 374 375 /** 376 * getgetStructuredMetadata 377 * Return as a hashmap (keyed by algorithm the structured audio data 378 * from the "big crunch" 379 */ 380 public function getStructuredMetadata($id) { 381 382 $classifier = new StructuredAudioClassifier(); 383 384 if ($classifier->available() && $classifier->hasMetadata($id)) { 385 return $classifier->loadMetadata($id); 386 } 387 388 return false; 389 390 } 391 392 393 public function attributionToHtmlByAlgorithm() { 394 395 $classifier = new StructuredAudioClassifier(); 396 397 $full_dataset_path = getcwd() . "/" . "datasets"; 398 399 400 $ametadata = $classifier->getAttribution(); 401 402 $style = "<style>\n"; 403 $style .= " tr:nth-child(even) {background: #DDD}\n"; 404 $style .= " tr:nth-child(odd) {background: #EEE}\n"; 405 $style .= "</style>\n"; 406 407 $html_str = "$style\n<table>"; 408 409 foreach ($ametadata as $key => $value) { 410 411 $html_str .= "<tr>"; 412 413 $entry = $value; 414 $title = $entry["title"]; 415 $year = $entry["year"]; 416 $articleUrl = $entry["articleUrl"]; 417 $authorList = $entry["authorList"]; 418 $authors = $entry["authors"]; 419 420 $opt_linked_title = $title; 421 422 if ($articleUrl != false) { 423 $opt_linked_title = "<a href=\"$articleUrl\">$title</a>"; 424 } 425 426 $desc_entry = "<i>$opt_linked_title</i> ($year)<br />\n"; 427 428 foreach ($authorList as $author) { 429 $author_details = $authors[$author]; 430 $organizations = $author_details["organization"]; 431 $email = $author_details["email"]; 432 433 $desc_entry .= $author; 434 if ($email != false) { 435 $email = str_replace("@"," at ",$email); 436 $desc_entry .= " (<tt>$email</tt>)"; 437 } 438 439 $desc_entry .= "<br />\n"; 440 } 441 442 $tarfilesize = filesize("$full_dataset_path/$key.tar.gz"); 443 444 $download_key = "<a href=\"datasets/$key.tar.gz\">Download $key</a> ($tarfilesize bytes)"; 445 $html_str .= " <td>$download_key</td><td>$desc_entry</td>\n"; 446 447 $html_str .= "</tr>\n"; 448 449 } 450 $html_str .= "</table>"; 451 452 return $html_str; 453 454 } 455 456 457 public function attributionToHtmlByCollection() { 458 459 ## $classifier = new StructuredAudioClassifier(); 460 461 $full_dataset_path = getcwd() . "/" . "datasets"; 462 463 464 $cmetadata = array ( 465 "american" => "American", 466 "classical" => "Classical", 467 "coversong" => "Cover Songs", 468 "dram" => "Dram", 469 "ehmann" => "Ehmann", 470 "jamendo" => "Jameno", 471 "latin" => "Latin", 472 "magnatune" => "Magnatune", 473 "mazurkas" => "Mazurkas", 474 "uscrap" => "US Bargin Bin", 475 "uspop" => "US Pop" 476 ); 477 478 $style = "<style>\n"; 479 $style .= " tr:nth-child(even) {background: #DDD}\n"; 480 $style .= " tr:nth-child(odd) {background: #EEE}\n"; 481 $style .= "</style>\n"; 482 483 $html_str = "$style\n<table>"; 484 485 foreach ($cmetadata as $key => $value) { 486 487 $html_str .= "<tr>"; 488 489 $tarfilesize = filesize("$full_dataset_path/$key.tar.gz"); 490 491 $download_key = "<a href=\"datasets/$key.tar.gz\">Download $value</a> ($tarfilesize bytes)"; 492 $html_str .= " <td>$download_key</td>\n"; 493 494 $html_str .= "</tr>\n"; 495 496 } 497 $html_str .= "</table>"; 498 499 return $html_str; 500 501 } 502 503 287 504 } 288 505
Note:
See TracChangeset
for help on using the changeset viewer.