|
From: <cyg...@us...> - 2007-08-14 16:46:31
|
Revision: 525
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=525&view=rev
Author: cyganiak
Date: 2007-08-14 09:46:23 -0700 (Tue, 14 Aug 2007)
Log Message:
-----------
Re-architected the book mashup and made new search interface
Added Paths:
-----------
trunk/bookmashup/.htaccess
trunk/bookmashup/ApiQueryService.php
trunk/bookmashup/bookmashup.php
trunk/bookmashup/config.inc.php
trunk/bookmashup/no-image.gif
trunk/bookmashup/rdf_icon.16.gif
trunk/bookmashup/search.php
Removed Paths:
-------------
trunk/bookmashup/documentation/
trunk/bookmashup/inc/
trunk/bookmashup/index.php
Added: trunk/bookmashup/.htaccess
===================================================================
--- trunk/bookmashup/.htaccess (rev 0)
+++ trunk/bookmashup/.htaccess 2007-08-14 16:46:23 UTC (rev 525)
@@ -0,0 +1,10 @@
+RewriteEngine on
+
+# Redirect homepage to Chris' web space
+RewriteRule ^$ http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/ [R,L]
+
+# Implement 303 redirects for URIs that identify books, reviews etc
+RewriteRule ^(books|reviews|persons|offers|shops)/(.*) /bookmashup/doc/$1/$2 [R=303,L]
+
+# Call bookmashup.php for document URIs
+RewriteRule ^doc/(books|reviews|persons|offers|shops)/(.*) /bookmashup/bookmashup.php?type=$1&item=$2 [L]
Copied: trunk/bookmashup/ApiQueryService.php (from rev 524, trunk/bookmashup/inc/ApiQueryService.php)
===================================================================
--- trunk/bookmashup/ApiQueryService.php (rev 0)
+++ trunk/bookmashup/ApiQueryService.php 2007-08-14 16:46:23 UTC (rev 525)
@@ -0,0 +1,280 @@
+<?php
+
+class ApiQueryService {
+
+ private $uri;
+ private $document;
+
+ public function ApiQueryService($uri, $document){
+ $this->uri = $uri;
+ $this->document = $document;
+ }
+
+ public function findInformationAboutBook(MemModel $model,$isbn){
+ $result = false;
+ $parsed_xml = $this->queryAmazon($isbn);
+ foreach($parsed_xml->Items->Item as $itemIndex => $item){
+ if($item->ItemAttributes->ISBN == strval($isbn)){
+ $this->addBookToModel($item,$model);
+ $result = true;
+ }
+ }
+ return $result;
+ }
+
+ public function findReview(MemModel $model,$review){
+ $isbn = substr($review,0,strpos($review,"_"));
+ // query Amazon:
+ $result = false;
+ $parsed_xml = $this->queryAmazon($isbn);
+ //var_dump($parsed_xml);
+ foreach($parsed_xml->Items->Item as $itemIndex => $item){
+ //only if right isbn
+ if($item->ItemAttributes->ISBN == strval($isbn)){
+ $result = $this->addReviewToModel($review,$item,$model);
+ }
+ }
+ return $result;
+ }
+
+ public function findOffer(MemModel $model,$offer){
+ $model->add(new Statement(new Resource($this->document),new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("RDF document describing an Offer")));
+ $result = false;
+ if(($pos = strpos($offer,"amazon"))!= false){
+ $isbn = substr($offer,0,strlen($offer)-($pos+1));
+ $result = $this->findAmazonOffer($model,$offer,$isbn);
+ }else{
+ $pos = $pos = strpos($offer,"google");
+ $isbn = substr($offer,0,strlen($offer)-($pos+1));
+ $result = $this->findGoogleOffer($model,$offer,$isbn);
+ }
+ return $result;
+ }
+
+ public function findShop(MemModel $model,$shop){
+ $itemresource = new Resource($this->uri);
+ $string = base64_decode($shop);
+ $shopAr = split("\|\|",$string);
+
+ $model->add(new Statement(new Resource($this->document),new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("RDF document describing the shop: ".$shopAr[1])));
+ $model->add(new Statement($itemresource ,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#Store")));
+ $model->add(new Statement($itemresource ,new Resource("http://xmlns.com/foaf/0.1/name"),new Literal($shopAr[1])));
+ $model->add(new Statement($itemresource ,new Resource("http://xmlns.com/foaf/0.1/page"),new Resource($shopAr[0])));
+ $model->add(new Statement($itemresource ,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal($shopAr[1])));
+ return true;
+ }
+
+ public function findInformationAboutPerson(MemModel $model,$person){
+ $name = urldecode($person);
+ $result = false;
+ $result = $this->addPersonToModel(null,$model,$name);
+ return $result;
+ }
+
+ private function addGoogleOffersToModel(MemModel $model){
+ $isbn = substr($this->uri,strrpos($this->uri,"/")+1,strlen($this->uri));
+ $itemresource = new Resource($this->uri);
+ //echo $isbn;
+ // build Query
+ $query = '[isbn:"'.$isbn.'"]';
+ $q_uri = "http://www.google.com/base/feeds/snippets?bq=".urlencode($query)."&max-results=250";
+ $con = file_get_contents($q_uri);
+ // hack: simple_xml ignores <g:....
+ $content = str_replace("<g:","<",$con);
+ $content = str_replace("</g:","</",$content);
+ $xml = simplexml_load_string($content);
+ $newuri = str_replace("/books/","/offers/",$this->uri);
+ $pos = strrpos($newuri,"/");
+ foreach($xml->entry as $key => $entry){
+ $id = substr($entry->id,strrpos($entry->id,"/")+1,strlen($entry->id));
+ $offer = new Resource($newuri."googleOffer".$id);
+ $model->add(new Statement($itemresource ,new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#hasOffer"),$offer));
+ $model->add(new Statement($offer ,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("Offer for the book with the ISBN: ".$isbn)));
+ }
+ }
+
+ private function addPersonToModel(SimpleXMLElement $item = null,MemModel $model,$name){
+ $itemresource = new Resource($this->uri);
+ // rdf:type
+ $model->add(new Statement($itemresource ,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource("http://xmlns.com/foaf/0.1/Person")));
+ // rdf:name
+ $model->add(new Statement($itemresource ,new Resource("http://xmlns.com/foaf/0.1/name"),new Literal($name)));
+ //
+ $this->findBooksFromAuthor($model,$name);
+
+ $model->add(new Statement(new Resource($this->document),new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("RDF document describing: ".$name)));
+ $this->dblpLookup($name,$model);
+ return true;
+ }
+
+ private function findBooksFromAuthor($model,$name){
+ $xml = $this->queryAmazon($name);
+ foreach($xml->Items->Item as $index =>$item){
+ if(isset($item->ItemAttributes->ISBN)){
+ if($item->ItemAttributes->Author == $name){
+ $book = str_replace("/persons/","/books/",$this->uri);
+ $book = substr($book,0,strrpos($book,"/")+1).$item->ItemAttributes->ISBN;
+ $model->add(new Statement(new Resource($book),new Resource("http://purl.org/dc/elements/1.1/creator"),new Resource($this->uri)));
+ $model->add(new Statement(new Resource($book) ,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal($item->ItemAttributes->Title)));
+ }
+ }
+ }
+ }
+
+
+
+ private function findAmazonOffer($model,$offer,$isbn){
+ // query Amazon:
+ $itemresource = new Resource($this->uri);
+ $parsed_xml = $this->queryAmazon($isbn);
+ $result = false;
+ foreach($parsed_xml->Items->Item as $itemIndex => $item){
+ //only if right isbn
+ if($item->ItemAttributes->ISBN == strval($isbn)){
+ $shopUri = substr($item->DetailPageURL,0,strpos($item->DetailPageURL,"/",8))."||Amazon";
+ $newuri = str_replace("/offers/","/shops/",$this->uri);
+ $newuri = substr($newuri,0,strrpos($newuri,"/")+1).base64_encode(trim($shopUri));
+ $model->add(new Statement($itemresource ,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#Offer")));
+ $model->add(new Statement($itemresource ,new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#offeredBy"),new Resource($newuri)));
+ $model->add(new Statement($itemresource ,new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#hasPrice"),new Literal((string)$item->OfferSummary->LowestNewPrice->FormattedPrice)));
+ $model->add(new Statement($itemresource ,new Resource("http://www.hackcraft.net/bookrdf/vocab/0_1/soldAt"),new Resource($item->DetailPageURL)));
+ $model->add(new Statement(new Resource($newuri) ,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("Amazon")));
+ $result = true;
+ break;
+ }
+ }
+ return $result;
+ }
+
+
+ private function findGoogleOffer($model,$offer,$isbn){
+ $result = false;
+ $itemresource = new Resource($this->uri);
+ $id = substr($offer,(strpos($offer,"google")+11));
+ // hack: don't query google. Get xml result from snippets id
+ $con = file_get_contents("http://www.google.com/base/feeds/snippets/".$id);
+ // hack: simple_xml ignores <g:....
+ $content = str_replace("<g:","<",$con);
+ $content = str_replace("</g:","</",$content);
+ $xml = simplexml_load_string($content);
+ $model->add(new Statement($itemresource ,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#Offer")));
+ foreach($xml->link as $key => $link){
+ if(($link['rel']=="alternate")&& ($link['type'] == "text/html") ){
+ $model->add(new Statement($itemresource ,new Resource("http://xmlns.com/foaf/0.1/page"),new Resource($link['href'])));
+ $shopUri = substr($link['href'],0,strpos($link['href'],"/",8))."||".trim($xml->author->name);
+ $newuri = str_replace("/offers/","/shops/",$this->uri);
+ $newuri = substr($newuri,0,strrpos($newuri,"/")+1).base64_encode($shopUri);
+ $model->add(new Statement($itemresource ,new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#offeredBy"),new Resource($newuri)));
+ $model->add(new Statement($itemresource ,new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#hasPrice"),new Literal($xml->price)));
+ $model->add(new Statement(new Resource($newuri) ,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal($xml->author->name)));
+ $result = true;
+ }
+ }
+ return $result;
+ }
+
+ private function addReviewToModel($review, $item, MemModel $model){
+ $number = substr($review,strpos($review,"_")+16);
+ $i = 1;
+ $result = false;
+ foreach($item->EditorialReviews->EditorialReview as $index => $rev){
+ if($i == $number){
+ $model->add(new Statement(new Resource($this->uri) ,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource("http://dannyayers.com/xmlns/rev/#Review")));
+ $model->add(new Statement(new Resource($this->uri) ,new Resource("http://dannyayers.com/xmlns/rev/#text"),new Literal("'".$rev->Content."'")));
+ $model->add(new Statement(new Resource($this->document),new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("RDF document describing a review about: ".$item->ItemAttributes->Title)));
+ $result = true;
+ break;
+ }
+ $i++;
+ }
+ return $result;
+ }
+
+ public function queryAmazon($query){
+ $searchIndex = "Books";
+ $request="http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=ItemSearch&ResponseGroup=Medium";
+ $request.="&SearchIndex=$searchIndex&Keywords=".urlencode($query);
+ $response = file_get_contents($request);
+ return simplexml_load_string($response);
+ }
+
+ private function addBookToModel(SimpleXMLElement $item,MemModel $model){
+
+ $itemresource = new Resource($this->uri);
+ // rdf:type
+ $model->add(new Statement($itemresource ,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#Book")));
+ // homepage (link to details page @ amazon)
+ //$model->add(new Statement($itemresource ,new Resource("http://xmlns.com/foaf/0.1/homepage"),new Resource($item->DetailPageURL)));
+ // label
+ $model->add(new Statement($itemresource ,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal((string)$item->ItemAttributes->Title)));
+ // date
+ $model->add(new Statement($itemresource ,new Resource("http://purl.org/dc/elements/1.1/date"),new Literal((string)$item->ItemAttributes->PublicationDate)));
+ // title
+ $model->add(new Statement($itemresource ,new Resource("http://purl.org/dc/elements/1.1/title"),new Literal((string)$item->ItemAttributes->Title)));
+ //large image
+ $model->add(new Statement($itemresource ,new Resource("http://xmlns.com/foaf/0.1/depiction"),new Resource((string)$item->LargeImage->URL)));
+ // thumbnail
+ $model->add(new Statement($itemresource ,new Resource("http://xmlns.com/foaf/0.1/thumbnail"),new Resource((string)$item->SmallImage->URL)));
+ // isbn
+ $model->add(new Statement($itemresource ,new Resource("http://purl.org/dc/elements/1.1/identifier"),new Resource("urn:ISBN:".$item->ItemAttributes->ISBN)));
+ // publisher
+ $model->add(new Statement($itemresource ,new Resource("http://purl.org/dc/elements/1.1/publisher"),new Literal((string)$item->ItemAttributes->Label)));
+ // format
+ if(isset($item->ItemAttributes->format))
+ $model->add(new Statement($itemresource ,new Resource("http://purl.org/dc/elements/1.1/format"),new Literal((string)$item->ItemAttributes->format)));
+ if(isset($item->ItemAttributes->Binding))
+ $model->add(new Statement($itemresource ,new Resource("http://purl.org/dc/elements/1.1/format"),new Literal((string)$item->ItemAttributes->Binding)));
+ // reviews
+ $i = 1;
+ foreach($item->EditorialReviews->EditorialReview as $index => $review){
+ $newuri = str_replace("/books/","/reviews/",$this->uri);
+ $pos = strrpos($newuri,"/");
+ $review = new Resource($newuri."_".$index.$i);
+ $model->add(new Statement($itemresource ,new Resource("http://dannyayers.com/xmlns/rev/#hasReview"),$review));
+ $model->add(new Statement($review,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("Review number ".$i." about: ".$item->ItemAttributes->Title)));
+ $i++;
+ }
+ // author
+ $newuri = str_replace("/books/","/persons/",$this->uri);
+ $pos = strrpos($newuri,"/");
+ if(isset($item->ItemAttributes->Author)){
+ foreach($item->ItemAttributes->Author as $k => $author){
+ $authorUri = new Resource(substr($newuri,0,$pos+1).urlencode($author));
+ $model->add(new Statement($itemresource ,new Resource("http://purl.org/dc/elements/1.1/creator"),$authorUri));
+ $model->add(new Statement($authorUri,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal((string)$author)));
+ }
+ }
+ if(isset($item->ItemAttributes->Creator)){
+ foreach($item->ItemAttributes->Creator as $key => $creator){
+ $creatorUri = new Resource(substr($newuri,0,$pos+1).urlencode($creator));
+ $model->add(new Statement($itemresource ,new Resource("http://purl.org/dc/elements/1.1/creator"),$creatorUri));
+ $model->add(new Statement($creatorUri,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal((string)$creator)));
+ }
+ }
+ // amazon offer
+ $newuri = str_replace("/books/","/offers/",$this->uri);
+ $pos = strrpos($newuri,"/");
+ $offer = new Resource($newuri."amazonOffer");
+ $model->add(new Statement($itemresource ,new Resource("http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#hasOffer"),$offer));
+ $model->add(new Statement($offer ,new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("Offer for the book with the ISBN: ".$item->ItemAttributes->ISBN)));
+ // create OFFER from google
+ $this->addGoogleOffersToModel($model,$this->uri);
+
+ //
+ $model->add(new Statement(new Resource($this->document),new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("RDF document about the book: ".$item->ItemAttributes->Title)));
+
+ }
+
+ private function dblpLookup($name,$model){
+ //query dblp
+ $querystring = 'PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?author WHERE { ?author foaf:name "'.$name.'" .}';
+ $request = "http://www4.wiwiss.fu-berlin.de/dblp/sparql?query=".urlencode($querystring);
+ $response = file_get_contents($request);
+ $parsed_xml = simplexml_load_string($response);
+ $itemresource = new Resource($this->uri);
+ if(isset($parsed_xml->results->result->binding->uri))
+ $model->add(new Statement($itemresource,new Resource("http://www.w3.org/2002/07/owl#sameAs"),new Resource($parsed_xml->results->result->binding->uri)));
+ }
+
+ }
+?>
Copied: trunk/bookmashup/bookmashup.php (from rev 524, trunk/bookmashup/index.php)
===================================================================
--- trunk/bookmashup/bookmashup.php (rev 0)
+++ trunk/bookmashup/bookmashup.php 2007-08-14 16:46:23 UTC (rev 525)
@@ -0,0 +1,66 @@
+<?php
+
+// I think the latest RAP works with E_ALL, but we still run an older version
+error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
+//error_reporting(E_ALL);
+
+include("config.inc.php");
+include(RDFAPI_INCLUDE_DIR . "RdfAPI.php");
+include("ApiQueryService.php");
+
+// Create an RDF model and fill with information about the resource
+$type = @$_GET["type"];
+$item = @$_GET["item"];
+$documentURI = BOOKMASHUP_BASE . "doc/" . urlencode($type) . "/" . urlencode($item);
+$resourceID = BOOKMASHUP_BASE . urlencode($type) . "/" . urlencode($item);
+$service = new ApiQueryService($resourceID, $documentURI);
+$model = ModelFactory::getDefaultModel();
+if ($type == "books") {
+ $service->findInformationAboutBook($model, $item);
+} else if ($type == "persons") {
+ $service->findInformationAboutPerson($model, urlencode($item));
+} else if ($type == "reviews") {
+ $service->findReview($model, $item);
+} else if ($type == "offers") {
+ $service->findOffer($model, urlencode($item));
+} else if ($type == "shops") {
+ $service->findShop($model, $item);
+} else {
+ header("HTTP/1.1 404 Not Found");
+ header("Content-Type: text/plain");
+ echo "Resource not found\n";
+ exit();
+}
+
+// Add document metadata to model
+$doc = new Resource($documentURI);
+$resource = new Resource($resourceID);
+$rdf_type = new Resource(RDF_NAMESPACE_URI . RDF_TYPE);
+$foaf_Document = new Resource("http://xmlns.com/foaf/0.1/Document");
+$foaf_primaryTopic = new Resource("http://xmlns.com/foaf/0.1/primaryTopic");
+$foaf_maker = new Resource("http://xmlns.com/foaf/0.1/maker");
+$dc_license = new Resource("http://purl.org/dc/elements/1.1/license");
+$rdfs_label = new Resource("http://www.w3.org/2000/01/rdf-schema#label");
+$AWS_license = new Resource("http://www.amazon.com/AWS-License-home-page-Money/b/ref=sc_fe_c_0_12738641_12/102-8791790-9885755?ie=UTF8&node=3440661&no=12738641&me=A36L942TSJ2AJA");
+$Google_license = new Resource("http://www.google.com/terms_of_service.html");
+$bookmashup = new Resource("http://www4.wiwiss.fu-berlin.de/is-group/resource/projects/Project10");
+
+$model->add(new Statement($doc, $rdf_type, $foaf_Document));
+$model->add(new Statement($doc, $foaf_primaryTopic, $resource));
+$model->add(new Statement($doc, $dc_license, $AWS_license));
+$model->add(new Statement($doc, $dc_license, $Google_license));
+$model->add(new Statement($doc, $foaf_maker, $bookmashup));
+$model->add(new Statement($bookmashup, $rdfs_label, new Literal("RDF Book Mashup")));
+
+// Output model as RDF/XML
+header('Content-Type: application/rdf+xml; charset=utf-8');
+include(RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_RDF);
+$s = new RdfSerializer();
+$s->addNamespacePrefix('foaf', 'http://xmlns.com/foaf/0.1/');
+$s->addNamespacePrefix('rev', 'http://dannyayers.com/xmlns/rev/#');
+$s->addNamespacePrefix('scom', 'http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#');
+$s->addNamespacePrefix('bookRdf', 'http://www.hackcraft.net/bookrdf/vocab/0_1/');
+$s->addNamespacePrefix('owl', 'http://www.w3.org/2002/07/owl#');
+echo $s->serialize($model);
+
+?>
Copied: trunk/bookmashup/config.inc.php (from rev 524, trunk/bookmashup/inc/config.inc)
===================================================================
--- trunk/bookmashup/config.inc.php (rev 0)
+++ trunk/bookmashup/config.inc.php 2007-08-14 16:46:23 UTC (rev 525)
@@ -0,0 +1,8 @@
+<?php
+
+define('BOOKMASHUP_BASE', 'http://www4.wiwiss.fu-berlin.de/bookmashup/');
+define('RDFAPI_INCLUDE_DIR','C:/!htdocs/rdfapi-php/api/');
+define('KEYID','1VM1PSHWXY16G9KM3F02');
+define('AssocTag','[YourAssocitaeTagHere]');
+
+?>
Deleted: trunk/bookmashup/index.php
===================================================================
--- trunk/bookmashup/index.php 2007-08-14 11:12:45 UTC (rev 524)
+++ trunk/bookmashup/index.php 2007-08-14 16:46:23 UTC (rev 525)
@@ -1,97 +0,0 @@
-<?php
-/*
- * Created on 20.11.2006
- *
- * To change the template for this generated file go to
- * Window - Preferences - PHPeclipse - PHP - Code Templates
- */
-
-if(strpos($_SERVER['SCRIPT_URI'],"/doc/")){
- // cut /doc/
- $uri = str_replace("/doc/","/",$_SERVER['SCRIPT_URI']);
-
- include("inc/config.inc");
-
- include(RDFAPI_INCLUDE_DIR."RdfAPI.php");
- // include query service
- include(RDF_BOOK_DIR."ApiQueryService.php");
-
- // initialize query service;
- $aqs = new ApiQueryService($uri);
-
- // get empty model
- $model = ModelFactory::getDefaultModel();
-
- // disable notices
- error_reporting(null);
-
- $res = false;
- // check if person (creator), book, review
-if(strpos($uri,"/books/")){
- $isbn = substr($_GET['var'],6);
- $res = $aqs->findInformationAboutBook($model,$isbn);
-}
-if(strpos($uri,"/persons/")){
- $person = urlencode(substr($_GET['var'],8));
- $res = $aqs->findInformationAboutPerson($model,$person);
-}
-
-if(strpos($uri,"/reviews/")){
- $review = substr($_GET['var'],8);
- //echo $review;
- $res = $aqs->findReview($model,$review);
-}
-if(strpos($uri,"/offers/")){
- $offer = urlencode(substr($_GET['var'],7));
- $res = $aqs->findOffer($model,$offer);
-}
-if(strpos($uri,"/shops/")){
- $shop = substr($_GET['var'],6);
- $res = $aqs->findShop($model,$shop);
-}
-if(!$res){
- header("HTTP/1.1 404 Not Found");
- echo "URI not found";
-}else{
-// add type triple
-$model->add(new Statement(new Resource($_SERVER['SCRIPT_URI']) ,new Resource(RDF_NAMESPACE_URI.RDF_TYPE),new Resource("http://xmlns.com/foaf/0.1/Document")));
-// add topic triple
-$model->add(new Statement(new Resource($_SERVER['SCRIPT_URI']),new Resource("http://xmlns.com/foaf/0.1/primaryTopic"),new Resource($uri)));
-// add license triple
-$model->add(new Statement(new Resource($_SERVER['SCRIPT_URI']),new Resource("http://purl.org/dc/elements/1.1/license"),new Resource("http://www.amazon.com/AWS-License-home-page-Money/b/ref=sc_fe_c_0_12738641_12/102-8791790-9885755?ie=UTF8&node=3440661&no=12738641&me=A36L942TSJ2AJA")));
-$model->add(new Statement(new Resource($_SERVER['SCRIPT_URI']),new Resource("http://purl.org/dc/elements/1.1/license"),new Resource("http://www.google.com/terms_of_service.html")));
-$model->add(new Statement(new Resource($_SERVER['SCRIPT_URI']),new Resource("http://xmlns.com/foaf/0.1/maker"),new Resource("http://www4.wiwiss.fu-berlin.de/is-group/resource/projects/Project10")));
-$model->add(new Statement(new Resource("http://www4.wiwiss.fu-berlin.de/is-group/resource/projects/Project10"),new Resource("http://www.w3.org/2000/01/rdf-schema#label"),new Literal("Book Mashup")));
-
- header('Content-type: application/rdf+xml; charset=utf-8');
-
- include(RDFAPI_INCLUDE_DIR.PACKAGE_SYNTAX_RDF);
- $s = new RdfSerializer();
- $s->addNamespacePrefix('foaf','http://xmlns.com/foaf/0.1/');
- $s->addNamespacePrefix('rev','http://dannyayers.com/xmlns/rev/#');
- $s->addNamespacePrefix('scom','http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/simpleCommerceVocab01.rdf#');
- $s->addNamespacePrefix('bookRdf','http://www.hackcraft.net/bookrdf/vocab/0_1/');
- $s->addNamespacePrefix('owl','http://www.w3.org/2002/07/owl#');
- echo $s->serialize($model);
-}
-}else{
-
- $docUri = "http://sites.wiwiss.fu-berlin.de/suhl/bizer/bookmashup/index.html";
- if(strpos($_SERVER['SCRIPT_URI'],"/books/"))
- $docUri = str_replace("/books/","/doc/books/",$_SERVER['SCRIPT_URI']);
- if(strpos($_SERVER['SCRIPT_URI'],"/persons/"))
- $docUri = str_replace("/persons/","/doc/persons/",$_SERVER['SCRIPT_URI']);
- if(strpos($_SERVER['SCRIPT_URI'],"/reviews/"))
- $docUri = str_replace("/reviews/","/doc/reviews/",$_SERVER['SCRIPT_URI']);
- if(strpos($_SERVER['SCRIPT_URI'],"/offers/"))
- $docUri = str_replace("/offers/","/doc/offers/",$_SERVER['SCRIPT_URI']);
- if(strpos($_SERVER['SCRIPT_URI'],"/shops/"))
- $docUri = str_replace("/shops/","/doc/shops/",$_SERVER['SCRIPT_URI']);
-
-
- header('Location: '.$docUri,false,303);
-}
-
-
-
-?>
Added: trunk/bookmashup/no-image.gif
===================================================================
(Binary files differ)
Property changes on: trunk/bookmashup/no-image.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/bookmashup/rdf_icon.16.gif
===================================================================
(Binary files differ)
Property changes on: trunk/bookmashup/rdf_icon.16.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Copied: trunk/bookmashup/search.php (from rev 524, trunk/bookmashup/documentation/booksearch.php)
===================================================================
--- trunk/bookmashup/search.php (rev 0)
+++ trunk/bookmashup/search.php 2007-08-14 16:46:23 UTC (rev 525)
@@ -0,0 +1,239 @@
+<?php
+
+class AmazonSearch {
+ var $search_index = "Books";
+ var $search_term;
+ var $page;
+ var $results = array();
+ var $total_pages = 0;
+ var $total_results = 0;
+ var $results_per_page = 10;
+
+ function __construct($search_term, $page = 1) {
+ $this->search_term = $search_term;
+ $this->page = $page;
+ }
+
+ function execute() {
+ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService"
+ . "&AWSAccessKeyId=" . KEYID
+ . "&AssociateTag=" . AssocTag
+ . "&Version=2006-09-11"
+ . "&Operation=ItemSearch"
+ . "&ResponseGroup=Medium"
+ . "&SearchIndex=" . $this->search_index
+ . "&Keywords=" . urlencode($this->search_term)
+ . "&ItemPage=" . $this->page;
+ $response = file_get_contents($request);
+ $xml = simplexml_load_string($response);
+ if ($xml->Items->Request->IsValid == "False" || $xml->Items->TotalResults == "0") {
+ return false;
+ }
+ $this->results = array();
+ foreach ($xml->Items->Item as $key =>$item) {
+ $book = array(
+ 'isbn' => (string) @$item->ItemAttributes->ISBN,
+ 'title' => (string) @$item->ItemAttributes->Title,
+ 'authors' => array(),
+ 'uri' => BOOKMASHUP_BASE . "books/" . @$item->ItemAttributes->ISBN,
+ 'image' => (string) @$item->SmallImage->URL,
+ );
+ foreach($item->ItemAttributes->Author as $author) {
+ if (in_array($author, $book['authors'])) continue;
+ $book['authors'][] = (string) $author;
+ }
+ foreach($item->ItemAttributes->Creator as $creator){
+ $book['authors'][] = (string) $creator;
+ }
+ $this->results[] = $book;
+ }
+ $this->total_pages = (int) $xml->Items->TotalPages;
+ $this->total_results = (int) $xml->Items->TotalResults;
+ return true;
+ }
+}
+
+include("config.inc.php");
+
+$query = @$_GET['keywords'];
+$page = @$_GET['page'];
+if (!$page) $page = 1;
+$output = @$_GET['output'];
+if ($output != 'rdf') $output = 'html';
+
+$service = new AmazonSearch($query, $page);
+$service->execute();
+
+if ($output == 'rdf') {
+ include(RDFAPI_INCLUDE_DIR . "RdfAPI.php");
+ $model = ModelFactory::getDefaultModel();
+
+ define("SEARCH_NS", "urn:x-search:");
+ $rdf_type = new Resource(RDF_NAMESPACE_URI . "type");
+ $rdfs_label = new Resource(RDF_SCHEMA_URI . "label");
+ $dc_creator = new Resource(DC_NS . "creator");
+ $foaf_name = new Resource(FOAF_NS . "name");
+ $foaf_depiction = new Resource(FOAF_NS . "depiction");
+ $SearchResultPage = new Resource(SEARCH_NS . "SearchResultPage");
+ $searchTerm = new Resource(SEARCH_NS . "searchTerm");
+ $page = new Resource(SEARCH_NS . "page");
+ $totalPages = new Resource(SEARCH_NS . "totalPages");
+ $totalResults = new Resource(SEARCH_NS . "totalResults");
+ $nextPage = new Resource(SEARCH_NS . "nextPage");
+ $searchResult = new Resource(SEARCH_NS . "result");
+ $rank = new Resource(SEARCH_NS . "rank");
+ $item = new Resource(SEARCH_NS . "item");
+ $document = new Resource(BOOKMASHUP_BASE . "search.php?keywords=" . urlencode($query) . "&page=" . $service->page . "&output=rdf");
+ $label = "Search results for: " . $query . (($service->total_pages > 1) ? " (page {$service->page} of {$service->total_pages})" : "");
+ $page_number = new Literal($service->page);
+ $page_number->setDatatype(XML_SCHEMA . "int");
+ $total_pages_number = new Literal($service->total_pages);
+ $total_pages_number->setDatatype(XML_SCHEMA . "int");
+ $total_results_number = new Literal($service->total_results);
+ $total_results_number->setDatatype(XML_SCHEMA . "int");
+ $next_page = new Resource(BOOKMASHUP_BASE . "search.php?keywords=" . urlencode($query) . "&page=" . ($service->page + 1) . "&output=rdf");
+
+ $model->add(new Statement($document, $rdf_type, $SearchResultPage));
+ $model->add(new Statement($document, $rdfs_label, new Literal($label)));
+ $model->add(new Statement($document, $searchTerm, new Literal($query)));
+ $model->add(new Statement($document, $page, $page_number));
+ $model->add(new Statement($document, $totalPages, $total_pages_number));
+ $model->add(new Statement($document, $totalResults, $total_results_number));
+ $model->add(new Statement($document, $nextPage, $next_page));
+ $i = ($service->page - 1) * $service->results_per_page;
+ foreach ($service->results as $book) {
+ $i++;
+ $this_result = new BlankNode("result$i");
+ $rank_number = new Literal($i);
+ $rank_number->setDatatype(XML_SCHEMA . "int");
+ $model->add(new Statement($document, $searchResult, $this_result));
+ $model->add(new Statement($this_result, $rank, $rank_number));
+ $model->add(new Statement($this_result, $item, new Resource($book['uri'])));
+ $model->add(new Statement($this_result, $rdfs_label, new Literal($book['title'])));
+ if ($book['image']) {
+ $model->add(new Statement($this_result, $foaf_depiction, new Resource($book['image'])));
+ }
+ foreach ($book['authors'] as $key => $author) {
+ $this_author = new BlankNode("result{$i}_author" . ($key + 1));
+ $model->add(new Statement($this_result, $dc_creator, $this_author));
+ $model->add(new Statement($this_author, $foaf_name, new Literal($author)));
+ }
+ }
+ header('Content-Type: application/rdf+xml; charset=utf-8');
+ include(RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_RDF);
+ $s = new RdfSerializer();
+ $s->addNamespacePrefix('rdf', RDF_NAMESPACE_URI);
+ $s->addNamespacePrefix('rdfs', RDF_SCHEMA_URI);
+ $s->addNamespacePrefix('dc', DC_NS);
+ $s->addNamespacePrefix('foaf', FOAF_NS);
+ $s->addNamespacePrefix('search', SEARCH_NS);
+ echo $s->serialize($model);
+ exit();
+}
+
+?><html lang="en">
+ <head>
+ <title><?php if ($query) { ?>Search Results: “<?php echo htmlspecialchars($query); ?>”<?php } else { ?>Book Search<?php } ?> | RDF Book Mashup</title>
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
+ <link rel='alternate' type='application/rdf+xml' href='search.php?keywords=<?php echo htmlspecialchars(urlencode($query)); ?>&page=<?php echo $page; ?>&output=rdf' />
+ <style type="text/css">
+body { background: white; color: black; font-family: sans-serif; line-height: 1.4em; padding: 2.5em 3em; margin: 0; }
+:link { color: #00c; }
+:visited { color: #609; }
+a:link img { border: none; }
+a:visited img { border: none; }
+h1, h2, h3 { background: white; color: #800; }
+h1 { font: 170% sans-serif; margin: 0; }
+h2 { font: 140% sans-serif; margin: 1.5em 0 -0.5em 0; }
+h3 { font: 120% sans-serif; margin: 1.5em 0 -0.5em 0; }
+h4 { font: bold 100% sans-serif; }
+h5 { font: italic 100% sans-serif; }
+h6 { font: small-caps 100% sans-serif; }
+.hide { display: none; }
+pre { background: #fff6bb; font-family: monospace; line-height: 1.2em; padding: 1em 2em; }
+dt { font-weight: bold; margin-top: 1.2em; margin-bottom: 0; }
+dd { margin: 0; padding: 0; }
+code, tt { font-family: monospace; }
+ul.toc { list-style-type: none; }
+ol.toc li a { text-decoration: none; }
+.note { color: red; }
+ul.results { list-style-type: none; padding-left: 0; }
+ul.results li { clear: left; margin-bottom: 1.2em; }
+.image { float: left; margin-bottom: 12px; padding-right: 1em; padding-top: 0.25em; text-align: right; width: 80px; }
+.title { color: #800; font-weight: bold; }
+.author { color: #888; font-size: 92%; }
+a.rdfuri { background: url(rdf_icon.16.gif) center left no-repeat; font-size: 92%; padding-left: 20px; text-decoration: none; }
+a.rdfuri:link { color: #66b; }
+a.rdfuri:visited { color: #869; }
+#header { border-bottom: 1px solid #ccc; }
+#logo { float: right; }
+#authors { clear: right; float: right; font-size: 80%; text-align: right; }
+#content { clear: both; margin: 2em auto 0 0; text-align: justify }
+#download { font-family: sans-serif; margin-bottom: 1em; text-align: center; }
+#download h2 { font-size: 125%; margin: 1.5em 0 -0.2em 0; }
+#download small { color: #888; font-size: 80%; }
+#footer { border-top: 1px solid #ccc; color: #aaa; margin: 2em 0 0; }
+
+@media Print {
+* { font-size: 92%; }
+body { padding: 0; line-height: 1.2em; }
+#content { margin: 0; width: 100%; }
+}
+@media Aural {
+h1 { stress: 20; richness: 90; }
+h2 { stress: 20; richness: 90; }
+h3 { stress: 20; richness: 90; }
+.hide { speak: none; }
+dt { pause-before: 20%; }
+pre { speak-punctuation: code; }
+}
+ </style>
+ </head>
+ <body>
+ <div id="header">
+ <h1><?php if ($query) { ?>Book Search Results for “<?php echo htmlspecialchars($query); ?>” <?php } else { ?>Book Search<?php } ?></h1>
+ </div>
+ <div id="content">
+ <form name='SearchTerms' action='search.php' method='GET'>
+ <p>Search for books:
+ <input type='text' name='keywords' size='40' value='<?php echo htmlspecialchars($query); ?>' />
+ <input type='submit' value='Go' /></p>
+ </form>
+<?php if ($service->results) { ?>
+ <p><strong>Note:</strong> You will need an RDF-capable browser to display any of these items.</p>
+ <ul class='results'>
+<?php foreach ($service->results as $book) { ?>
+<?php if (!isset($book['isbn'])) continue; ?>
+ <li>
+<?php if ($book['image']) { ?>
+ <div class='image'><img src='<?php echo htmlspecialchars($book['image']); ?>' alt='' /></div>
+<?php } else { ?>
+ <div class='image'><img src='no-image.gif' alt='' /></div>
+<?php } ?>
+ <div style='margin-left: 80px; padding-left: 1em'>
+ <span class='title'><?php echo htmlspecialchars($book['title']); ?></span><br />
+<?php if ($book['authors']) { ?>
+ <span class='author'><?php echo join(', ', $book['authors']); ?></span><br />
+<?php } ?>
+ <a class='rdfuri' href='<?php echo htmlspecialchars($book['uri']); ?>'><?php echo htmlspecialchars($book['uri']); ?></a></span></li>
+ </div>
+<?php } ?>
+ </ul>
+<?php } else { ?>
+ <p><strong>Your query returned no results.</strong></p>
+<?php } ?>
+ <p>
+<?php if ($page > 1) { ?>
+ « <a href='search.php?keywords=<?php echo htmlspecialchars(urlencode($query)); ?>&page=<?php echo $page - 1; ?>'>Previous</a>
+<?php } ?>
+<?php if ($page > 1 && $page < $service->total_pages) { ?> | <?php } ?>
+<?php if ($page < $service->total_pages) { ?>
+ <a href='search.php?keywords=<?php echo htmlspecialchars(urlencode($query)); ?>&page=<?php echo $page + 1; ?>'>Next</a> »
+<?php } ?>
+ </p>
+ </div>
+ <div id="footer">
+ <small><a href="<?php echo BOOKMASHUP_BASE; ?>">Back to RDF Book Mashup</a></small>
+ </div>
+ </body>
+</html>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|