From: <jen...@us...> - 2008-06-23 16:20:47
|
Revision: 977 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=977&view=rev Author: jenslehmann Date: 2008-06-23 09:20:34 -0700 (Mon, 23 Jun 2008) Log Message: ----------- Jamendo artist search Modified Paths: -------------- trunk/src/music-recommender/ajax.php trunk/src/music-recommender/index.php Modified: trunk/src/music-recommender/ajax.php =================================================================== --- trunk/src/music-recommender/ajax.php 2008-06-23 11:11:48 UTC (rev 976) +++ trunk/src/music-recommender/ajax.php 2008-06-23 16:20:34 UTC (rev 977) @@ -31,17 +31,19 @@ $xajax = new xajax(); +// set to debug during development if needed +$xajax->configureMany(array('debug'=>false)); + // register functions $xajax->registerFunction("doSearch"); - $xajax->processRequest(); // search for songs matching the search string function doSearch($searchString) { // ToDo: execute a SPARQL query (find labels matching search string) by contacting DL-Learner web service - $query = 'PREFIX geo:<http://www.geonames.org/ontology#> + /*$query = 'PREFIX geo:<http://www.geonames.org/ontology#> PREFIX wgs:<http://www.w3.org/2003/01/geo/wgs84_pos#> SELECT ?a ?place ?lat ?long WHERE { @@ -52,7 +54,20 @@ wgs:lat ?lat; wgs:long ?long } - LIMIT 1'; + LIMIT 1';*/ + // unfortunately full text search does not work yet - I am in contact with Yves Raimond to find a solution + // currently, we look for exact matches + $query = ' + SELECT ?artist ?name ?image ?homepage + WHERE { + ?artist a mo:MusicArtist . + ?artist foaf:name "'.$searchString.'" . + ?artist foaf:name ?name . + ?artist foaf:img ?image . + ?artist foaf:homepage ?homepage . + } + LIMIT 10'; + /*PREFIX geo: <http://www.geonames.org/ontology#> PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#> SELECT DISTINCT ?an ?lat ?long ?name ?population @@ -72,8 +87,29 @@ try { $connection = new DLLearnerConnection(); - $result = $connection->sparqlQuery($query); - $newContent = 'searching for '.$searchString.' ... not implemented '.$result; + $json = $connection->sparqlQuery($query); + $result = json_decode($json); + $bindings = $result->results->bindings; + + // preprocessing phase + // found artists (currently all results are artists) + /* + $artists = array(); + $count = 0; + foreach($bindings as $binding) { + $artists[$count]['image'] = $binding->image; + $count++; + }*/ + + // var_dump($bindings); + // $newContent = 'searching for '.$searchString.' ... not implemented <pre>test</pre>'; + $newContent = '<h3>Search Results</h3>'; + foreach($bindings as $binding) { + $newContent .= '<img style="float:right" src="'.$binding->image->value.'" />'; + $newContent .= '<b>'.$binding->name->value.'</b><br />'; + $newContent .= '<a href="'.$binding->homepage->value.'">'.$binding->homepage->value.'</a><br />'; + $newContent .= 'TODO: make author name clickable such that people can get tracks from this artist and listen to them'; + } } catch (Exception $e) { $newContent = '<b>Search aborted: '.$e->getMessage().'</b>'; } Modified: trunk/src/music-recommender/index.php =================================================================== --- trunk/src/music-recommender/index.php 2008-06-23 11:11:48 UTC (rev 976) +++ trunk/src/music-recommender/index.php 2008-06-23 16:20:34 UTC (rev 977) @@ -45,6 +45,8 @@ require_once 'ajax.php'; +// doSearch('Allison Crowe'); + echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> <!DOCTYPE html @@ -64,9 +66,11 @@ <!-- search form --> <input type="text" id="label" /> <button onclick="xajax_doSearch(document.getElementById('label').value);">search</button> + <p>Enter an artist and click the search button. (TODO: Enable search also for tracks and tags. Enable hitting enter instead of clicking button.)</p> + <p>Example artist: Allison Crowe</p> <!-- search result display --> - <div id="searchElement"></div> + <div id="searchElement" style="max-width:500px;"></div> <h2>Song List</h2> <a href="http://mediaplayer.yahoo.com/example1.mp3">song 1</a> <br /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |