예제 #1
0
function testAnalysis()
{
    $textrazor = new TextRazor();
    $textrazor->addExtractor('entities');
    $textrazor->addExtractor('words');
    $textrazor->addEnrichmentQuery("fbase:/location/location/geolocation>/location/geocode/latitude");
    $textrazor->addEnrichmentQuery("fbase:/location/location/geolocation>/location/geocode/longitude");
    $text = 'LONDON - Barclays misled shareholders and the public about one of the biggest investments in the banks history, a BBC Panorama investigation has found.';
    $response = $textrazor->analyze($text);
    if (isset($response['response']['entities'])) {
        foreach ($response['response']['entities'] as $entity) {
            print "Entity ID: " . $entity['entityId'];
            $entity_data = $entity['data'];
            if (!is_null($entity_data)) {
                print PHP_EOL;
                print "Entity Latitude: " . $entity_data["fbase:/location/location/geolocation>/location/geocode/latitude"][0];
                print PHP_EOL;
                print "Entity Longitude: " . $entity_data["fbase:/location/location/geolocation>/location/geocode/longitude"][0];
            }
            print PHP_EOL;
        }
    }
}
예제 #2
0
파일: index.php 프로젝트: xelaus/NewsPulse
function getNews($getfield, $newsSource, $settings, $api_key, $tweetArray, $tags_array)
{
    //echo "INSIDE FUNCTION";
    $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    $obj = json_decode($response, true);
    //echo $obj[0]['text'];
    $stringArray = array();
    for ($x = 0; $x < 20; $x++) {
        $text1 = $obj[$x]['text'];
        $text2 = str_replace('#', '', $text1);
        array_push($stringArray, $text2);
    }
    //echo '<br>';
    for ($i = 0; $i < 20; $i++) {
        $check = false;
        if (isset($tags_array)) {
            foreach ($tags_array as $tag) {
                if (strpos($stringArray[$i], $tag)) {
                    $check = true;
                    break;
                }
            }
        } else {
            continue;
        }
        if ($check) {
            $text = $stringArray[$i];
            $textrazor = new TextRazor($api_key);
            $textrazor->addExtractor('entities');
            $textrazor->addExtractor('words');
            $textrazor->addEnrichmentQuery("fbase:/location/location/geolocation>/location/geocode/latitude");
            $textrazor->addEnrichmentQuery("fbase:/location/location/geolocation>/location/geocode/longitude");
            $response = $textrazor->analyze($text);
            if (isset($response['response']['entities'])) {
                foreach ($response['response']['entities'] as $entity) {
                    //echo '<h1>';
                    //print("Entity ID: " . $entity['entityId']);
                    $urlcontent = '';
                    //                    if (strpos($entity['entityId'], 'http') !== false) {
                    //                        //echo "SDKJLFHSDLKFJHSDLJKFHSDLJ";
                    //                        $urlcontent = $entity['entityId'];
                    //                        // echo $urlcontent;
                    //                    }
                    $pattern = '#\\bhttps?://[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/))#';
                    $subject = $stringArray[$i];
                    preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
                    $urlcontent = $matches[0];
                    $stringArray2 = preg_replace($pattern, '', $stringArray[$i]);
                    // echo '</h1>';
                    $entity_data = $entity['data'];
                    if (!is_null($entity_data)) {
                        //print(PHP_EOL);
                        //print(PHP_EOL);
                        //echo $entity['entityId'];
                        if (count($tweetArray) == 0) {
                            $newTweet = new tweet($newsSource, $stringArray2, $entity_data["fbase:/location/location/geolocation>/location/geocode/latitude"][0], $entity_data["fbase:/location/location/geolocation>/location/geocode/longitude"][0], $urlcontent);
                            array_push($tweetArray, $newTweet);
                        } else {
                            $newTweet = new tweet($newsSource, $stringArray2, $entity_data["fbase:/location/location/geolocation>/location/geocode/latitude"][0], $entity_data["fbase:/location/location/geolocation>/location/geocode/longitude"][0], $urlcontent);
                            //                            for($i = 0; $i <= count($tweetArray); $i++) {
                            //                                if($tweetArray[$i]->stweet !==  $stringArray2){
                            //                                    array_push($tweetArray, $newTweet);
                            //                                }
                            //
                            //                            }
                            foreach ($tweetArray as $tw) {
                                if ($tw->stweet !== $stringArray2) {
                                    array_push($tweetArray, $newTweet);
                                    break;
                                }
                            }
                        }
                    }
                    //print(PHP_EOL);
                }
            }
        }
    }
    //echo '<br>';
    //var_dump($tweetArray);
    return $tweetArray;
}