Exemple #1
0
function testEntityDictionary()
{
    $textrazorDictionary = new DictionaryManager();
    $dictionaryId = 'test_ents_php';
    try {
        print_r($textrazorDictionary->deleteDictionary($dictionaryId));
    } catch (Exception $e) {
        // Silently ignore missing dictionary for now.
    }
    // Define a new dictionary, then add some test entries
    print_r($textrazorDictionary->createDictionary($dictionaryId, 'STEM', true, "eng"));
    $new_entities = array();
    array_push($new_entities, array("id" => "TV_1", "text" => "BBC Panorama"));
    print_r($textrazorDictionary->addEntries($dictionaryId, $new_entities));
    // To use the new dictionary, simply add its ID to your analysis request.
    $textrazor = new TextRazor();
    $textrazor->addEntityDictionary($dictionaryId);
    $text = '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);
    // The matched entities will be available in the response
    print_r($response['response']['entities']);
    // The client offers various methods for manipulating your stored dictionary entries.
    print_r($textrazorDictionary->getEntry($dictionaryId, "TV_1"));
    print_r($textrazorDictionary->allEntries($dictionaryId, 10));
    print_r($textrazorDictionary->getDictionary($dictionaryId));
    print_r($textrazorDictionary->allDictionaries());
    print_r($textrazorDictionary->deleteDictionary($dictionaryId));
}
 /**
  * @static
  * @return DictionaryManager
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
 /**
  * Dictionary : Delete a word
  */
 public function delDictionaryWord()
 {
     if (!AccountManager::getInstance()->isLogged()) {
         return JsonResponseBuilder::failure();
     }
     if (AccountManager::getInstance()->isAnonymous) {
         return JsonResponseBuilder::failure();
     }
     $wordId = $this->getRequestVariable('wordId');
     DictionaryManager::getInstance()->delWord($wordId);
     return JsonResponseBuilder::success();
 }