From: <neb...@us...> - 2009-03-17 00:07:22
|
Revision: 1652 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1652&view=rev Author: nebelschwade Date: 2009-03-17 00:07:12 +0000 (Tue, 17 Mar 2009) Log Message: ----------- SparqlQueries over DL-Learner are now working (try testJamendo.php) Modified Paths: -------------- trunk/src/moosique.net/js/player.js Added Paths: ----------- trunk/src/moosique.net/php/DllearnerConnection.php trunk/src/moosique.net/php/SparqlQueryBuilder.php trunk/src/moosique.net/php/Utilities.php trunk/src/moosique.net/php/config.ini trunk/src/moosique.net/php/config.php trunk/src/moosique.net/php/requestHandler.php trunk/src/moosique.net/php/test.php trunk/src/moosique.net/php/testJamendo.php Property Changed: ---------------- trunk/src/moosique.net/ trunk/src/moosique.net/php/ Property changes on: trunk/src/moosique.net ___________________________________________________________________ Added: svn:ignore + .git Modified: trunk/src/moosique.net/js/player.js =================================================================== --- trunk/src/moosique.net/js/player.js 2009-03-16 10:23:18 UTC (rev 1651) +++ trunk/src/moosique.net/js/player.js 2009-03-17 00:07:12 UTC (rev 1652) @@ -39,6 +39,7 @@ 'html': 'X', 'events': { 'click': function() { + console.log('Deleted Song from PLaylist'); this.getParent().destroy(); // and refresh the playlist if clicked y.addTracks($('playlist'), '', true); @@ -164,86 +165,95 @@ * adding functionality for the player-GUI and the play, next etc. buttons */ addEventsToButtons: function() { + + var that = this; // the Play-Pause Button - this.playPause.addEvent('click', function() { + that.playPause.addEvent('click', function() { + console.log('Clicked Play/Pause'); // STOPPED: 0, PAUSED: 1, PLAYING: 2,BUFFERING: 5, ENDED: 7 - if (this.y.getPlayerState() == 0 || - this.y.getPlayerState() == 1 || - this.y.getPlayerState() == 7) { - this.y.play(); + if (that.y.getPlayerState() == 0 || + that.y.getPlayerState() == 1 || + that.y.getPlayerState() == 7) { + that.y.play(); } else { - this.y.pause(); + that.y.pause(); } - }.bind(this)); + }); // the previous-Track Button - this.prev.addEvent('click', function() { - this.y.previous(); - }.bind(this)); + that.prev.addEvent('click', function() { + console.log('Clicked Prev Button'); + that.y.previous(); + }); // the next-Track Button - this.next.addEvent('click', function() { - this.y.next(); - }.bind(this)); + that.next.addEvent('click', function() { + console.log('Clicked Next Button'); + that.y.next(); + }); // the Stop-Playing Button - this.stop.addEvent('click', function() { - this.playPause.setStyle('background-image', 'url(img/play.png)'); - this.nowPlayingHeader.set('text', 'Player stopped'); - this.nowPlayingTrack.set('text', '...'); - this.nowPlayingTime.set('text', '0:00 / 0:00'); - this.y.stop(); - }.bind(this)); + that.stop.addEvent('click', function() { + console.log('Clicked Stop Button'); + that.playPause.setStyle('background-image', 'url(img/play.png)'); + that.nowPlayingHeader.set('text', 'Player stopped'); + that.nowPlayingTrack.set('text', '...'); + that.nowPlayingTime.set('text', '0:00 / 0:00'); + that.y.stop(); + }); // Mute-Toggle-Switch - this.toggleMute.addEvent('click', function() { - if (this.y.getVolume() > 0) { - this.y.setVolume(0); - this.toggleMute.setStyle('text-decoration', 'line-through'); + that.toggleMute.addEvent('click', function() { + console.log('Clicked Mute Switch'); + if (that.y.getVolume() > 0) { + that.y.setVolume(0); + that.toggleMute.setStyle('text-decoration', 'line-through'); } else { - this.y.setVolume(1); - this.toggleMute.setStyle('text-decoration', 'none'); + that.y.setVolume(1); + that.toggleMute.setStyle('text-decoration', 'none'); } - }.bind(this)); + }); }, /** * Playlist related functions */ initPlaylist: function() { - this.togglePlaylist.addEvent('click', function() { - if (this.playlistContainer.getStyle('display') == 'none') { - this.playlistContainer.setStyle('display', 'block'); - this.togglePlaylist.setStyle('text-decoration', 'line-through'); + var that = this; + + that.togglePlaylist.addEvent('click', function() { + if (that.playlistContainer.getStyle('display') == 'none') { + that.playlistContainer.setStyle('display', 'block'); + that.togglePlaylist.setStyle('text-decoration', 'line-through'); } else { - this.playlistContainer.setStyle('display', 'none'); - this.togglePlaylist.setStyle('text-decoration', 'none'); + that.playlistContainer.setStyle('display', 'none'); + that.togglePlaylist.setStyle('text-decoration', 'none'); } - }.bind(this)); + }); // same for the closePlaylist-Button - this.closePlaylist.addEvent('click', function() { - this.playlistContainer.setStyle('display', 'none'); - this.togglePlaylist.setStyle('text-decoration', 'none'); - }.bind(this)); + that.closePlaylist.addEvent('click', function() { + that.playlistContainer.setStyle('display', 'none'); + that.togglePlaylist.setStyle('text-decoration', 'none'); + }); // nifty UI-Stuff, draggable and resizable - this.playlistContainer.makeDraggable({ + that.playlistContainer.makeDraggable({ handle: $('playlistHeader') }); - this.playlistContainer.makeResizable({ + that.playlistContainer.makeResizable({ handle: $('playlistFooter'), limit: {x: [300, 600], y: [150, 1000]} }); // opacity and intial hide - this.playlistContainer.setStyle('opacity', 0.9); // easier than css hacks + that.playlistContainer.setStyle('opacity', 0.9); // easier than css hacks // this.playlistContainer.setStyle('display', 'none'); // Make the playlist, samples and recommendations sortable - this.makeSortableLists($$('#playlist, #samples, #recommendations')); + that.makeSortableLists($$('#playlist, #samples, #recommendations')); // make links unclickable for recommendations and samples - this.makeLinksUnclickable($$('#recommendations li a, #samples li a')); + that.makeLinksUnclickable($$('#recommendations li a, #samples li a')); }, @@ -267,6 +277,9 @@ * @param {Object} lists An Element-Collection of lists (ol, ul) */ makeSortableLists: function(lists) { + + var that = this; + new Sortables(lists, { // indicate moving state by adding styles onStart: function(li) { @@ -280,9 +293,10 @@ if (li.getParent().get('id') == 'playlist') { li.getFirst('a').set('class', 'htrack'); // reload playlist - this.y.addTracks(this.playlist, '', true); + that.y.addTracks(that.playlist, '', true); + console.log('Updated Playlist'); } - }.bind(this) + } }); } Property changes on: trunk/src/moosique.net/php ___________________________________________________________________ Added: svn:ignore + def0.xsd def1.xsd main.wsdl Added: trunk/src/moosique.net/php/DllearnerConnection.php =================================================================== --- trunk/src/moosique.net/php/DllearnerConnection.php (rev 0) +++ trunk/src/moosique.net/php/DllearnerConnection.php 2009-03-17 00:07:12 UTC (rev 1652) @@ -0,0 +1,42 @@ +<?php + +/** + * + */ +class dllearnerConnection { + + private $conf; + private $client; + private $endpoint; + + function __construct($conf) { + $this->conf = $conf; + // we use jamendo as the default sparql-endpoint + $this->setEndpoint($this->conf->getUrl('jamendo')); + $this->connect(); + } + + private function connect() { + // connect to DL-Learner-Web-Service + $this->client = new SoapClient( + $this->conf->getUrl('wsdlLocal') + ); + } + + public function setEndpoint($endpoint) { + $this->endpoint = $endpoint; + } + + public function getEndpoint() { + return $this->endpoint; + } + + public function sparqlQuery($query) { + $id = $this->client->generateID(); + $knowledgeSourceId = $this->client->addKnowledgeSource($id, 'sparql', $this->endpoint); + $result = $this->client->sparqlQuery($id, $knowledgeSourceId, $query); + return $result; + } + +} +?> \ No newline at end of file Added: trunk/src/moosique.net/php/SparqlQueryBuilder.php =================================================================== --- trunk/src/moosique.net/php/SparqlQueryBuilder.php (rev 0) +++ trunk/src/moosique.net/php/SparqlQueryBuilder.php 2009-03-17 00:07:12 UTC (rev 1652) @@ -0,0 +1,109 @@ +<?php + +/** + * TODO, create a universal SparqlQueryBuilder for the different requests + * that can be made by a user or are made by the system for additional data + * like geodates, images, stuff... + */ +class SparqlQueryBuilder { + + private $config; + private $queryString; + + function __construct($config, $search, $typeOfSearch, $results) { + $this->config = $config; + $this->buildQuery($search, $typeOfSearch, $results); + } + + function getQuery() { + return $this->queryString; + } + + private function buildQuery($search, $typeOfSearch, $results) { + $this->queryString = ''; + $this->queryString .= $this->sparqlPrefixes(); + $this->queryString .= $this->selectStatement($typeOfSearch); + $this->queryString .= $this->whereStatement($search, $typeOfSearch, $results); + } + + + private function sparqlPrefixes() { + $prefixes = ''; + foreach($this->config->getPrefixes() as $prefix => $resource) { + $prefixes .= 'PREFIX ' . $prefix . ': ' . $resource . "\n"; + } + return $prefixes; + } + + private function selectStatement($typoOfSearch) { + $select = 'SELECT '; + switch($typoOfSearch) { + + case 'artist' : + $select .= '?artist ?album'; + break; + + case 'song': + $select .= '?artist ?album'; + break; + + case 'tag': + $select .= '?artist ?album'; + break; + } + return $select; + } + + private function whereStatement($search, $typeOfSearch, $wantedResults) { + $where = 'WHERE { ' . "\n"; + + switch($typeOfSearch) { + + case 'artist' : + $where .= ' + ?artist a mo:MusicArtist . + ?artist foaf:name "' . $search . '" . + ?artist foaf:homepage ?homepage . + ?record foaf:maker ?artist . + ?record dc:title ?title . + ?record mo:image ?image . + '; + break; + + case 'song' : + $where .= ' + ?track a mo:Track . + ?track dc:title "' . $search . '" . + ?track foaf:maker ?artist . + ?artist foaf:name ?name . + ?track dc:title ?tracksname . + ?record mo:track ?track . + ?record dc:title ?recordname . + '; + break; + + case 'tag' : + + break; + + // default case is artist + default : + $where .= ' + ?artist a mo:MusicArtist . + ?artist foaf:name "' . $search . '" . + ?artist foaf:homepage ?homepage . + ?record foaf:maker ?artist . + ?record dc:title ?title . + ?record mo:image ?image . + '; + break; + + } + $where .= ' }'; + return $where; + } + +} + + +?> \ No newline at end of file Added: trunk/src/moosique.net/php/Utilities.php =================================================================== --- trunk/src/moosique.net/php/Utilities.php (rev 0) +++ trunk/src/moosique.net/php/Utilities.php 2009-03-17 00:07:12 UTC (rev 1652) @@ -0,0 +1,167 @@ +<?php +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +// Pear HTTP_Request class required +include ('HTTP/Request.php'); + +/** + * Collection of static utility functions. + * + * @author Jens Lehmann + * @author Sebastian Hellmann + */ + +class Utilities { + + /** + * Loads WSDL and imported XSD files from web service and stores them + * locally. + */ + public static function loadWSDLfiles($wsdluri) { + $main = self :: getRequest($wsdluri); + $other = self :: getXSDImports($main); + $newMain = self :: changeXSDImports($main); + self :: writeToFile("main.wsdl", $newMain); + $x = 0; + foreach ($other as $o) { + self :: writeToFile("def" . ($x++) . ".xsd", self :: getRequest($o)); + } + } + + /** + * Change XSD imports in WSDL file to point to local imports. + */ + public static function changeXSDImports($wsdlFileContent) { + $before = "<xsd:import schemaLocation=\""; + $after = "\" namespace=\""; + $newWSDL = ""; + $desca = "def"; + $descb = ".xsd"; + $x = 0; + while ($posstart = strpos($wsdlFileContent, $before)) { + $posstart += strlen($before); + $newWSDL .= substr($wsdlFileContent, 0, $posstart); + $wsdlFileContent = substr($wsdlFileContent, $posstart); + $newWSDL .= $desca . ($x++) . $descb; + $posend = strpos($wsdlFileContent, $after); + $wsdlFileContent = substr($wsdlFileContent, $posend); + } + return $newWSDL . $wsdlFileContent; + } + + /** + * Extracts XSD imports from WSDL file. + */ + public static function getXSDImports($wsdlFileContent) { + $before = "<xsd:import schemaLocation=\""; + $after = "\" namespace=\""; + $ret = array (); + while ($posstart = strpos($wsdlFileContent, $before)) { + $posstart += strlen($before); + $wsdlFileContent = substr($wsdlFileContent, $posstart); + $posend = strpos($wsdlFileContent, $after); + $tmp = substr($wsdlFileContent, 0, $posend); + $ret[] = $tmp; + $wsdlFileContent = substr($wsdlFileContent, $posend +strlen($after)); + } + return $ret; + } + + /** + * Peforms a GET request and returns body of result. + */ + public static function getRequest($uri) { + $req = & new HTTP_Request($uri); + $req->setMethod(HTTP_REQUEST_METHOD_GET); + $req->sendRequest(); + $ret = $req->getResponseBody(); + return $ret; + } + + /** + * Writes $content to file $filename. + */ + public static function writeToFile($filename, $content) { + $fp = fopen($filename, "w"); + fwrite($fp, $content); + fclose($fp); + } + + /** + * Prints a list of all Web Service components and their configuration options. + */ + public static function printWebserviceComponents($client) { + echo '<h1>Web Service Information</h1>'; + + echo '<h2>Knowledge Sources</h2>'; + Utilities :: printComponentsInfo($client, $client->getKnowledgeSources()->item); + + echo '<h2>Reasoners</h2>'; + Utilities :: printComponentsInfo($client, $client->getReasoners()->item); + + echo '<h2>Learning Problems</h2>'; + Utilities :: printComponentsInfo($client, $client->getLearningProblems()->item); + + echo '<h2>Learning Algorithms</h2>'; + Utilities :: printComponentsInfo($client, $client->getLearningAlgorithms()->item); + } + + /** + * Print information about all given components. + */ + public static function printComponentsInfo($client, $components) { + foreach ($components as $component) + Utilities :: printComponentInfo($client, $component); + } + + /** + * Print information about a component. + */ + public static function printComponentInfo($client, $component) { + echo '<h3>component: ' . $component . '</h3>'; + + $options = $client->getConfigOptions($component, true)->item; + if (!is_array($options)) + $options = array ( + $options + ); + + foreach ($options as $option) + Utilities :: printOption($option); + } + + /** + * Prints information about an option. + * + * @param String Option as returned by the DL-Learner web service + * getConfigOption() method. + */ + public static function printOption($option) { + $parts = split('#', $option); + echo 'option name: <b>' . $parts[0] . '</b><br />'; + echo 'option description: ' . $parts[1] . '<br />'; + echo 'option class: ' . $parts[2] . '<br />'; + if ($parts[3] != 'null') + echo 'option name: ' . $parts[3] . '<br />'; + echo '<br />'; + } +} +?> Added: trunk/src/moosique.net/php/config.ini =================================================================== --- trunk/src/moosique.net/php/config.ini (rev 0) +++ trunk/src/moosique.net/php/config.ini 2009-03-17 00:07:12 UTC (rev 1652) @@ -0,0 +1,32 @@ +; Config file for moosique.net +; Define Prefixes and global URLs here + +[general] +path = "./" + +[url] +wsdl = "http://localhost:8181/services?wsdl" +wsdlLocal = "main.wsdl" +musicbrainz = "http://dbtune.org/musicbrainz/sparql/" +jamendo = "http://dbtune.org/jamendo/sparql/" + +[prefix] +; map = "<file:/home/moustaki/work/motools/musicbrainz/d2r-server-0.4/mbz_mapping_raw.n3#>" +rdfs = "<http://www.w3.org/2000/01/rdf-schema#>" +owl = "<http://www.w3.org/2002/07/owl#>" +event = "<http://purl.org/NET/c4dm/event.owl#>" +rel = "<http://purl.org/vocab/relationship/>" +lingvoj = "<http://www.lingvoj.org/ontology#>" +foaf = "<http://xmlns.com/foaf/0.1/>" +rdf = "<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +tags = "<http://www.holygoat.co.uk/owl/redwood/0.1/tags/>" +db = "<http://dbtune.org/musicbrainz/resource/>" +dc = "<http://purl.org/dc/elements/1.1/>" +geo = "<http://www.geonames.org/ontology#>" +bio = "<http://purl.org/vocab/bio/0.1/>" +mo = "<http://purl.org/ontology/mo/>" +vocab = "<http://dbtune.org/musicbrainz/resource/vocab/>" +xsd = "<http://www.w3.org/2001/XMLSchema#>" +mbz = "<http://purl.org/ontology/mbz#>" +; +; \ No newline at end of file Added: trunk/src/moosique.net/php/config.php =================================================================== --- trunk/src/moosique.net/php/config.php (rev 0) +++ trunk/src/moosique.net/php/config.php 2009-03-17 00:07:12 UTC (rev 1652) @@ -0,0 +1,53 @@ +<?php + +/** + * + */ +class config { + + private $config; + + /** + * On Class initialization, read the ini file to get + * the config values and hand them to $this->config + */ + function __construct() { + $this->config = parse_ini_file('config.ini', true); + + // load WSDL files (has to be done due to a Java web service bug) + include('Utilities.php'); + ini_set('soap.wsdl_cache_enabled', '0'); + Utilities::loadWSDLfiles($this->getUrl('wsdl')); + } + + /** + * + * @return + * @param String $value + */ + function getGeneral($value) { + return $this->config['general'][$value]; + } + + /** + * + * @return + * @param object $value + */ + function getUrl($value) { + return $this->config['url'][$value]; + } + + /** + * + * @return + */ + function getPrefixes() { + return $this->config['prefix']; + } +} + +// instantiate the config class +$conf = new config; + +?> \ No newline at end of file Added: trunk/src/moosique.net/php/requestHandler.php =================================================================== --- trunk/src/moosique.net/php/requestHandler.php (rev 0) +++ trunk/src/moosique.net/php/requestHandler.php 2009-03-17 00:07:12 UTC (rev 1652) @@ -0,0 +1,17 @@ +<?php + +class RequestHandler { + + function handle() { + + } + + function schalala() { + + } + + + +} + +?> \ No newline at end of file Added: trunk/src/moosique.net/php/test.php =================================================================== --- trunk/src/moosique.net/php/test.php (rev 0) +++ trunk/src/moosique.net/php/test.php 2009-03-17 00:07:12 UTC (rev 1652) @@ -0,0 +1,25 @@ +<?php + +include('config.php'); +include('SparqlQueryBuilder.php'); +include('DllearnerConnection.php'); + + +$connection = new DllearnerConnection($conf); +$connection->setEndpoint('http://arc.semsol.org/community/irc/sparql'); + +$query = ' +SELECT ?s ?p ?o WHERE { + ?s ?p ?o . +} LIMIT 10'; + + +$json = $connection->sparqlQuery($query); +$result = json_decode($json); +$bindings = $result->results->bindings; + +echo '<pre>'; +print_r($bindings); +echo '</pre>'; + +?> \ No newline at end of file Added: trunk/src/moosique.net/php/testJamendo.php =================================================================== --- trunk/src/moosique.net/php/testJamendo.php (rev 0) +++ trunk/src/moosique.net/php/testJamendo.php 2009-03-17 00:07:12 UTC (rev 1652) @@ -0,0 +1,33 @@ +<?php + +include('config.php'); +// include('SparqlQueryBuilder.php'); +include('DllearnerConnection.php'); + +$connection = new DllearnerConnection($conf); + +$query = ' +SELECT ?artist ?album +WHERE +{ ?a + a mo:MusicArtist; + foaf:name ?artist; + foaf:made ?album. + ?album tags:taggedWithTag <http://dbtune.org/jamendo/tag/stonerrock>. + } +'; + +/* TODO +$spargel = new SparqlQueryBuilder($conf, 'Low Earth Orbit', 'artist', array('artist', 'title', 'image')); +$query = $spargel->getQuery(); +*/ + +$json = $connection->sparqlQuery($query); +$result = json_decode($json); +$bindings = $result->results->bindings; + +echo '<pre>'; +print_r($bindings); +echo '</pre>'; + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |