コード例 #1
0
 public function getTaxonomyFor($text)
 {
     $taxonomy = $this->alchemy->taxonomy('text', $text);
     $words = array();
     if (isset($taxonomy['taxonomy'])) {
         $total = 0;
         foreach ($taxonomy['taxonomy'] as $keyword) {
             $words[] = (string) $keyword['label'];
         }
     }
     return $words;
 }
コード例 #2
0
<?php

require_once 'alch/alchemyapi.php';
$alchemyapi = new AlchemyAPI();
$demo_text = $_GET['text'];
$result = array();
$response = $alchemyapi->taxonomy('text', $demo_text, null);
if ($response['status'] == 'OK') {
    #echo '## Response Object ##', PHP_EOL;
    #echo print_r($response);
    #echo PHP_EOL;
    #echo '## Categories ##', PHP_EOL;
    $i = 0;
    foreach ($response['taxonomy'] as $category) {
        $x = explode('/', $category['label']);
        foreach ($x as $y) {
            if (!isset($result[$y]) && $y != '') {
                $result[$y] = $category['score'];
            }
        }
        $i = $i + 1;
        #echo $category['label'], ' : ', $category['score'], PHP_EOL;
    }
}
#$res = json_decode($output, true);
echo json_encode($result);
コード例 #3
0
ファイル: tests.php プロジェクト: fstream9/Slash
assert($response['status'] == 'OK');
$response = $alchemyapi->image_keywords('random', $test_url, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Image keyword tests complete!', PHP_EOL, PHP_EOL;
//image extraction
echo 'Checking image extraction . . . ', PHP_EOL;
$response = $alchemyapi->imageExtraction('url', $test_url, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->imageExtraction('random', $test_url, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Image extraction tests complete!', PHP_EOL, PHP_EOL;
//taxonomy
echo 'Checking Taxonomy . . . ', PHP_EOL;
$response = $alchemyapi->taxonomy('text', $test_text, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->taxonomy('random', $test_text, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Taxonomy tests complete!', PHP_EOL, PHP_EOL;
//combined
echo 'Checking Combined . . . ', PHP_EOL;
$response = $alchemyapi->combined('text', $test_text, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->combined('random', $test_text, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Combined tests complete!', PHP_EOL, PHP_EOL;
//Entities
echo 'Checking entities . . . ', PHP_EOL;