Exemplo n.º 1
0
function testClassifier()
{
    $textrazorClassifier = new ClassifierManager();
    $classifierId = 'test_cats_php';
    try {
        print_r($textrazorClassifier->deleteClassifier($classifierId));
    } catch (Exception $e) {
        // Silently ignore missing classifier for now.
    }
    // Define some new categories and upload them as a new classifier.
    $newCategories = array();
    array_push($newCategories, array('categoryId' => '1', 'query' => "concept('banking')"));
    array_push($newCategories, array('categoryId' => '2', 'query' => "concept('health')"));
    $textrazorClassifier->createClassifier($classifierId, $newCategories);
    // Test the new classifier out with an analysis request.
    $textrazor = new TextRazor();
    $textrazor->addClassifier($classifierId);
    $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);
    print_r($response['response']);
    // The client offers various methods for manipulating your stored classifier.
    print_r($textrazorClassifier->allCategories($classifierId));
    print_r($textrazorClassifier->deleteClassifier($classifierId));
}