Zemanta API & examples – over view with PHP

June 27, 2008

Zemanta provides live suggesions when you start writing blogs.  Zemanta also a browser based plugin gives you suggestions based on your text that you typing, image, url’s & more.

What is the purpose of using Zemanta ?

You can get relevant tags what you have typed.

NLP – Natural Language processing, it analyze your input text with lexical analyzer & find out the tags(/objects/names)

Based on that tags, it lists the number of URL’s/ images found related to those tags.

Input  : “text”

Output : Related URLs, Tags & images

Sample Code how it works,

Contact Zemanta & get API from them.

Live Testing URL :  http://livebillion.com/calais/test_zemanta.php

test_zemanta.php

——–

<form action=”dozemanta.php”>
<table width=”100%”>
<tr><th colspan=”2″>Testing Zemanta API</th></tr>
<tr><td>Text:</td><td>
<textarea name=”text” style=”width:500px;”></textarea>
</td></tr>
<tr><td> ——— Or ————–</td></tr>
<tr><td>URL:</td><td>
<input name=”url” type=”text” value=”" style=”width:500px;”/>
</td></tr>
<tr><td> <input type=”submit” name=”btn” value=”Extract” /></td></tr>
</table>
</form>

dozemanta.php

$url = ‘http://api.zemanta.com/services/rest/0.0/’; //Should be in a conffile
$format = ‘xml’; // May depend of your application context
$text = $_REQUEST["text"];
if($_REQUEST["url"]!=”"){
$text = strip_tags(file_get_contents($_REQUEST["url"]));
}

$key = “YOUR_API_KEY”; //Should be in a conf file
$method = “zemanta.suggest”; // May depend of your application context

$args = array(
‘method’=> $method,
‘api_key’=> $key,
‘text’=> $text,
‘format’=> $format
);

$data = “Here we build the data we want to POST to Zementa”;
foreach($args as $key=>$value)
{
$data .= ($data != “”)?”&”:”";
$data .= urlencode($key).”=”.urlencode($value);
}

/* Initialisation of curl */
$ch = curl_init();
/* Setup of the url*/
curl_setopt($ch, CURLOPT_URL, $url);
/* We want a post request */
curl_setopt($ch, CURLOPT_POST, 1);
/* Here we give to curl the data we want to send to Zementa*/
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
/* We setup the response method of curl */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
/* Execute curl and fetch the result */
$response = curl_exec ($ch);
/* Close curl connection */
curl_close ($ch);
//echo $response;

$xmlArray = xml2array($response); // XML2ARRAY is a function to covert xml to array

// Get the top array

$content = $xmlArray["rsp"];

// Related Articles

foreach($content["articles"] as $articles){
$i = 0;
echo ‘<table width=”100%”><tr><th colspan=2>Related Articles:</th></tr>’;
foreach($articles as $article){
//echo $i;
//echo $article["url"]["value"];
echo ‘<tr><td><a href=”‘.$article["url"]["value"].’” target=”_new” >’.$article["title"]["value"].’</a></td></tr>’;
$i++;
}
//print_r($articles[0]["url"]["value"]);
echo ‘</table>’;
}

// Related Keywords

foreach($content["keywords"] as $keywords){
//print_r($markup);
$i = 0;
echo ‘<table width=”100%”><tr><th colspan=2>Keywords:</th></tr><tr><td>’;
foreach($keywords as $keyword){
//echo $i;
//echo $article["url"]["value"];
echo ‘<a href=”http://www.popdup.com/tag/’.$keyword["name"]["value"].’” target=”_new” >’.$keyword["name"]["value"].’</a>   ’;
$i++;
}
//print_r($articles[0]["url"]["value"]);
echo ‘</td></tr></table>’;
}

// Related Images

foreach($content["images"] as $images){
//print_r($markup);
$i = 0;
echo ‘<table width=”100%”><tr><th colspan=2>Images:</th></tr>’;
foreach($images as $image){
//echo $i;
//echo $article["url"]["value"];
echo ‘<tr><td><a href=”‘.$image["url_l"]["value"].’” target=”_new” ><img src=”‘.$image["url_s"]["value"].’” style=” border:0px;” /></a></td><td>’.$image["description"]["value"].’</td></tr>’;
$i++;
}
//print_r($articles[0]["url"]["value"]);
echo ‘</table>’;
}

Zemanta Pixie

Buzzwords of semantic web

June 26, 2008

Since 2000, people are talking much about semantic web, web 2, web 3 .. what are the buzzwords behind the semantic web ?

semantic web – a meaning of web by the web itself. Making the web understandable by machines.

RDF -  Resource Description Framework – W3C Standards to descripe anything in semantic web – it is an XML - RDF is a directed, labeled graph data format for representing information in the Web

FOAF - Friend Of A Friend – W3C standards to describe people & networks, the links between them and the things they create and do

SIOC - Semantically interconnected Online Communities -  a Semantic Web ontology for representing rich data from the Social Web in RDF

OWL - Web Ontology Language (Ontology – representation of a set of concepts within a domain and the relationships between them) – it is a family of ontologies to describe semantic web – OWL ontologies are most commonly serialized using RDF/XML syntax

SPARQL - SPARQL Protocol and RDF Query Language , is an RDF query language

Linked Open Data – is a community lead effort to create openly accessible, and interlinked, RDF Data on the Web

APML - allows users to share their own personal Attention Profile

Attention Profile – A profile that have build with a combination of your Semantic data

Open ID - open decentralized ID system that provides single access to the web

OAuth - OAuth is a simple way to publish and interact with protected data. It’s also a safer and more secure way for people to give you access.

Single Sign ON (SS0) -  a secured authentication for over the web.

Data Portability – a mixing of open standars inclucing RDF,OPML,Micro formats,APML,OpenID ..

Microformats - Designed for humans first and machines second, microformats are a set of simple, open data formats built upon existing and widely adopted standards

NLP – Natural Language Processing -  handling human languages

Some Buzz Applications :

know3 – http://www.know3.com

Twine – http://www.twine.com

powerset – http://www.powerset.com

Yahoo Search Monkey

DBpedia

freebase

radarnetworks

trueknowledge.com

talis platform

opencalais

Data Portability.org

zemanta.com

Add more applications & buzzwords & comments to make this a library for beginners .. thanks for reading this..