Example #1
0
<?php

require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI();
$feed_url = "http://www.the-star.co.ke/star-health";
$content = file_get_contents($feed_url, true);
$feed = json_decode($content);
if (property_exists($feed, "nodes") && isFresh($content)) {
    //first dump raw content to file to check if new in subsequent pulls
    file_put_contents("oldsha.txt", sha1($content));
    $items = $feed->nodes;
    $articles = array();
    $concepts = array();
    foreach ($items as $d) {
        $item = $d->node;
        $response = $alchemyapi->concepts('text', $item->body, null);
        $tags = array();
        $weighted_tags = array();
        if ($response['status'] == 'OK') {
            foreach ($response['concepts'] as $concept) {
                if (!array_key_exists($concept['text'], $tags)) {
                    //No exact match
                    //check if this key is substring of existing key or vice versa
                    $existing_key = sub_exists($concept['text'], $concepts);
                    if ($existing_key != null) {
                        $new_value = $concepts[$existing_key] + 1;
                        $concepts[$existing_key] = $new_value;
                        $tags[] = $existing_key;
                    } else {
                        $concepts[$concept['text']] = 1;
                        $tags[] = $concept['text'];
Example #2
0
<?php

$base_url = dirname(__FILE__) . "/";
require_once $base_url . 'alchemyapi.php';
$alchemyapi = new AlchemyAPI();
$feed_url = "http://www.the-star.co.ke/star-health";
$content = file_get_contents($feed_url, true);
$feed = json_decode($content);
if (property_exists($feed, "nodes") && isFresh($content, $base_url)) {
    //first dump raw content to file to check if new in subsequent pulls
    file_put_contents($base_url . "oldsha.txt", sha1($content));
    $items = $feed->nodes;
    $articles = array();
    $concepts = array();
    foreach ($items as $d) {
        $item = $d->node;
        $response = $alchemyapi->concepts('text', $item->body, null);
        $tags = array();
        $weighted_tags = array();
        if ($response['status'] == 'OK') {
            foreach ($response['concepts'] as $concept) {
                if (!array_key_exists($concept['text'], $tags)) {
                    //No exact match
                    //check if this key is substring of existing key or vice versa
                    $existing_key = sub_exists($concept['text'], $concepts);
                    if ($existing_key != null) {
                        $new_value = $concepts[$existing_key] + 1;
                        $concepts[$existing_key] = $new_value;
                        $tags[] = $existing_key;
                    } else {
                        $concepts[$concept['text']] = 1;