public function search()
 {
     $validation = Validator::make(Input::all(), array('stackExchangeSearch' => 'required | max:50'));
     if ($validation->fails()) {
         return Redirect::back()->withInput()->withErrors($validation->messages());
     }
     $response = $this->getPosts(Input::get('stackExchangeSearch'), Input::get('count'));
     $alchemyapi = new AlchemyAPI();
     $postIntel = [];
     foreach ($response->items as $post) {
         $textOptions = ['useMetadata' => 1];
         $textResponse = $alchemyapi->text('url', $post->link, $textOptions);
         $sentimentOptions = ['sentiment' => 1];
         $postSentiment = $this->doAlchemy('url', $post->link, $sentimentOptions, 'sentiment', 'docSentiment', $alchemyapi);
         //Dont use concepts
         //when loading stack url into concepts call, it just returns random unrelated stuff
         //when loading extracted text into concepts call, it returns empty every time
         $entityOptions = ['maxRetrieve' => 5, 'sentiment' => 1];
         $postEntities = $this->doAlchemy('text', $textResponse['text'], $entityOptions, 'entities', 'entities', $alchemyapi);
         $keywordOptions = ['sentiment' => 1, 'showSourceText' => 1, 'maxRetrieve' => 5];
         $postKeywords = $this->doAlchemy('text', $textResponse['text'], $keywordOptions, 'keywords', 'keywords', $alchemyapi);
         $tmp = ['link' => $post->link, 'title' => $post->title, 'answered' => $post->is_answered, 'sentiment' => $postSentiment, 'entities' => $postEntities, 'keywords' => $postKeywords];
         array_push($postIntel, $tmp);
     }
     return View::make('stackResults')->with('postIntel', $postIntel)->with('searchTerm', Input::get('stackExchangeSearch'));
 }
예제 #2
0
<?php

require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI();
extract($_GET);
$url = rawurldecode($url);
$response = $alchemyapi->text('url', $url, null);
if ($response['status'] == 'OK') {
    $content = explode(".", $response['text'], 1);
    $retstr = implode(".", $content);
    echo $retstr;
} else {
    echo 'Error in the text extraction call: ', $response['statusInfo'];
}
예제 #3
0
파일: tests.php 프로젝트: fstream9/Slash
$response = $alchemyapi->sentiment_targeted('text', $test_text, 'heart', null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment_targeted('html', $test_html, 'language', null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment_targeted('url', $test_url, 'Congress', null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment_targeted('random', $test_url, 'Congress', null);
assert($response['status'] == 'ERROR');
//invalid flavor
$response = $alchemyapi->sentiment_targeted('text', $test_text, null, null);
assert($response['status'] == 'ERROR');
//missing target
echo 'Targeted sentiment tests complete!', PHP_EOL, PHP_EOL;
//Text
echo 'Checking clean text . . . ', PHP_EOL;
$response = $alchemyapi->text('text', $test_text, null);
assert($response['status'] == 'ERROR');
//text only works on html and url content
$response = $alchemyapi->text('html', $test_html, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->text('url', $test_url, null);
assert($response['status'] == 'OK');
echo 'Clean text tests complete!', PHP_EOL, PHP_EOL;
//Text Raw
echo 'Checking raw text . . . ', PHP_EOL;
$response = $alchemyapi->text_raw('text', $test_text, null);
assert($response['status'] == 'ERROR');
//text_raw only works on html and url content
$response = $alchemyapi->text_raw('html', $test_html, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->text_raw('url', $test_url, null);