/**
  * @return array[]
  */
 public function getEntitiesFor($text)
 {
     $entities = $this->alchemy->entities('text', $text);
     $items = array();
     $words = array();
     if (isset($entities['entities'])) {
         foreach ($entities['entities'] as $entity) {
             if ($entity['relevance'] > 0.3) {
                 $type = (string) $entity['type'];
                 $text = (string) $entity['text'];
                 if (!array_key_exists($type, $items)) {
                     $items[$type] = array();
                 }
                 $items[$type][] = $text;
                 $words[] = $text;
             }
         }
     }
     return $words;
     //		$this->api->setQueryString(array(
     //			'apikey' => self::$config['api_key'],
     //			'text'   => $text
     //		));
     //
     //		$request = $this->api->request('TextGetRankedNamedEntities');
     //
     //		if (!$request->isError()) {
     //			$entities = array();
     //
     //			foreach ($request->simpleXML()->entities->entity as $entity) {
     //				if ($entity->relevance > .3) {
     //					$type = (string) $entity->type;
     //					$text = (string) $entity->text;
     //
     //					if (!array_key_exists($type, $entities)) {
     //						$entities[$type] = array();
     //					}
     //
     //					$entities[$type][] = $text;
     //				}
     //			}
     //
     //			return $entities;
     //		} else {
     //			return array();
     //		}
 }
Beispiel #2
0
echo ',???????  :7777777                                                                                77                                       ', PHP_EOL;
echo ' =?????  ,7777777                                                                               77=                                        ', PHP_EOL;
echo '   +?+  7777777?                                                                                                                           ', PHP_EOL;
echo '    +  ~7777777                                                                                                                            ', PHP_EOL;
echo '       I777777                                                                                                                             ', PHP_EOL;
echo '          :~                                                                                                                               ', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '#   Entity Extraction Example              #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->entities('text', $demo_text, array('sentiment' => 1));
if ($response['status'] == 'OK') {
    echo '## Response Object ##', PHP_EOL;
    echo print_r($response);
    echo PHP_EOL;
    echo '## Entities ##', PHP_EOL;
    foreach ($response['entities'] as $entity) {
        echo 'text: ', $entity['text'], PHP_EOL;
        echo 'type: ', $entity['type'], PHP_EOL;
        echo 'relevance: ', $entity['relevance'], PHP_EOL;
        echo 'sentiment: ', $entity['sentiment']['type'], ' (' . $entity['sentiment']['score'] . ')', PHP_EOL;
        echo PHP_EOL;
    }
} else {
    echo 'Error in the entity extraction call: ', $response['statusInfo'];
}
 public function find_entities($message)
 {
     $alchemyapi = new \AlchemyAPI();
     $response = $alchemyapi->entities("text", $message, null);
     if ($response['status'] == 'OK') {
         /*//sort by relevance
           usort($response['entities'], function($a, $b) {
               return $a['relevance'] - $b['relevance'];
           });
           */
         return $response['entities'];
     } else {
         return null;
     }
 }
Beispiel #4
0
assert($response['status'] == 'OK');
$response = $alchemyapi->taxonomy('random', $test_text, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Taxonomy tests complete!', PHP_EOL, PHP_EOL;
//combined
echo 'Checking Combined . . . ', PHP_EOL;
$response = $alchemyapi->combined('text', $test_text, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->combined('random', $test_text, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Combined tests complete!', PHP_EOL, PHP_EOL;
//Entities
echo 'Checking entities . . . ', PHP_EOL;
$response = $alchemyapi->entities('text', $test_text, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->entities('html', $test_html, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->entities('url', $test_url, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->entities('random', $test_url, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Entity tests complete!', PHP_EOL, PHP_EOL;
//Keywords
echo 'Checking keywords . . . ', PHP_EOL;
$response = $alchemyapi->keywords('text', $test_text, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->keywords('html', $test_html, null);
assert($response['status'] == 'OK');
                      <form method="post">

                      <p>Person:</p>

                       <?php 
require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI();
//$myText = "I can't wait to integrate AlchemyAPI's awesome PHP SDK into my app!";
if ($_SESSION["rawsearch"] == 0) {
    $urladd = $_SESSION["facedquery"];
} else {
    $urladd = "http://52.32.49.169:8983/solr/proj3/select?q=" . $_SESSION['query'] . "&start=0&rows=100&wt=json&indent=true";
}
//echo ($_SESSION["rawsearch"]);
$options["sentiment"] = 1;
$response = $alchemyapi->entities("url", $urladd, $options);
//echo "Sentiment: ", $response["docSentiment"]["type"], PHP_EOL;
//echo $response;
//echo print_r($response,true);
//$obj=json_decode($response,true);
$person;
$p_num = 0;
$country;
$c_num = 0;
$city;
$city_num = 0;
$hashtag;
$hash_num = 0;
//echo $response["entities"][0]["type"];
$len = count($response["entities"]);
//echo $len;
<button onclick="homeButton()">Back to Home</button>
<br>
<br>
<?php 
$file = file_get_contents('../all.txt', true);
require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI();
?>
<form name="entity" action="?page=entity" method="POST" autocomplete="off">
  <table border = '1px solid black' style="border-collapse: collapse; width: 960px;">
    <tr>
      <th> Entity </th>
      <th> Type </th>
    </tr>
<?php 
$response = $alchemyapi->entities('text', $file, null);
foreach ($response['entities'] as $entity) {
    ?>
	<tr>
      <td> <?php 
    echo (string) $entity['text'];
    ?>
 </td>
      <td> <?php 
    echo (string) $entity['type'];
    ?>
 </td>
    </tr>
<?php 
}
?>