-
-
Save caseysoftware/557fac23cf3829a16fc4 to your computer and use it in GitHub Desktop.
In this one, we use PHP to tie together the AlchemyData News API along with the Clarify.io API. This is part of a post for the IBM Watson blog: http://blog.alchemyapi.com/decoding-the-debates-a-cognitive-approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Don't forget to rename credentials-dist.php to credentials.php and insert your API key | |
require __DIR__ . '/credentials.php'; | |
require __DIR__.'/../vendor/autoload.php'; | |
use GuzzleHttp\Client as GuzzleClient; | |
$bundle_id = 'bundles/abcde12345'; | |
$bundle = new Clarify\Bundle($apikey); | |
$insights = $bundle->insights; | |
$_data = $insights->load($bundle_id); | |
$insights->get($_data['_links']['insight:spoken_keywords']['href']); | |
$keywords = $insights->keywords; | |
$alchemy_client = new GuzzleClient(['base_uri' => 'https://gateway-a.watsonplatform.net/calls/data/GetNews']); | |
$options = []; | |
$options['apikey'] = 'alchemy-key'; | |
$options['outputMode'] = 'json'; | |
$options['start'] = 'now-5d'; | |
$options['end'] = 'now'; | |
$options['return'] = 'enriched.url.title,enriched.url.url'; | |
$options['count'] = 10; | |
foreach($keywords as $keyword) { | |
echo $keyword['term'] . "\n"; | |
$options['q.enriched.url.enrichedTitle.relations.relation'] = '|subject.text=' . $keyword['term'] . ',object.entities.entity.type=Person|'; | |
$response = $alchemy_client->request('GET', '', $options); | |
$results = json_decode($response->getBody(), true); | |
$articles = $results['result']['docs']; | |
foreach($articles as $article) { | |
echo $article['source']['enriched']['url']['url'] . "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment