コード例 #1
0
function CheckParameterTypes()
{
    $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");
    $namedEntityParams = new AlchemyAPI_NamedEntityParams();
    $keywordParams = new AlchemyAPI_KeywordParams();
    try {
        $result = $alchemyObj->URLGetRankedNamedEntities("http://www.cnn.com/2010/HEALTH/06/03/gulf.fishermans.wife/index.html?hpt=C2", "xml", $keywordParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetRankedNamedEntities($htmlFile2, "http://www.test.com/", "xml", $keywordParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->TextGetRankedNamedEntities("Hello my name is Bob.  I am speaking to you at this very moment.  Are you listening to me, Bob?", "xml", $keywordParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetCategory("http://www.techcrunch.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->TextGetCategory("Latest on the War in Iraq.", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetCategory($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetConstraintQuery("http://microformats.org/wiki/hcard", "1st link", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetConstraintQuery($htmlFile, "http://www.test.com/", "1st link", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetFeedLinks("http://www.techcrunch.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetFeedLinks($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetRankedKeywords("http://www.techcrunch.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->TextGetRankedKeywords("Hello my name is Bob Jones.  I am speaking to you at this very moment.  Are you listening to me, Bob?", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetRankedKeywords($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetLanguage("http://www.techcrunch.fr/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->TextGetLanguage("Hello my name is Bob Jones.  I am speaking to you at this very moment.  Are you listening to me, Bob?", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetLanguage($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetMicroformats("http://microformats.org/wiki/hcard", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetMicroformats($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetTitle("http://www.techcrunch.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetText("http://www.techcrunch.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->URLGetRawText("http://www.techcrunch.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetTitle($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetText($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
    try {
        $result = $alchemyObj->HTMLGetRawText($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
        //should throw an exception for mismatched parameters
        assert(1 == 0);
    } catch (Exception $e) {
    }
}
コード例 #2
0
<?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");
// Create a named entity API parameters object
$namedEntityParams = new AlchemyAPI_NamedEntityParams();
// Turn off quotations extraction
$namedEntityParams->setQuotations(0);
// Turn off entity disambiguation
$namedEntityParams->setDisambiguate(0);
// Turn on sentiment analysis
$namedEntityParams->setSentiment(1);
// Extract a ranked list of named entities from a web URL, using the previously created parameters object.
$result = $alchemyObj->URLGetRankedNamedEntities("http://www.techcrunch.com/", "xml", $namedEntityParams);
echo "{$result}<br/><br/>\n";
// Extract a ranked list of named entities from a text string, using the previously created parameters object.
$result = $alchemyObj->TextGetRankedNamedEntities("Hello my name is Bob.  I am speaking to you at this very moment.  Are you listening to me, Bob?", "xml", $namedEntityParams);
echo "{$result}<br/><br/>\n";
// Load a HTML document to analyze.
$htmlFile = file_get_contents("data/example.html");
// Extract a ranked list of named entities from a HTML document, using the previously created parameters object.
$result = $alchemyObj->HTMLGetRankedNamedEntities($htmlFile, "http://www.test.com/", "xml", $namedEntityParams);
echo "{$result}<br/><br/>\n";
コード例 #3
0
ファイル: entities.php プロジェクト: radicalsuz/fe
<?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 a ranked list of named entities from a web URL.
$result = $alchemyObj->URLGetRankedNamedEntities("http://www.techcrunch.com/");
echo "{$result}<br/><br/>\n";
// Extract a ranked list of named entities from a text string.
$result = $alchemyObj->TextGetRankedNamedEntities("Hello my name is Bob.  I am speaking to you at this very moment.  Are you listening to me, Bob?");
echo "{$result}<br/><br/>\n";
// Load a HTML document to analyze.
$htmlFile = file_get_contents("data/example.html");
// Extract a ranked list of named entities from a HTML document.
$result = $alchemyObj->HTMLGetRankedNamedEntities($htmlFile, "http://www.test.com/");
echo "{$result}<br/><br/>\n";