예제 #1
0
파일: tests.php 프로젝트: fstream9/Slash
assert($response['status'] == 'OK');
echo 'Raw text tests complete!', PHP_EOL, PHP_EOL;
//Author
echo 'Checking author . . . ', PHP_EOL;
$response = $alchemyapi->author('text', $test_text, null);
assert($response['status'] == 'ERROR');
//author only works on html and url content
$response = $alchemyapi->author('html', $test_html, null);
assert($response['status'] == 'ERROR');
//there is no author listed in the test HTML content
$response = $alchemyapi->author('url', $test_url, null);
assert($response['status'] == 'OK');
echo 'Author tests complete!', PHP_EOL, PHP_EOL;
//Language
echo 'Checking language . . . ', PHP_EOL;
$response = $alchemyapi->language('text', $test_text, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->language('html', $test_html, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->language('url', $test_url, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->language('random', $test_url, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Language tests complete!', PHP_EOL, PHP_EOL;
//Title
echo 'Checking title . . . ', PHP_EOL;
$response = $alchemyapi->title('text', $test_text, null);
assert($response['status'] == 'ERROR');
//title only works on html and url content
$response = $alchemyapi->title('html', $test_html, null);
예제 #2
0
파일: example.php 프로젝트: Laradev/sdk_php
    echo 'text: ', $response['category'], PHP_EOL;
    echo 'score: ', $response['score'], PHP_EOL;
} else {
    echo 'Error in the text categorization call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '#   Language Detection Example             #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->language('text', $demo_text, null);
if ($response['status'] == 'OK') {
    echo '## Response Object ##', PHP_EOL;
    echo print_r($response);
    echo PHP_EOL;
    echo '## Language ##', PHP_EOL;
    echo 'language: ', $response['language'], PHP_EOL;
    echo 'iso-639-1: ', $response['iso-639-1'], PHP_EOL;
    echo 'native speakers: ', $response['native-speakers'], PHP_EOL;
} else {
    echo 'Error in the language detection call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
<?php

if (isset($_POST['query']) and !empty($_POST['query'])) {
    $query = $_POST['query'];
    $facetNames = array("lang" => "Language", "en" => "English", "de" => "German", "ru" => "Russian", "es" => "Spanish", "fr" => "French", "ar" => "Arabic", "tweet_hashtags" => "Tweet Hashtags", "content_tags_orig" => "Content Tags", "location" => "Location");
    ?>
	<div class="row">
		  <?php 
    $url = "http://52.35.194.159:8983/solr/project/select?wt=json&indent=true&defType=dismax&qf=";
    //$url="http://52.35.194.159:8983/solr/project/select?wt=json&indent=true&defType=dismax&q.alt=";
    //
    require_once "./includes/alchemyapi/alchemyapi.php";
    $alchemyapi = new AlchemyAPI();
    $response = $alchemyapi->language('text', $query, null);
    if ($response['status'] == 'OK') {
        $detectedLanguage = $response['language'];
    } else {
        $detectedLanguage = 'English';
    }
    $queryString = null;
    if ($detectedLanguage == 'German') {
        $queryString = "text_de^5.0+text_en+text_ru+text_fr+text_es+text_ar+tweet_hashtags";
    } else {
        if ($detectedLanguage == 'Spanish') {
            $queryString = "text_es^5+text_en+text_ru+text_de+text_fr+text_ar+tweet_hashtags";
        } else {
            if ($detectedLanguage == 'Russian') {
                $queryString = "text_ru^5+text_en+text_de+text_fr+text_es+text_ar+tweet_hashtags";
            } else {
                if ($detectedLanguage == 'French') {
                    $queryString = "text_fr^5+text_en+text_ru+text_de+text_es+text_ar+tweet_hashtags";