<?php // Load the AlchemyAPI module code. include "../module/AlchemyAPI.php"; // Or load the AlchemyAPI PHP+CURL module. /*include "../module/AlchemyAPI_CURL.php";*/ // Create an AlchemyAPI object. $alchemyObj = new AlchemyAPI(); // Load the API key from disk. $alchemyObj->loadAPIKey("api_key.txt"); // Extract concept tags from a web URL. $result = $alchemyObj->URLGetRankedConcepts("http://www.techcrunch.com/"); echo "{$result}<br/><br/>\n"; // Extract concept tags from a text string. $result = $alchemyObj->TextGetRankedConcepts("This thing has a steering wheel, tires, and an engine. Do you know what it is?"); echo "{$result}<br/><br/>\n"; // Load a HTML document to analyze. $htmlFile = file_get_contents("data/example.html"); // Extract concept tags from a HTML document. $result = $alchemyObj->HTMLGetRankedConcepts($htmlFile, "http://www.test.com/"); echo "{$result}<br/><br/>\n";
function CheckConceptsParams() { $alchemyObj = new AlchemyAPI(); $alchemyObj->loadAPIKey("api_key.txt"); $htmlFile = file_get_contents("../example/data/example.html"); $htmlFile2 = file_get_contents("../example/data/example2.html"); $htmlFile2_nolinks = file_get_contents("../example/data/example2_nolinks.html"); $conceptsParams = new AlchemyAPI_ConceptParams(); $result = $alchemyObj->HTMLGetRankedConcepts($htmlFile2_nolinks, "http://www.test.com/", "xml", $conceptsParams); $doc = simplexml_load_string($result); CheckForOKStatus($result); $matches = $doc->xpath("//concept"); assert(count($matches) != 0); try { $conceptsParams->setSourceText("xpath"); $conceptsParams->setXPath("//a"); $result = $alchemyObj->HTMLGetRankedConcepts($htmlFile2_nolinks, "http://www.test.com/", "xml", $conceptsParams); //should return an error. If there is no error, xpath found a link when there are none. assert(1 == 0); } catch (Exception $e) { } }